Hi,
I am using axis2 and I created a
test service and client. I used the wsdl file generated from the service and used the emitted classes to create the client. I am trying to send xml in
soap messages, both in the request and response, but what is happening is, the stub is adding its own element with ns1 namespace around my soap elements.
This is the soap request I am supposed to send:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soap:search xmlns:soap="http://example1.org/example1">
<soap:SSN>123</soap:SSN>
<soap:FirstName>ABC</soap:FirstName>
<soap:LastName>DEF</soap:LastName>
</soap:search>
</soapenv:Body>
</soapenv:Envelope>
but this is how it is sending it when I call the search method in the Stub
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns1:search xmlns:ns1="http://com/xsd">
<ns1:search>
<soap:search xmlns:soap="http://example1.org/example1">
<soap:SSN>123</soap:SSN>
<soap:FirstName>ABC</soap:FirstName>
<soap:LastName>DEF</soap:LastName>
</soap:search>
</ns1:search>
</ns1:search>
</soapenv:Body>
</soapenv:Envelope>
It is adding its own <ns1:search> elements around my message. So obviously when i am trying to extract the elements from the message I am getting the wrong values.
Can you please tell me how I can avoid this?
My service looks something like this:
public class SampleService {
private HashMap<
String, String> searchMap = new HashMap<String, String>();
public OMElement search(OMElement element)
throws XMLStreamException {
element.build();
element.detach();
String rootName = element.getLocalName();
System.out.println("Reading "+ rootName+ " element");
Iterator allChildren = element.getChildElements();
while (allChildren.hasNext()) {
OMElement omElement = (OMElement) allChildren.next();
String attr = omElement.getLocalName();
System.out.println("This is the Key element of search:" + attr);
System.out.println("");
String value = omElement.getText();
System.out.println("This is the Value element of search:" + value);
System.out.println("");
searchMap.put(attr, value);
}
System.out.println("The value for key SSN :" + searchMap.get("SSN"));
System.out.println("The value for key FirstName :" + searchMap.get("FirstName"));
System.out.println("The value for key LastName :" + searchMap.get("LastName"));
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace(
"http://example1.org/example1", "soap");
OMElement method = fac.createOMElement("searchResults", omNs);
return method;
}
}
My Client looks like this
public class SampleClient {
private static final String EPR = "http://localhost:9080/axis2/services/SOAPAPI";
private static EndpointReference targetEPR =
new EndpointReference("http://localhost:9080/axis2/services/SOAPAPI");
public static OMElement searchRequest() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://example1.org/example1", "soap");
OMElement method = fac.createOMElement("search", omNs);
OMElement sv = fac.createOMElement("SSN", omNs);
sv.addChild(fac.createOMText(sv, "123"));
method.addChild(sv);
OMElement sv2 = fac.createOMElement("FirstName", omNs);
sv2.addChild(fac.createOMText(sv2, "ABC"));
method.addChild(sv2);
OMElement sv3 = fac.createOMElement("LastName", omNs);
sv3.addChild(fac.createOMText(sv3, "DEF"));
method.addChild(sv3);
return method;
}
public static void main(String[] args) {
try {
OMElement request = SampleClient.searchRequest();
SOAPAPIStub stub = new SOAPAPIStub(EPR);
stub._getServiceClient().getOptions().setTransportInProtocol(Constants.TRANSPORT_HTTP);
Search search = new Search();
search.setSearch(request);
SearchResponse response = stub.search(search);
OMElement element = response.get_return();
} catch (Exception e) { //(XMLStreamException e) {
// e.printStackTrace();
System.out.println(e.toString());
}
}
}
Please let me know if you need more information.
Thanks!