How do I intercept a Soap Response XML with invalid character - java

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?

Related

How do I bind an UUID within a multipart/form-data to an endpoint argument

I have an api that consumes multipart/form-data and produces application/json. The form-data contains a UUID string. When I make a request to that api, it gives an 400 BAD_REQUEST status, stating that some mostSigBits and leastSigBits of the UUID instance is missing. I figured that the UUID instance might have been instantiated with some missing requirements.
How can I resolve this?
Here's my api.
#PatchMapping(value = "/{username}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
#Transactional
public ResponseEntity<?> takeThisGiveThat(UUID uuid, String somestring, String someMoreString) {
return ResponseEntity.ok(Map.of("uuid", uuid, "somestring", somestring, "someMoreString", someMoreString));
}

WebParam.Mode.OUT meaning and documentation

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

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

Using javax.jws.WebParam to have more the one WebParam in different xml sub tag

I need to create a method to receive a XML like this . Starting from java code
<web:listMd5FileSynchronizedSlave>
<descricaoSumaria>Test file sincrona </descricaoSumaria>
<fileFullPath>/opt/apagar/file01</fileFullPath>
<fileType>0</ fileType >
<fileFullPath>/opt/apagar/*.sh</fileFullPath>
<fileType>0</ fileType >
<fileFullPath>…….dynamic number of FileFullPath
</web:listMd5FileSynchronizedSlave>
My java code is :
#WebMethod (operationName = "listMd5FileSynchronizedSlave") String listMd5FileSynchronizedSlave(
#WebParam(name = "descricaoSumaria") String descricao ,
#WebParam(name = "fileFullPath") String [] fileFullPath
);
The implementation is :
#Override
public String listMd5FileSynchronizedSlave(String descricao, String [] fileFullPath) {}
with this code I have a working method that accept 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 can I add a xml subtag <fileType> in tag <fileFullPath>/ ?

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