• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to pass complex type parameter in web service while creating it through SAAJ

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

I am developing one webservice through SAAJ. I want to know, is the request and response are SOAP message or not? But i donot know how to pass the complex type parameter through SAAJ. Below is the code that i am using.

import goog.*;
import javax.xml.soap.*;
import java.net.*;
import javax.activation.*;
public class RmiTypeClient extends goog.Pressures{
public RmiTypeClient(String value){
super(value);
}
public static void main(String args[]){
try{
RmiTypeClient r1 = new RmiTypeClient("gramPressurePersqcm");
RmiTypeClient r2 = new RmiTypeClient("inchH2O60F");

MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();

SOAPBody body = message.getSOAPBody();

SOAPFactory soapFactory = SOAPFactory.newInstance();
Name operation = soapFactory.createName("changePressureUnit","webservicex","http://www.webservicex.net"); //changePressureUnit is the method name

SOAPBodyElement operElement = body.addBodyElement(operation);
Name param1 = soapFactory.createName("param1");
SOAPElement paramElement1 = operElement.addChildElement(param1);
paramElement1.addTextNode("12.0"); // this is first parameter

Name param2 = soapFactory.createName("param2");
SOAPElement paramElement2 = operElement.addChildElement(param2);
paramElement2.addTextNode("r1"); // this is second parameter, r1 is the complex type parameter of "RmiTypeClient" class. but i donot know how to pass it here??

Name param3 = soapFactory.createName("param3");
SOAPElement paramElement3 = operElement.addChildElement(param3);
paramElement3.addTextNode("r2"); // this is third parameter, r2 is the complex type parameter of "RmiTypeClient" class, but i donot know how to pass it here??

SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
SOAPConnection con = conFactory.createConnection();

URL serviceUrl = new URL("http://www.webservicex.net/CovertPressure.asmx?WSDL");

SOAPMessage response = con.call(message,serviceUrl);
SOAPBody resBody = response.getSOAPBody();
if(resBody.hasFault()){
SOAPFault fault = resBody.getFault();
System.out.println("Error occured at: "+fault.getFaultCode()+ " side coding");
System.out.println("reason: "+fault.getFaultString());
}else{
System.out.println("this is soap message");
}
}catch(Exception e){
System.out.println(e);
}
}
}

Please help me to resolve it.
Thanks in advance.
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Basically, I play with APACHE CXF to generate Client/Consumer side and TCPIP monitor to watch the request SOAP Message.
2. The SOAP message is



3. What you need to create/code is the ChangePressureUnit Element (complex type).
Add this ChangePressureUnit Element to the soap Body Element. Hope this help.

 
Sachin Mangla
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,
Thanks for the reply. But I am using axis2 at client/consume services.
I tried to check the request with TCP Tunnel, but it requires a port to whom it diverts from there port, which is not feasible in my case.

I also tried the case that you defined but not working, i make the request this way:

SOAPBodyElement operElement = body.addBodyElement(operation);
Name param1 = soapFactory.createName("PressureValue");
SOAPElement paramElement1 = operElement.addChildElement(param1);
paramElement1.addTextNode("12.0");

Name param2 = soapFactory.createName("fromPressureUnit");
SOAPElement paramElement2 = operElement.addChildElement(param2);
paramElement2.addTextNode("gramPressurePersqcm"); // i changed value here, but i donot understand that "changePressureUnit" method requires object of RmiTypeClient class, how it will treats this value as object

Name param3 = soapFactory.createName("toPressureUnit");
SOAPElement paramElement3 = operElement.addChildElement(param3);
paramElement3.addTextNode("inchH2O60F"); // same case here

it always give me this error:

Error occured at: Client side coding
reason: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)


Please suggest some other option which helps with axis2.

Thanks in advance
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I set TCP/IP Monitor:

1. Local Monitoring port: 18080
2. Monitor
Hostname www.webservicex.net
Port 80
Type HTTP
3. String targetEndPoint="http://localhost:18080/CovertPressure.asmx";
This way I see the request soap message going out from the client side.

To solve the exception "Server did not recognize the value of HTTP Header SOAPAction"

From http://www.webservicex.net/CovertPressure.asmx?WSDL, there is an soapAction


So you need to set the HTTP Header SOAPAction to http://www.webserviceX.NET/ChangePressureUnit




 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Here is a way to create ChangePressureUnit Element


 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
executing web service client i got the following error: please help me

javax.xml.ws.soap.SOAPFaultException: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
 
reply
    Bookmark Topic Watch Topic
  • New Topic