Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do i get the Soap envelope from a  Axis webservice call

Posted on 2009-05-13
8
Medium Priority
?
1,898 Views
Last Modified: 2013-11-19
Hi ,
    I am generating a wsdl through Axis and calling its method using Java Stub.I want to be able to be able to retrive the SoapEnvelope generated from the method call and parse it.Is there any API to do this?
0
Comment
Question by:res_this
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 24382722
This actually depends on how you are invoking the web service, if you are creating a axis stub and invoking the web service then, you can do something like this, But please note this works only after the call happens else returns null

In you xxxxxSoapBindingStub class in the particular method where u wanna capture req/res xml just add the following lines after the invoke() call.

Here is a sample from my helloService which takes a name.

 java.lang.Object _resp = _call.invoke(new java.lang.Object[] {name});
	 System.out.println(_call.getMessageContext().getRequestMessage().getSOAPPartAsString());
 System.out.println(_call.getResponseMessage().getSOAPPartAsString());

Open in new window

0
 

Author Comment

by:res_this
ID: 24391473
Hi,
  Thanks , but method call is going through the AxisServlet's doPost methood and through rpc to the webservice method.I am not using stubs .I tried to redirect to a custom servlet class which extends AxisServlet and could get hold of the request object.I need to pass one of the arguments in the request header to my webservice method.I had read about using MessageContext's SOAPMessage header  object to pass parameters , but not sure Can you help with this regard
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 24392212
>>.I need to pass one of the arguments in the request header to my webservice method
 can you clarify this?
 All I want to know is weather you want to add SOAP Header? or HTTP Header?
I am also wondering why is that you are extending a axis servlet?

First can you please tell are you coding for webservice implementation or the webservice client implementation?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:res_this
ID: 24394267
i am calling a webservice method say testmethod(x,y,z).When the Axis Servlet intercepts this method call from the webservice caller,the request object has a value in its header say m=n which I have to access inside my webservice method testmethod..When i print the incoming request inputstream(whose code i have attached below), i get the following

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:c2o="http://optinuity.com/c2o" xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><wsa:mID>9a7ca1dc-5879-4c2f-927c-c67f8b462cb5</wsa:mID><wsa:ReplyTo>http://testbox:8080/itpam/soap</wsa:ReplyTo><wsa:Action>testMethod</wsa:Action><wsa:ReferenceParameters><c2o:ReplyMethod>AsyncSoapResponse</c2o:ReplyMethod></wsa:ReferenceParameters></SOAP-ENV:Header><SOAP-ENV:Body><testMethod xmlns="urn:usmRequestService">
<sessionID/>
<x>10001</x>
<y>1</y>
<z>10102</z>
</testMethod></SOAP-ENV:Body></SOAP-ENV:Envelope>

I need to access the mID value inside the testmethod webservicecall.That's the reason I extending the Axis Servlet to get hold of the request header info.
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response){
    try{
      
      
      
     System.out.println(request.getHeaderNames());
  // Traverse the HTTP headers and show them on the screen
     for(Enumeration enumr = request.getHeaderNames(); enumr.hasMoreElements(); ) {
     String header = (String)enumr.nextElement();
     String value = request.getHeader(header);
     System.out.println(" "+header+" = "+value);
     }
  
     super.doPost(request,response);
    }
    catch(Exception e){
      
      e.printStackTrace();
    }
    }

Open in new window

0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 24409626
>>  String value = request.getHeader(header);
According me this only give access to HTTP Header and not the SOap Header,

Can you show me the code where you are actrually making the request to the web service.
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 24409642
if you ask ideally you need to do something like this, create a soap client (stub) using axis and then invoke the methods of this stub (operations) via your servlet and then u can use my previous apporach, else u can try a direct client call some thing like this  http://www.experts-exchange.com/Q_23396120.html
0
 

Author Comment

by:res_this
ID: 24411807
Hi all,
  Thanks for the comments.The webservice call is made by a 3rd party component.According to my previous comment, the request inputstream does contain the soap envelope information.However, i was able to get this working , by adding the following code in my webservice method.
 MessageContext mc = MessageContext.getCurrentContext();
        MimeHeaders mh=mc.getRequestMessage().getMimeHeaders();
        String[] mhStr = mh.getHeader("mID");
        log.info("Message ID"+mhStr[0]);

This is working fine.Is there any problem with this approach

0
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 2000 total points
ID: 24412438
I am actually wondering how is that code working because as per the documentation( as well as the naming style) it says

"getMimeHeaders():
          Returns all the transport-specific MIME headers for this SOAPMessage object in a transport-independent fashion."

check:
http://ws.apache.org/axis/java/apiDocs/javax/xml/soap/SOAPMessage.html

So ideally it must give u only HTTP header and not soap header, as your Mid is coming as part of the soap header it must have been something like this
MessageContext mc = MessageContext.getCurrentContext();
        Message message=mc.getRequestMessage();
 
SOAPPart sp = message.getSOAPPart();
 SOAPEnvelope se = sp.getEnvelope();
 SOAPHeader sh = se.getHeader();
Iterator litr = sh.examineAllHeaderElements();
 
while(litr.hasNext()) {
 
     SOAPHeaderElement  element = ( SOAPHeaderElement )litr.next(); 
  //print the element actually element.getChildElements(); should give u the actual headers.
} 

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question