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.
Related
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?
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 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
I am new to web service development, so maybe I'm not aware of something... I have a web service class currently has two methods in it. The below is just the first part of the second method.
#WebMethod(operationName = "getPassengerName")
public String getPassengerName(#WebParam(name = "passengerId ") int passengerId)
{
//MySQL elements
Connection connection;
ResultSet rs = null;
String returnValue = "start method with passengerId having a value of: " + passengerId;
and when I run a "test web service" in NetBeans, passing in a 1, the passengerId appended to the string is 0.
getPassengerName Method invocation
Method parameter(s)
Type Value
int 1
Method returned
java.lang.String : "start method with passengerId having a value of: 0"
What would make this happen? I appreciate any insight anyone can offer.
New Content
In response to EJK's post about the value not being in passengerID, I have added more of the screen print from the "Test Web Service" test.
SOAP Request
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns2:getPassengerName xmlns:ns2="http://database_access.lytthouseair.com/">
<passengerId>1</passengerId>
</ns2:getPassengerName>
</S:Body>
</S:Envelope>
I think I have hit upon the issue. I think it is a bug in the NetBeans IDE. I created a new method, which I modeled after this one that doesn't work:
#WebMethod(operationName = "getPassengerName")
public String getPassengerName(#WebParam(name = "passengerId ") int passengerId)
And typed in this:
#WebMethod(operationName = "getFirstName")
public String getFirstName(#WebParam(name="passengerNumber") int passengerNumber)
Then I simply copied all of my code into this new method, and when I checked the value of the variable passed in right at the top of the code, it worked - 1 was still 1 (not 0).
This was in NetBeans 8.0
Hi trying to generate a security header in a Java Axis2 Client program in the format of.
<soapenv:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext>
<wsse:UsernameToken>
<wsse:Username>myUsername</wsse:Username>
<wsse:Password>myPassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
using the following code
SOAPHeaderElement wsseSecurity = new SOAPHeaderElement(new PrefixedQName("http://schemas.xmlsoap.org/ws/2002/04/secext","Security", "wsse"));
MessageElement usernameToken = new MessageElement("", "wsse:UsernameToken");
MessageElement username = new MessageElement("", "wsse:Username");
MessageElement password = new MessageElement("", "wsse:Password");
username.setObjectValue(myProps.getProperty("username"));
usernameToken.addChild(username);
password.setObjectValue(myProps.getProperty("password"));
usernameToken.addChild(password);
wsseSecurity.addChild(usernameToken);
BookingPort bp = bsl.getBooking();
((Stub) bp).setHeader(wsseSecurity);
Unfortunately its not generating quite what I wanted and I get.
<soapenv:Header>
<wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
<wsse:UsernameToken xmlns:wsse="">
<wsse:Username xmlns:wsse="">myUsername</wsse:Username>
<wsse:Password xmlns:wsse="">myPassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
The service on the other end doesn't seem to handle the extra bits, resulting in an error
faultDetail:
{http://xml.apache.org/axis/}stackTrace:com.ctc.wstx.exc.WstxParsingException: Non-default namespace can not map to empty URI (as per Namespace 1.0 # 2) in XML 1.0 documents
at [row,col {unknown-source}]: [1,450]
How do I generate the SOAPHeader to not print out all the extra empty bits?
Cheers
You're passing an empty string as the first argument to MessageElement, and you need to pass null. Note that null and the empty string ("") are not the same thing in Java. Also, you are really cheating by passing the namespace prefix to the local name (second) parameter of the MessageElement constructor...this is not what it is designed for. That being said, you can fix the problem by passing null as the namespace (first) parameter. If you try to pass it directly, you'll likely get an ambiguous constructor error, so do something like the following:
SOAPHeaderElement wsseSecurity = new SOAPHeaderElement(new PrefixedQName("http://schemas.xmlsoap.org/ws/2002/04/secext","Security", "wsse"));
String nullString = null;
MessageElement usernameToken = new MessageElement(nullString, "wsse:UsernameToken");
MessageElement username = new MessageElement(nullString, "wsse:Username");
MessageElement password = new MessageElement(nullString, "wsse:Password");
username.setObjectValue(myProps.getProperty("username"));
usernameToken.addChild(username);
password.setObjectValue(myProps.getProperty("password"));
usernameToken.addChild(password);
wsseSecurity.addChild(usernameToken);
BookingPort bp = bsl.getBooking();
((Stub) bp).setHeader(wsseSecurity);
I'd also recommend you use a different web service engine (not Axis2) if you have any choice in the matter.
Try this way to create custom header with Axis 1.* (The above code doesnt look like with Axis2)
import org.apache.axis.message.SOAPHeaderElement;
import javax.xml.soap.SOAPElement;
public void createCustomHeader(){
SOAPElement oHeaderElement;
SOAPElement oElement;
oHeaderElement = new SOAPHeaderElement("http://ws.mycompany.com", "securityHeader");
oHeaderElement.setPrefix("sec");
oHeaderElement.setMustUnderstand(false);
oElement = oHeaderElement.addChildElement("username");
oElement.addTextNode("myusername");
oElement = oHeaderElement.addChildElement("password");
oElement.addTextNode("mypassword");
// You can create client code something like this..
MySampleServiceServiceLocator service = new MySampleServiceServiceLocator();
service.setMySampleServiceEndpointAddress("endpointURL");
MySampleWebService serv = service.getMySampleService();
MySampleServiceSoapBindingStub stub = (MySampleServiceSoapBindingStub)serv;
// add this header to your stubs
stub.setHeader(oHeaderElement);
// Finally call your web service methid
serv.getMyClaimStatus("XYZ001");
}
//It creates the custom header like this:
<soapenv:Header>
<sec:securityHeader xmlns:sec="http://ws.mycompany.com"
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">
<sec:username>myusername</sec:username>
<sec:password>mypassword</sec:password>
</sec:securityHeader>
</soapenv:Header>