Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

JAX-RPC Client invoking Document based web service

 
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
 
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
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • 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: 8943
Firefox Browser Spring Java
  • 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
 
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());
 
    Bookmark Topic Watch Topic
  • New Topic