WebParam.Mode.OUT meaning and documentation - java

I usually create stub to interrogate external web service, It is the first time that after I created the stub of a project, in the Service.class I have this code:
public void getInformation(
#WebParam(name = "username", targetNamespace = "http://mysite")
java.lang.String username,
#WebParam(name = "password", targetNamespace = "http://mysite")
java.lang.String password,
#WebParam(mode = WebParam.Mode.OUT, name = "GetInformation", targetNamespace = "http://mysite")
javax.xml.ws.Holder<MyInformation> getInformation,
#WebParam(mode = WebParam.Mode.OUT, name = "outPut", targetNamespace = "http://mysite")
javax.xml.ws.Holder<MyFile> fOutPut
);
In the documentation of this web method there is written that the input parameter is username and password, and the output parameter is Holder getInformation,Holder fOutPut; but when I try to call the method, I have to insert all the paramenter in input, like
myClientClass.getInformation(username,password,getInformation,fOutPut);
I try to search online a documentation but I have not found anything, I have understand that It is a way to populate my output value without have It in return, but I want to understand how It really works and If there is any documentation/example to implement a web method like this or how to send value in this way.
Thank you

Related

How do I intercept a Soap Response XML with invalid character

The error is as follows: [com.ctc.wstx.exc.WstxLazyException] Illegal character entity: expansion character (code 0x1a\r\n at [row,col {unknown-source}]: [1,8035]
This is my WebService in Springboot with its WebMethod which receives an array of Polizas from which one of its fields contains an invalid character:
#WebService(targetNamespace = "http://example.org.co/", name = "PolizaSoap")
#XmlSeeAlso({ObjectFactory.class})
public interface PolizaSoap {
#WebMethod(operationName = "Polizas", action = "http://example.org.co/Polizas")
#RequestWrapper(localName = "Polizas", targetNamespace = "http://example.org.co/", className = "com.example.Polizas")
#ResponseWrapper(localName = "PolizasResponse", targetNamespace = "http://example.org.co/", className = "com.example.PolizasResponse")
#WebResult(name = "PolizasResult", targetNamespace = "http://example.org.co/")
public ArrayOfPolizas Polizas(
#WebParam(name = "param1", targetNamespace = "http://example.org.co/")
java.lang.String param1,
#WebParam(name = "param2", targetNamespace = "http://example.org.co/")
java.lang.String param2,
#WebParam(name = "param3", targetNamespace = "http://example.org.co/")
java.lang.String param3
);
}
I have tried all kinds of interceptor (ClientInterceptor), filters (WebFilter), handler (SOAPHandler, HandlerInterceptor) and none have worked for me, the error occurs instantly and I have not found a way to obtain the XML response with the invalid character to be able to modify it and so everything works.
I'm beginning to think it's impossible to do, is there any other alternative that doesn't involve asking the response provider to correct it?. How can I intercept a XML response with invalid character (0x1a) without/before trigger a WebServiceException?
EDIT: Does anyone know if it is possible to use a FilterInputStream to correct the "XML" that comes with invalid characters before throwing an exception?

How to get screen name in Liferay 7 or Liferay DXP

I have the written the below code but its always returning user id (numeric like '40156' ,'20147' e.t.c) only not user name
Can somebody tell me how to get screen name
ThemeDisplay themeDisplay;
HttpServletRequest httpRequest;
themeDisplay = (ThemeDisplay) httpRequest.getAttribute(WebKeys.THEME_DISPLAY);
User user = null;
long userId1 = themeDisplay.getUserId();
user = UserLocalServiceUtil.getUserById(userId1);
String screenname1 = user.getScreenName();
I used the below code in java class, i can get the screen name now using the below code
now the "user" object has screen name in the variable _originalScreenName
HttpServletRequest request;
long companyID = PortalUtil.getCompanyId(request);
User user = UserLocalServiceUtil.getUserByEmailAddress(companyID, EmailID);

Java JAX WS create a method from java code that produce/accept a XML

Java JAX WS create a method from java code that produce/accept a XML like this
<web:listMd5FileSynchronizedSlave>
<descricaoSumaria>Test file sincrona </descricaoSumaria>
<fileFullPath>
<file>/opt/apagar/file01</file>
<type>1</type>
</fileFullPath>
<fileFullPath>
<file>/opt/apagar/file02</file>
<type>0</type>
</fileFullPath>
<fileFullPath>…….dynamic number of FileFullPath tag sent from the client
</web:listMd5FileSynchronizedSlave>
On my interface I have a code :
#SOAPBinding(style = Style.DOCUMENT)
#WebMethod (operationName = "listMd5FileSynchronizedSlave") String listMd5FileSynchronizedSlave(
#WebParam(name = "descricaoSumaria") String descricao ,
#WebParam(name = "fileFullPath") String [] fileFullPath
) ;
And the implementation is :
#Override
public String listMd5FileSynchronizedSlave(String descricao, String [] fileFullPath) {…}
This produce a XML like this
<web:listMd5FileSynchronizedSlave>
<descricaoSumaria>Test file sincrona </descricaoSumaria>
<fileFullPath>/opt/apagar/file01</fileFullPath>
<fileFullPath>/opt/apagar/*.sh</fileFullPath>
<fileFullPath>/opt/apagar/*.properties</fileFullPath>
</web:listMd5FileSynchronizedSlave>
How should I change my code to generate and accept a XML with sub tag of ?
<fileFullPath>
<file>/opt/apagar/file02</file>
<type>0</type>
</fileFullPath>
Tanks for this help

How to extract parameters from an object to show in parameters in documentation

I have the following API endpoint:
#ApiResponses(
value = {
#ApiResponse(code = 200, message = "OK",
responseHeaders = {
#ResponseHeader(name = "X-RateLimit-Limit", description = "The defined maximum number of requests available to the consumer for this API.", response = Integer.class),
#ResponseHeader(name = "X-RateLimit-Remaining", description = "The number of calls remaining before the limit is enforced and requests are bounced.", response = Integer.class),
#ResponseHeader(name = "X-RateLimit-Reset", description = "The time, in seconds, until the limit expires and another request will be allowed in. This header will only be present if the limit is being enforced.", response = Integer.class)
}
)
}
)
#ApiOperation(httpMethod = "GET", hidden = false, nickname = "Get Network Availability in JSON", value = "Get network availability for a product", response = AvailableToPromise.class, position = 1)
#RequestMapping(value = "/{product_id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> networkAvailabilityJsonResponse(
#RequestHeader HttpHeaders headers,
#PathVariable("product_id") String productId,
#Valid NetworkAvailabilityCmd cmd, //query params
BindingResult result)
throws Exception {}
}
Certain parameters, such as key are taken from the query and mapped into this object through Spring MVC.
However, in the parameters section of my endpoint in the swagger-ui, it's showing me a few odd things:
None of the variables that are in NetworkAvailabilityCmd show in this parameters list, and cmd itself shows as being located in the request body (it's actually located in the query). Is there a way to hide cmd and extract the params inside this object to show on the params list? I'd like the params list to look like this (with more params):
I'm able to do this if I use #ApiImplicitParams on the method endpoint, and write out each of the params. However, this NetworkAvailabilityCmd is used for many endpoints, and having the list of params on each endpoint is very messy. Being able to extract the variables from in the object would be far cleaner, and would prevent people from forgetting to add the entire list to new endpoints.
I imagine that it requires an annotation on NetworkAvailabilityCmd cmd, and potentially something on the variables in that class, but I can't seem to find what I'm looking for in the docs.
Thanks!
I found out that adding #ModelAttribute worked magically. This annotation is from Spring.

CXF Web-Services Response return invalid name

I used CXF WSDL2java to generate a server for an existing WSDL.
This gave me a SEI like that :
#WebService(targetNamespace = "http://mon.namespace.1", name = "MonWs")
#XmlSeeAlso({ObjectFactory.class})
public interface MonWs {
#WebResult(name = "Output", targetNamespace = "http://mon.namespace.1")
#RequestWrapper(localName = "maMethodePrincipale", targetNamespace = "http://mon.namespace.1", className = "MaMethodePrincipaleRequest")
#WebMethod(operationName = "maMethodePrincipale", action = "http://mon.namespace.1/MonWs/maMethodePrincipale")
#ResponseWrapper(localName = "maMethodePrincipaleResponse", targetNamespace = "http://mon.namespace.1", className = "MaMethodePrincipaleResponse")
public MaMethodePrincipaleResponse.Output maMethodePrincipale(
#WebParam(name = "Input", targetNamespace = "http://mon.namespace.1")
MaMethodePrincipaleRequest.Input Input
);
}
I created a basic implementation but when I call it on my server (hosted on tomcat, with de CXfNonSpringServlet) with soapUI (and other client) I got this kind of return :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:MaMethodePrincipaleResponse xmlns:ns1="http://mon.namespace.1">
<ns2:return xmlns="http://mon.namespace.2" xmlns:ns2="http://mon.namespace.1"/>
...
my return object field list correctly named
...
</ns2:return>
</ns1:MaMethodePrincipaleResponse>
</soap:Body>
</soap:Envelope>
my problem is the the tag "ns2:return ..." it should be name "Output" like I define in all the annotations (even in maMethodePrincipaleResponse name etc...)
So when i try to call my server with a java client I've got an error message like
javax.xml.bind.UnmarshalException: Unexpected Element (URI : "http://mon.namespace.1", local : "return"). Expected elements are <{http://mon.namespace.1}Output>
I already try a bunch of possible correction like set the soap binding to "bare" and set every partname or name to "Output" But nothing works.
What should i do to have this return parameter named "Output"?
You can try to use Interceptor.
in this link you can see how you can modify cxf response.
good luck
You are using Request/ResponseWrapper's. Thus, the names for the elements would be defined in the annotations on the fields in those classes.

Categories

Resources