It's not a secret anymore!*
The moose likes Web Services and the fly likes JAX-RPC Client invoking Document based web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX-RPC Client invoking Document based web service" Watch "JAX-RPC Client invoking Document based web service" New topic
Author

JAX-RPC Client invoking Document based web service

Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
Hi All,

I am trying to code a JAX-RPC client invoking a document based web service (i.e, style = "document" and input/output use="literal".



I am not sure what should be supplied to the call.invoke(..). I want to send the string 'xmltobeSent'. but have no clue of how to do it for invoking a doc based web service.

Can someone please through some pointers?

Thanks in advance,
Kiran


------------<br />SCJP
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi Kiran,
I think you can use javax.xml.transform.Source and javax.xml.stream.StreamSource to 'wrap' your xml before send it.

Example:


Hope this helps and correct me if I am wrong...

thanks
daniel
Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
Hi Fisher,

Thanks for your response. But, call.invoke(..) doesn't take Source as arg right? It only supports Object[].

Thanks,
Kiran
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by Kiran Kumar:
Hi Fisher,

Thanks for your response. But, call.invoke(..) doesn't take Source as arg right? It only supports Object[].

Thanks,
Kiran


new Object[]{Source}


Groovy
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Kiran,

I want to know if using call.invoke is the only way of invoking document/literal WS. Can't i use stub classes.
Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
Fisher,

I tried what you said, but I get a run-time exception like this..



I think this is because, the schema of the xml I send as request contains complex elements. Is there no way to invoke a doc/literal based web service using a dynamic invoker in JAX-RPC world?

Pradeep,
Since I want to invoke using a dynamic client, I am not taking the stub approach.

Thanks and regards,
Kiran
susha bhogs
Greenhorn

Joined: Mar 29, 2006
Posts: 6
Reason for failure is that the SOAP request to another service does not contain the the Service name- in order to get around is to insert this manually

Before insertion -
<xml-fragment>
<Elements> complex structure....</elements>
</xml-fragment>

Repalce <xml-fragment> with uour service i.e.
<getMyData xmlns=..... xmlns:s1=......>
<Elements>..complex structure..</elements>
</getMyData>


==== code is below

public SOAPEnvelope getEnv() {
String serviceHeader="<getMyData xmlns=..... xmlns:s1=......>"

String xmlBean = param.xmlText();
StringBuffer sb = new StringBuffer();
String newXMLBean = xmlBean.substring(14, xmlBean.length() - 15);
sb.append(serviceConfig.get("serviceHeader"));
sb.append("<element>");
sb.append(newXMLBean);
sb.append("</elements>");
sb.append("</");
sb.append(serviceConfig.get("operation"));
sb.append(">");

Document request = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);

DocumentBuilder builder = factory.newDocumentBuilder();
request = builder.parse(new java.io.ByteArrayInputStream(sb.toString().getBytes()));

SOAPBodyElement requestMessage = new SOAPBodyElement(request.getDocumentElement());

envelope = new SOAPEnvelope();
return envelope.addBodyElement(requestMessage);

}

Service service = new Service();
Call call = (Call) service.createCall(new QName("serviceport"),
new QName(("operation"));

call.setTargetEndpointAddress(new java.net.URL(("endpoint")));
SOAPEnvelope response = call.invoke(getEnv());
 
wood burning stoves
 
subject: JAX-RPC Client invoking Document based web service