Perl client to JAX-WS java server issue - java

I have a JAX-WS java server which publishes a web-service
#WebService(endpointInterface="calculator.operation.Calculator")
public class CalculatorWs implements Calculator{
public String[] add(String a) {
System.out.println(a);
String[] test = {"this", "that"};
System.out.println(test);
return test;
}
}
and
#WebService
#SOAPBinding(style=SOAPBinding.Style.DOCUMENT)
public interface Calculator {
String[] add(String a);
}
and have a perl client
use SOAP::Lite +trace => 'all';
$SOAP::Constants::PREFIX_ENV = 'soapenv';
$SOAP::Constants::PREFIX_ENC = "SOAP-ENC";
my $soap = SOAP::Lite
->service('http://localhost:8080/tomcat/calculator?wsdl')
->soapversion('1.1');
my $var = {'a' => "test"};
my $result = $soap -> add($var);
The problem I'm having is that the Java server does not receive the arguments passed by the Perl client, although the value returned by the Java server is received and recognized by the client.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsam="http://www.w3.org/2
007/05/addressing/metadata" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/
policy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="ht
tp://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://operation.calculator/
" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soapenv:Body><tns:add><c-gensym3
><a xsi:type="xsd:string">test</a></c-gensym3></tns:add></soapenv:Body></soapenv
:Envelope>
this is the SOAP request sent by the Perl client. Im assuming the way its building the SOAP request is to blame . But if anyone could help me figure it out, would be greatly appreciated. Thanks.
(edit)
Here is the WSDL generated by JAX-WS:
<?xml version="1.0" encoding="UTF-8" ?>
- <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-.
-->
- <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-.
-->
- <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://operation.calculator/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://operation.calculator/" name="CalculatorWsService">
- <types>
- <xsd:schema>
<xsd:import namespace="http://operation.calculator/" schemaLocation="http://localhost:8080/tomcat/calculator?xsd=1" />
</xsd:schema>
</types>
- <message name="add">
<part name="parameters" element="tns:add" />
</message>
- <message name="addResponse">
<part name="parameters" element="tns:addResponse" />
</message>
- <portType name="Calculator">
- <operation name="add">
<input wsam:Action="http://operation.calculator/Calculator/addRequest" message="tns:add" />
<output wsam:Action="http://operation.calculator/Calculator/addResponse" message="tns:addResponse" />
</operation>
</portType>
- <binding name="CalculatorWsPortBinding" type="tns:Calculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="add">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="CalculatorWsService">
- <port name="CalculatorWsPort" binding="tns:CalculatorWsPortBinding">
<soap:address location="http://localhost:8080/tomcat/calculator" />
</port>
</service>
</definitions>

Showing the java function is great for java programmers, you need to show the WSDL or sample SOAP (read XML) invocation ... my guess, all you need
my $result = $soap -> add( 'test');
You should know SOAP::Simple is better at wsdl than SOAP::Lite

I was having the same problem. I made it work with the following two changes:
Name your arguments as in the XSD (http://localhost:8080/tomcat/calculator?xsd=1)
Don't use the default namespace, but a namespace prefix for the SOAP method (ns() method).
Example code:
my $soap = SOAP::Lite
-> proxy('http://localhost:8080/tomcat/calculator')
-> ns ('http://operation.calculator/');
my $response = $soap->call('add', SOAP::Data->name( arg0 => 'Peter Pan'));

Related

SOAP client using wsdl2java and Apache CXF

I ran wsdl2java command using Apache CXF codegen plugin. Excerpt from my WSDL:
<!-- submitSMSv3 -->
<message name="submitSMSv3">
<part name="parameters" element="tns:submitSMSv3"></part>
<!--<part name="gdspHeader" element="tns:gdspHeader"></part>-->
</message>
<message name="submitSMSv3Response">
<part name="result" element="tns:submitSMSv3Response"></part>
</message>
<portType name="SMSv3">
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
</jaxws:bindings>
<operation name="SubmitSMSv3" parameterOrder="parameters">
<input message="tns:submitSMSv3"></input>
<output message="tns:submitSMSv3Response"></output>
</operation>
</portType>
<binding name="SubmitSMSv3PortBinding" type="tns:SMSv3">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="SubmitSMSv3">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal" parts="parameters"></soap:body>
<!--<soap:header message="tns:submitSMSv3" part="gdspHeader" use="literal"></soap:header>-->
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="SubmitSMSv3Service">
<port name="SubmitSMSv3Port" binding="tns:SubmitSMSv3PortBinding">
<soap:address location="http://localhost:${HttpDefaultPort}/GDSPWebServices/SMSv3Service"></soap:address>
</port>
</service>
When I invoke the service, my SOAP body looks like this:
<soap:Body>
<ns1:submitSMSv3 xmlns:ns1="http://ws.gdsp.vodafone.com/">
<ns2:arg0 xmlns:ns2="http://ws.gdsp.vodafone.com/">
<deviceId>xxxxxx</deviceId>
<messageData></messageData>
<messageType>Text</messageType>
</ns2:arg0>
</ns1:submitSMSv3>
</soap:Body>
But I don't want the code as it fails the web call, I want my soap body to look like this instead:
<soap:Body>
<ns1:submitSMSv3 xmlns:ns1="http://ws.gdsp.vodafone.com/">
<deviceId>xxxxxxx</deviceId>
<messageData></messageData>
<messageType>Text</messageType>
</ns1:submitSMSv3>
</soap:Body>
I'm not sure what to do in order to get it to be this way as I know this way works.
after many of difficulties with the POJO messaging format, I opted to use PAYLOAD and now everything is working as designed. I had to add a processor for the request and the response but it now works.

Invoke a SOAP web service method with simple parameters from browser using ONLY url

What controls if a web service method can be invoked from a browser via a URL or not?
The platform (among other things) on which the service is authored (java vs .net vs xxx)?
I know .net based web services provide a nice interface to invoke the methods.
Why does it not happen for java based ones?
Since in both cases it is soap, should they not behave identically?
What is .net implementation doing extra that java doesn't?
What are the necessary config settings/properties that control if a soap webservice is browser invokeable?
I have seen plenty of online examples where for simple arguments, the web service methods seem to be browser invokeable, via a URL.
But in my case, it doesn't seem to work.
I have a working web service (JAX-WS), wsdl as below:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://services/" name="MYServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://services/" schemaLocation="http://example.com:8888/myservice?xsd=1" />
</xsd:schema>
</types>
<message name="getToken">
<part name="parameters" element="tns:getToken" />
</message>
<message name="getTokenResponse">
<part name="parameters" element="tns:getTokenResponse" />
</message>
<portType name="MYService">
<operation name="getToken">
<input message="tns:getToken" />
<output message="tns:getTokenResponse" />
</operation>
</portType>
<binding name="MYServicePortBinding" type="tns:MYService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<operation name="getToken">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="MYServiceService">
<port name="MYServicePort" binding="tns:MYServicePortBinding">
<soap:address location="http://example.com:8888/myservice" />
</port>
</service>
</definitions>
Works fine (if consumed via client app, I get the method output successfully).
But when I try using via browser, I get a "No JAX-WS context information available" message.
http://example.com:8888/myservice?wsdl works fine, but
http://example.com:8888/myservice/getToken?param0=xxx&param1=yyy gives me the above message. param0,param1 are the same names I used in the implementation, and they are both of type String.
I am hosting the web service in a JRE 1.6 environment, as a stand alone Java program.

How to specify a java.util.HashMap (key ==> value) in wsdl

An existing WebService (written in PHP) specifies an Key, Value Store as xsd:struct. Because Axis doesn't know how to interpretate this, I like to download and patch the Wsdl for my personal use.
At the end, the generated Request should look like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:emn="interface.foobar">
<soap:Header/>
<soap:Body>
<emn:searchFoobar>
<emn:searchParameter>
<emn:username>xxxx</emn:username>
<emn:password>xxxx</emn:password>
<emn:maxHitCount>1</emn:maxHitCount>
<emn:sorting>distance</emn:sorting>
<emn:searchtext>example</emn:searchtext>
</emn:searchParameter>
</emn:searchFoobar>
</soap:Body>
</soap:Envelope>
In this example the searchParameter is used as an java.util.HashMap on my client. Its childern are the Key and Value entries.
It's like this:
<emn:hashmapName>
<key1>value1</key1>
<key2>value2</key2>
<key3>value3</key3>
</emn:hashmapName>
The full WSDL looks like this (at the end I like to replace the xsd:struct by an java.util.HashMap):
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://foobar.service.de/service/v2" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Soap_Manager" targetNamespace="http://foobar.service.de/service/v2">
<types>
<xsd:schema targetNamespace="http://foobar.service.de/service/v2"/>
</types>
<portType name="Soap_ManagerPort">
<operation name="searchFoo">
<documentation>searchFoo</documentation>
<input message="tns:searchFooIn"/>
<output message="tns:searchFooOut"/>
</operation>
</portType>
<binding name="Soap_ManagerBinding" type="tns:Soap_ManagerPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="searchFoo">
<soap:operation soapAction="http://foobar.service.de/service/v2#searchFoo"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://foobar.service.de/service/v2"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://foobar.service.de/service/v2"/>
</output>
</operation>
</binding>
<service name="Soap_ManagerService">
<port name="Soap_ManagerPort" binding="tns:Soap_ManagerBinding">
<soap:address location="http://foobar.service.de/service/v2"/>
</port>
</service>
<message name="searchFooIn">
<part name="param" type="xsd:struct"/>
</message>
<message name="searchFooOut">
<part name="return" type="xsd:struct"/>
</message>
</definitions>
Could somebody show me how specify a java.util.HashMap for this kind of use?
Download apache axis from here Link to download
Once you download it, unzip it or follow the installation instructions. It comes with a utility called wsdl2java that will read in your wsdl file and build the java classes for it.
I saved your wsdl from above to a file named c:\temp\test.wsdl
Then I ran the wsdl2java command against it like this:
wsdl2java -uri c:\temp\test.wsdl
It generated a source folder with the package names from your wsdl and 2 java classes that can be used to call that service.

How to get complex soap response using java web-service?

i have create a web service to add two numbers using netbeans...and i am getting the following response
SOAP Response
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:AddResponse xmlns:ns2="http://calculator.me.org/">
<return>9</return>
</ns2:AddResponse>
</S:Body>
</S:Envelope>
Bu i need to generate the soap response xml of the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<CalculatedValue>9</CalculatedValue>
<response>
my java code:
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
/**
*
* #author User
*/
#WebService(serviceName = "CalculatorWS")
#Stateless()
public class CalculatorWS {
/**
* This is a sample web service operation
*/
#WebMethod(operationName = "hello")
public String hello(#WebParam(name = "name") String txt) {
return "<a>" + txt + "</a>";
}
/**
* Web service operation
*/
#WebMethod(operationName = "Add")
public int Add(#WebParam(name = "i") int i, #WebParam(name = "j") int j) {
//TODO write your implementation code here:
int k=i+j;
return k;
}
}
wsdl:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.1.1-b09 (branches/2.1-6834; 2011-07-16T17:14:48+0000) JAXWS-RI/2.2.5-promoted-b04 JAXWS/2.2. -->
<definitions targetNamespace="http://calculator.me.org/" name="CalculatorWS" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:tns="http://calculator.me.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<types>
<xsd:schema>
<xsd:import namespace="http://calculator.me.org/" schemaLocation="CalculatorWS_schema1.xsd"/>
</xsd:schema>
</types>
<message name="hello">
<part name="parameters" element="tns:hello"/>
</message>
<message name="helloResponse">
<part name="parameters" element="tns:helloResponse"/>
</message>
<message name="Add">
<part name="parameters" element="tns:Add"/>
</message>
<message name="AddResponse">
<part name="parameters" element="tns:AddResponse"/>
</message>
<portType name="CalculatorWS">
<operation name="hello">
<input wsam:Action="http://calculator.me.org/CalculatorWS/helloRequest" message="tns:hello"/>
<output wsam:Action="http://calculator.me.org/CalculatorWS/helloResponse" message="tns:helloResponse"/>
</operation>
<operation name="Add">
<input wsam:Action="http://calculator.me.org/CalculatorWS/AddRequest" message="tns:Add"/>
<output wsam:Action="http://calculator.me.org/CalculatorWS/AddResponse" message="tns:AddResponse"/>
</operation>
</portType>
<binding name="CalculatorWSPortBinding" type="tns:CalculatorWS">
<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>
<operation name="Add">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="CalculatorWS">
<port name="CalculatorWSPort" binding="tns:CalculatorWSPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
i searched a lot on this....but didn't get any answer.I found a similar post in stackoverflow with no correct answer.How to generate that particular soap response using the web-service?
It's not possible to get a reply like the one you posted. By definition a SOAP document (or message) must contain an Envelope and at least the Body element. See more in the SOAP specification.
Your only control is over the contents of the Body element, by specifying the operation style to be RPC (remote procedure call) or document (plain XML).

WSDL warning: not a SOAP port, it has no soap:address

I get these warnings when I create a Web Service Client using Netbeans v 6.7.1, providing the following wsdl.
parsing WSDL...
[WARNING] port
"ComposedWebServicePort" is not
a SOAP port, it has no soap:address
line 29 of
file:/C:/Users/blavi/Documents/NetBeansProjects/ComposedClient/xml-resources/web-service-references/ComposedWebService/wsdl/ComposedWebService.wsdl
[WARNING] port
"ComposedWebServiceServicePort": not a
standard SOAP port. The generated
artifacts may not work with JAXWS
runtime. line 29 of
file:/C:/Users/blavi/Documents/NetBeansProjects/ComposedClient/xml-resources/web-service-references/ComposedWebService/wsdl/ComposedWebService.wsdl
The WSDL which fires the warnings is:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" name="ComposedWebService" targetNamespace="http://j2ee.netbeans.org/wsdl/CompositionBpelModule/ComposedWebService" xmlns:ns0="http://www.w3.org/2001/XMLSchema" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap" xmlns:tns="http://j2ee.netbeans.org/wsdl/CompositionBpelModule/ComposedWebService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl">
<types/>
<message name="EnterComposition">
<part name="compositionIN" type="ns0:string"/>
</message>
<message name="ExitComposition">
<part name="compositionOUT" type="ns0:string"/>
</message>
<portType name="ComposedWebServicePortType">
<operation name="ComposedWebServiceSOperation">
<input message="tns:EnterComposition" name="input1"/>
<output message="tns:ExitComposition" name="output1"/>
</operation>
</portType>
<binding name="ComposedWebServiceBinding" type="tns:ComposedWebServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="ComposedWebServiceOperation">
<soap:operation soapAction="http://j2ee.netbeans.org/wsdl/CompositionBpelModule/ComposedWebService/ComposedWebServiceOperation" style="document"/>
<input name="input1">
<soap:body use="literal"/>
</input>
<output name="output1">
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ComposedWebService">
**<port binding="tns:ComposedWebServiceBinding" name="ComposedWebServicePort">**
<soap:address location="http://localhost:8184/ComposedWebService/ComposedWebServicePort"/>
</port>
</service>
<plnk:partnerLinkType name="ComposedWebServicePLT">
<plnk:role name="compositionPartnerLinkType" portType="tns:ComposedWebServicePortType"/>
</plnk:partnerLinkType>
</definitions>
The line marked with ** is line 29 where the warnings appear.
When I try to invoke the web service that has this wsdl, I always get Unsupported Endpoint Address Exception. Can these warnings and exception be related? How can I solve this?
Thank you
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
The SOAP namespace declaration is incorrect; it should have a trailing forward slash.
<part name="compositionOUT" type="ns0:string"/>
If I'm not mistaken, you need an element attribute here.
ComposedWebServiceServiceService
More concise names might make the document a little more readable.

Categories

Resources