WSDL creating parsing Error - java

I am trying to expose SOAP web service. For this I am using apache camel. So I have to use apache CXF to expose SOAP web service. But I am getting below error.
org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 223; The
value of the attribute
"prefix="xmlns",localpart="tns",rawname="xmlns:tns"" is invalid.
Prefixed namespace bindings may not be empty.
This is following I have coded.
#WebService(endpointInterface="com.ericsson.fdp.SOAP.FulfillmentService", targetNamespace = "http://apache.org/hello_world_soap_http",portName="FulfillmentServicePort",serviceName="FulfillmentService")
public class FulfillmentServiceImpl implements FulfillmentService{
#Produce(uri = "servlet:///fulfillmentService?servletName=FulfillmentService&matchOnUriPrefix=false")
private ProducerTemplate template;
#Override
public FulfillmentResponse buyProduct(String input, String userName, String password, String msisdn, String iname) {
Map<String,Object> queryMap = new HashMap<>();
queryMap.put("input", input);
queryMap.put("password", password);
queryMap.put("msisdn", msisdn);
queryMap.put("iname", iname);
String response = (String) template.requestBodyAndHeaders(null, queryMap);
FulfillmentResponse responseObject=null;
try {
responseObject = XmlUtil.unmarshall(response, FulfillmentResponse.class);
} catch (JAXBException e) {
e.printStackTrace();
}
return responseObject;
}
}
This is interface for above implementation
#WebService(name="fulfillmentService", targetNamespace = "http://apache.org/hello_world_soap_http",portName="FulfillmentServicePort",serviceName="FulfillmentService")
public interface FulfillmentService {
public FulfillmentResponse buyProduct(String input,String userName, String password,String msisdn,String iname);
}
I tried to check into. This is WSDL that is created for above code.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="fulfillmentService" targetNamespace="" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://apache.org/hello_world_soap_http" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:import namespace="http://apache.org/hello_world_soap_http" location="fulfillmentService.wsdl">
</wsdl:import>
<wsdl:binding name="fulfillmentServiceSoapBinding" type="ns1:fulfillmentService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="buyProduct">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="buyProduct">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="buyProductResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="fulfillmentService">
<wsdl:port name="fulfillmentServicePort" binding="fulfillmentServiceSoapBinding">
<soap:address location="http://127.0.0.1:8980/cisBusiness/services/fulFillment"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
How I can fix this error?

Try adding same namespace to the following.
xmlns:tns="http://www.example.org" targetNamespace="http://www.example.org"
Ofcourse, you can change the "http://www.example.org" to something of your liking...

Related

Creating and sending a SOAP message in java to a very simple web service

I am currently trying to create and send a SOAP message to a very simple web service I've created myself.
Obviously the webservice have a wsdl file, which you can see here:
wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://service.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://service.com">
<wsdl:documentation>Please Type your service description here</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.com">
<xs:element name="echoTest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="echoString" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="echoTestResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="echoTestRequest">
<wsdl:part name="parameters" element="ns:echoTest"/>
</wsdl:message>
<wsdl:message name="echoTestResponse">
<wsdl:part name="parameters" element="ns:echoTestResponse"/>
</wsdl:message>
<wsdl:portType name="RequestHandlerPortType">
<wsdl:operation name="echoTest">
<wsdl:input message="ns:echoTestRequest" wsaw:Action="urn:echoTest"/>
<wsdl:output message="ns:echoTestResponse" wsaw:Action="urn:echoTestResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="RequestHandlerSoap11Binding" type="ns:RequestHandlerPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="echoTest">
<soap:operation soapAction="urn:echoTest" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="RequestHandlerSoap12Binding" type="ns:RequestHandlerPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="echoTest">
<soap12:operation soapAction="urn:echoTest" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="RequestHandlerHttpBinding" type="ns:RequestHandlerPortType">
<http:binding verb="POST"/>
<wsdl:operation name="echoTest">
<http:operation location="echoTest"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RequestHandler">
<wsdl:port name="RequestHandlerHttpSoap11Endpoint" binding="ns:RequestHandlerSoap11Binding">
<soap:address location="http://localhost:8181/PayCheckHandlerMainWebService/services/RequestHandler.RequestHandlerHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="RequestHandlerHttpSoap12Endpoint" binding="ns:RequestHandlerSoap12Binding">
<soap12:address location="http://localhost:8181/PayCheckHandlerMainWebService/services/RequestHandler.RequestHandlerHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="RequestHandlerHttpEndpoint" binding="ns:RequestHandlerHttpBinding">
<http:address location="http://localhost:8181/PayCheckHandlerMainWebService/services/RequestHandler.RequestHandlerHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I've then used the google chrome plugin called Wizdler, to find out how the structure of soap messages should look like. THe Soap message for this example, should look like this.
<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
<Body>
<echoTest xmlns="http://service.com">
<echoString>[string?]</echoString>
</echoTest>
</Body>
</Envelope>
So a pretty simple and straightforward SOAP message.. Nevertheless, Ican get it to work.
I am trying to create the SOAP message with the following code:
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://service.com";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
// SOAP Body
SOAPBody soapBody = envelope.getBody();
soapBody.addNamespaceDeclaration("", serverURI);
SOAPElement soapBodyElem = soapBody.addChildElement("echoTest");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("echoString");
soapBodyElem1.addTextNode("HELLO?!?");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("RequestHandler", serverURI);
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
The above code, produces the following SOAP message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/>
<SOAP-ENV:Header/>
<SOAP-ENV:Body xmlns="http://service.com">
<echoTest xmlns="">
<echoString xmlns="http://service.com">HELLO?!?</echoString>
</echoTest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I don't know why the echoString get the xmlns="http://service.com".. it should be in the echoTest tag instead.. and I guess this could be a part of the problem.
The response message looks like this:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>namespace mismatch require http://service.com found none</faultstring>
<detail />
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
As can figure out, there is a problem with the namespace, but i seems like no matter what I do, the problem still occurs.
I hope someone can see the problem and maybe can provide a solution.
Any help will be greatly appreciated.
SOAPElement soapBodyElem = soapBody.addChildElement("echoTest","", serverURI);
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("echoString","", serverURI);
But why are you constructing your SOAP explicitly?
If there is no particular reason, then use wsimport. Java classes + JAXB annotations will help you.
Anyways, after trying for a loooong time, I finally got it to work.. and of course just right after posting this question, I got it to work. So here is the complete java code for the problem described in the question:
public class PayCheckHandler {
public PayCheckHandler() throws Exception {
// TODO Auto-generated method stub
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://localhost:8181/PayCheckHandlerMainWebService/services/RequestHandler?wsdl";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// print SOAP Response
System.out.println();
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://service.com";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
// SOAP Body
SOAPBodyElement element = body.addBodyElement(envelope.createName("echoTest", "", serverURI));
element.addChildElement("echoString").addTextNode("Hello!!!");
return soapMessage;
}
public static void main(String[] args) throws Exception {
new PayCheckHandler();
}
}
Btw. if I absolutely didn't have to create my own SOAP messages manually, I would do as artem.ponchakov suggested.

Trying to create a Client for a JAX WS Provider using JAXWSProxyFactoryBean

Ok, so I came across an example on how to create a client using JaxWsProxyFactoryBean for an SEI-
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:9000/helloWorld");
HelloWorld client = (HelloWorld) factory.create();
String reply = client.sayHi("HI");
System.out.println("Server said: " + reply);
System.exit(0); `
I tried to duplicate it for a JAX WS Provider Interface(since I couldn't find any examples)-
public static void main(String args[]) throws Exception {
MessageFactory mf = MessageFactory.newInstance();
System.out.println("TEST");
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
System.out.println("TEST");
factory.setAddress("http://localhost:8123/SoapContext/SoapPort1");
System.out.println("TEST");
factory.setServiceClass(Provider.class);
System.out.println("TEST");
factory.setWsdlLocation("http://localhost:8123/SoapContext/SoapPort1?wsdl");
System.out.println("TEST");
Provider<SOAPMessage> client = (Provider<SOAPMessage>) factory.create();
//Below Never Prints
System.out.println("TEST");
SOAPFactory sf = SOAPFactory.newInstance();
SOAPMessage request = mf.createMessage();
SOAPBody reqBody = request.getSOAPBody();
Name bodyName = sf.createName("ClientInsertedmainbody");
reqBody.addBodyElement(bodyName);
SOAPElement reqContent = reqBody.addChildElement("client");
reqContent.setValue("JPFB\n");
SOAPElement reqContent2 = reqBody.addChildElement("client2");
reqContent2.setValue("clieennnt\n");
System.out.println(" Request from client " + request.getSOAPBody().getTextContent());
System.out.println("Invoking server through JPFB interface using SOAPMessage");
SOAPMessage soapResp = client.invoke(request);
System.out.println("Response from server: " + soapResp.getSOAPBody().getTextContent());
System.exit(0);
}
Anyway, it fails. The server is working fine. It responded when I used a client created in another way (Using a Dispatch instance).
The error messages -
May 19, 2015 6:44:55 PM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://ws.xml.javax/}ProviderService from WSDL: http://localhost:8123/SoapContext/SoapPort1?wsdl
Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://ws.xml.javax/}ProviderService.
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:158)
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:405)
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:525)
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:199)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
at main.JSFBClient.main(JSFBClient.java:40)
Right the question: What's wrong and how do I fix it? I get the nagging feeling that the code I wrote might be completely off, but hey in that case, how would I do it?
EDIT : Here is the wsdl
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost:8123/SoapContext/SoapPort1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://server/" name="Provider1" targetNamespace="http://localhost:8123/SoapContext/SoapPort1">
<wsdl:import location="http://localhost:8123/SoapContext/SoapPort1?wsdl=Provider1.wsdl" namespace="http://server/">
</wsdl:import>
<wsdl:binding name="Provider1SoapBinding" type="ns1:Provider1">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="invoke">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="invoke">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="invokeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Provider1">
<wsdl:port binding="tns:Provider1SoapBinding" name="Provider1Port">
<soap:address location="http://localhost:8123/SoapContext/SoapPort1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Try to remove this line of code:
factory.setWsdlLocation("http://localhost:8123/SoapContext/SoapPort1");

How to communicate with JAX-WS based SOAP webservice from java?

I searched google, but i cant find a way to do this. I have a SOAP webservice built in netbeans with JAX-WS . Gerated wsdl cannot be accessed by my java client code. Is the way i am trying to access is wrong? someone help..
my web service code
#WebService(serviceName = "HolaMundo")
public class HolaMundo {
#WebMethod(operationName = "hello")
public String hello(#WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
}
generated wsdl
<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://publicar.ws.org.mx/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://publicar.ws.org.mx/" name="HolaMundo">
<types>
<xsd:schema>
<xsd:import namespace="http://publicar.ws.org.mx/" schemaLocation="http://localhost:8084/HolaMundo/HolaMundo?xsd=1"/>
</xsd:schema>
</types>
<message name="hello">
<part name="parameters" element="tns:hello"/>
</message>
<message name="helloResponse">
<part name="parameters" element="tns:helloResponse"/>
</message>
<portType name="HolaMundo">
<operation name="hello">
<input wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloRequest" message="tns:hello"/>
<output wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloResponse" message="tns:helloResponse"/>
</operation>
</portType>
<binding name="HolaMundoPortBinding" type="tns:HolaMundo">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="hello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HolaMundo">
<port name="HolaMundoPort" binding="tns:HolaMundoPortBinding">
<soap:address location="http://localhost:8084/HolaMundo/HolaMundo"/>
</port>
</service>
</definitions>
Java client code
public class cliente {
public cliente() {
}
public static String consumir(Object[] parametros){
String regresar = null;
Service service = null;
Call call = null;
String endpoint = null;
try {
endpoint = "http://localhost:8084/HolaMundo/HolaMundo";
service = new Service();
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("hello");
regresar=String.valueOf(call.invoke(parametros));
}// try
catch (Exception e) {
e.printStackTrace();
}// catch
finally {
return regresar;
}// finally
}
public static void main(String[] args) {
try {
String parametro = "José";
String respuesta = consumir(new Object[]{parametro});
System.out.println("respuesta: --->" + respuesta);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
but i am getting the error
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultSubcode:
faultString: Cannot find dispatch method for {}hello
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:Cannot find dispatch method for {}hello
help me. thanks

Axis WSDL2Java generation issue

I've wrote some simple service that consists of several files (wsdl, xsd).
In xsd file I've got following definition:
<xs:complexType name="ServerMessage">
<xs:sequence>
<xs:element name="type" type="xs:int"/>
<xs:element name="info" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ServerMessage" type="tns:ServerMessage"/>
Then this element is referenced in wsdl file like this
<wsdl:message name="createItemFault">
<wsdl:part name="createItemFault" element="tns:ServerMessage"/>
</wsdl:message>
<wsdl:portType name="Service">
<wsdl:operation name="createItem">
<wsdl:input message="tns:createItemRequest"/>
<wsdl:output message="tns:createItemResponse"/>
<wsdl:fault name="Fault" message="tns:createItemFault"/>
</wsdl:operation>
And at last
<wsdl:binding name="ServiceBinding" type="intf:Service">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="createItem">
<soap:operation soapAction="http://test.com/createItem"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="Fault">
<soap:fault name="Fault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
After launching WSDL2Java I receive the following code
public interface ServerMessage extends org.apache.xmlbeans.XmlObject
{
How come ServerMessage becomes defined like this? When I've used WSDL2Java provided by Axis1 final definition in java file was like this
public class ServerMessage extends org.apache.axis.AxisFault implements java.io.Serializable
And after Axis2 generation resulting "item" is drastically differs, it's not even throwable. What am I doing wrong?
From that WSDL you should get a CreateItemFault (due to the wsdl:message name) that looks something like:
public class CreateItemFault extends java.lang.Exception {
private org.example.www.service.ServerMessageDocument faultMessage;
...
}
That ServerMessageDocument probably looks like:
public interface ServerMessageDocument extends org.apache.xmlbeans.XmlObject {
...
org.example.www.service.ServerMessage getServerMessage();
void setServerMessage(org.example.www.service.ServerMessage serverMessage);
org.example.www.service.ServerMessage addNewServerMessage();
...
}
And here's where we get to your ServerMessage:
public interface ServerMessage extends org.apache.xmlbeans.XmlObject {
...
}
The method signature should throw a CreateItemFault, though.

Problem with deserialization of String sent over wire with XStream

I am trying to create a simple webservice which takes a String as input and returns string as output.
I am using Ecelipse Helios and Axis 2.15.
I am writing simple WSDL for the same.
I am generating the stubs using code generator.
New ->code generator -> java class from wsdl-> give WSDL and generates the java skeletons.
And in the skelton I am just print the value what is coming as parameter. and returning the same value.
I have written client code to invoke the method of the webservice. which takes a String.
but when I am trying to invoke the method I am getting following exception and it's not hitting the webservice.
Infact I am using XStream along with Client/WebService.
Code goes like this for the webservice skeleton:
public com.url.pkg.ShowInputResponse showInput(
com.url.pkg.ShowInput showInput) {
// TODO : fill this with the necessary business logic
String inputString = showInput.getInputString();
System.out.println("INput String is :\n" + inputString);
XStream xStream = new XStream();
System.out.println("After XStream Declaration...");
SOVO vo = null;
try {
vo = (SOVO) xStream.fromXML(inputString);
} catch (Throwable e) {
System.out.println(e);
e.printStackTrace();
}
System.out.println("After SOVO casting from XML");
System.out.println(vo.getName());
System.out.println(vo.getParams());
// TODO: business logic
ShowInputResponse response = new ShowInputResponse();
response.set_return(inputString);
return response;
}
My client code goes like this :
public static void main(String[] args) throws Exception {
BasicServiceStub stub = new BasicServiceStub();
ShowInput request = new ShowInput();
SOVO sovo = new SOVO();
sovo.setName("I am the post for SO");
Map params = new HashMap();
params.put("key1", "val1");
params.put("key2", "val2");
sovo.setParams(params);
XStream xStream = new XStream();
String soVoString = xStream.toXML(sovo);
// System.out.println(soVoString);
request.setInputString(soVoString);
ShowInputResponse response = stub.showInput(request);
System.out.println("....................................");
System.out.println("response = " + response.get_return());
}
SOVO is a simple POJO which is present at both client and webservice side.
public class SOVO {
private String name;
private Map params;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map getParams() {
return params;
}
public void setParams(Map params) {
this.params = params;
}
}
And last but most important WSDL is here:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://pkg.url.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://pkg.url.com">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://pkg.url.com">
<xs:element name="showInput">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="inputString" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="showInputResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="showInputRequest">
<wsdl:part name="parameters" element="ns:showInput"/>
</wsdl:message>
<wsdl:message name="showInputResponse">
<wsdl:part name="parameters" element="ns:showInputResponse"/>
</wsdl:message>
<wsdl:portType name="BasicServicePortType">
<wsdl:operation name="showInput">
<wsdl:input message="ns:showInputRequest" wsaw:Action="urn:showInput"/>
<wsdl:output message="ns:showInputResponse" wsaw:Action="urn:showInputResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicServiceSoap11Binding" type="ns:BasicServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="showInput">
<soap:operation soapAction="urn:showInput" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="BasicServiceSoap12Binding" type="ns:BasicServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="showInput">
<soap12:operation soapAction="urn:showInput" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="BasicServiceHttpBinding" type="ns:BasicServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="showInput">
<http:operation location="BasicService/showInput"/>
<wsdl:input>
<mime:content type="text/xml" part="showInput"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="showInput"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BasicService">
<wsdl:port name="BasicServiceHttpSoap11Endpoint" binding="ns:BasicServiceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/BasicService"/>
</wsdl:port>
<wsdl:port name="BasicServiceHttpSoap12Endpoint" binding="ns:BasicServiceSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/BasicService"/>
</wsdl:port>
<wsdl:port name="BasicServiceHttpEndpoint" binding="ns:BasicServiceHttpBinding">
<http:address location="http://localhost:8080/axis2/services/BasicService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
And the Stack trace for the exception I must modify :
I am not very sure if its hitting the webservice layer.
Caused by: org.apache.axis2.AxisFault: string
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:446)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.url.pkg.BasicServiceStub.showInput(BasicServiceStub.java:184)
at com.url.pkg.Client.main(Client.java:30)
It looks like more its some problem with XStream desirialization. Even though SOVO is in the classpath why its happening? Am I missing something?
When I try sending XXXXX as string it tells:
only whitespace content allowed before start tag and not X (position: START_DOCUMENT seen X... #1:1)
When i try sending "some value" it says:
only whitespace content allowed before start tag and not s (position: START_DOCUMENT seen s... #1:1)
I am not sure what's wrong.
I would suggest the following:
Test the service with another client
Use soapUI to generate a valid test request for your showInput method. If you don't get any errors using this tool, you know your service is working fine. If you do get an error, then you know to start digging around in your service code.
Enable client side logging for SOAP messages
Add these JVM options when running your client:
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.httpclient.wire=debug
-Dorg.apache.commons.logging.simplelog.log.org.apache.commons.httpclient=debug
This will let you to see the SOAP messages that get transmitted. Pay close attention to content appearing before your start tags like the error message says.

Categories