Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAX-RPC Client invoking Document based web service

 
Kiran Kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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}
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic