Solved

Help Needed with SOAP And Apache Axis

Posted on 2008-06-11
15
3,659 Views
Last Modified: 2013-12-02
Hi.,
I am trying to develop a simple SOAP application using Axis.
I deployed axis in Apache Tomcat 6.
I have given server and client code in code snippet.


And when I try to execute the program I am getting this Exception in Tomcat Console

AxisFault
 faultCode: {http://xml.apache.org/axis/}Client.NoSOAPAction
 faultSubcode:
 faultString: no SOAPAction header!
 faultActor:
 faultNode:
 faultDetail:
        {http://xml.apache.org/axis/}stackTrace:no SOAPAction header!
        at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013)
        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
        at java.lang.Thread.run(Unknown Source)
        {http://xml.apache.org/axis/}hostname:GSPCW046
no SOAPAction header!
        at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013)
        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
        at java.lang.Thread.run(Unknown Source)

Thanks.
My Server code is : MessageService.jws

(I have copied this file in CATALIA_HOME\webapps\axis folder).

import org.w3c.dom.Element;

import javax.xml.soap.SOAPEnvelope;

import javax.xml.soap.Name;

import javax.xml.soap.SOAPBody;

import javax.xml.soap.SOAPBodyElement;

import javax.xml.soap.SOAPHeader;

import javax.xml.soap.SOAPElement;
 

public class MessageService

{

    public Element[] echoElements(Element [] elems)

    {

        return elems;

    }

   

    public void process(SOAPEnvelope req, SOAPEnvelope resp) throws javax.xml.soap.SOAPException

    {

        try

        {

            SOAPBody body = resp.getBody();

            System.out.println("\n\n");

            System.out.println(body);

            System.out.println("\n\n");

            Name ns0 =  resp.createName("TestNS0", "ns0", "http://example.com");

            Name ns1 =  resp.createName("TestNS1", "ns1", "http://example.com");

            SOAPElement bodyElmnt = body.addBodyElement(ns0);

            SOAPElement el = bodyElmnt.addChildElement(ns1);

            el.addTextNode("TEST RESPONSE");

        }

        catch(Exception exp)

        {

            exp.printStackTrace();

        }

    }

}
 

And Client Code is : TestClient.java
 

import java.io.ByteArrayInputStream;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import javax.xml.soap.MessageFactory;

import javax.xml.soap.SOAPEnvelope;

import javax.xml.soap.SOAPMessage;

import javax.xml.soap.SOAPPart;

import javax.xml.soap.SOAPConnection;

import javax.xml.soap.MimeHeaders;

import javax.xml.soap.SOAPConnectionFactory;

import javax.xml.soap.SOAPBodyElement;

import javax.xml.soap.SOAPBody;
 

public class TestClient

{

    public static void main(String [] args)

    {

        try

        {

            String        xmlString        =    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +

                                            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +

                                            "                   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +

                                            "                   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +

                                            " <soapenv:Header>\n" +

                                            "  <shw:Hello xmlns:shw=\"http://localhost:8080/axis/MessageService.jws\">\n" +

                                            "    <shw:Myname>Tony</shw:Myname>\n" +

                                            "  </shw:Hello>\n" +

                                            " </soapenv:Header>\n" +

                                            " <soapenv:Body>\n" +

                                            "  <shw:process xmlns:shw=\"http://localhost:8080/axis/MessageService.jws\">\n" +

                                            "    <shw:City>GENT</shw:City>\n" +

                                            "  </shw:process>\n" +

                                            " </soapenv:Body>\n" +

                                            "</soapenv:Envelope>";

           

            MessageFactory    mf            =    MessageFactory.newInstance();

            SOAPMessage        smsg        =    mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));

            SOAPPart        sp            =    smsg.getSOAPPart();

            SOAPEnvelope    se            =    (SOAPEnvelope)sp.getEnvelope();

           

            SOAPConnection    conn        =    SOAPConnectionFactory.newInstance().createConnection();

            SOAPMessage        response    =    conn.call(smsg, "http://localhost:8080/axis/MessageService.jws");

           

            System.out.println("Response : " + response.getSOAPBody());

         }

        catch (Exception e)

        {

            System.err.println(e.toString());

        }

    }

}

Open in new window

0
Comment
Question by:sandeep1984
  • 6
  • 6
  • 3
15 Comments
 
LVL 10

Expert Comment

by:mukundha_expert
Comment Utility
try MimeHeaders h = message.getMimeHeaders()
and set
h.setProperty( Call.SOAPACTION_USE_PROPERTY, new Boolean( true ) );
h.setProperty( Call.SOAPACTION_URI_PROPERTY, "<your_soap_action_uri>");
0
 
LVL 2

Author Comment

by:sandeep1984
Comment Utility
setProperty method s not available in MimeHeaders class.
0
 
LVL 10

Expert Comment

by:mukundha_expert
Comment Utility
sorry its addHeader()
0
 
LVL 2

Author Comment

by:sandeep1984
Comment Utility
I tried with this. Still getting the same error.
What might be the problem??

I am using MessageService.jws

Should I use "http://localhost:8080/axis/MessageService.jws?method=process"
or
"http://localhost:8080/axis/MessageService.jws"
for Call.SOAPACTION_URI_PROPERTY
SOAPConnection	conn		=	SOAPConnectionFactory.newInstance().createConnection();

MimeHeaders		h			=	new MimeHeaders();

SOAPMessage		smsg		=	mf.createMessage(h, new ByteArrayInputStream(xmlString.getBytes()));

h.addHeader(Call.SOAPACTION_USE_PROPERTY, "true");

h.addHeader(Call.SOAPACTION_URI_PROPERTY, "http://localhost:8080/axis/MessageService.jws?method=process");

SOAPMessage		response	=	conn.call(smsg, "http://localhost:8080/axis/MessageService.jws");

System.out.println("Response : " + response.getSOAPBody());

Open in new window

0
 
LVL 10

Expert Comment

by:mukundha_expert
Comment Utility
ths is your URI, "http://localhost:8080/axis/MessageService.jws"
adding this should work,

But this can be achieved more easily with JAXWS,

get the wsdl, generate the client stubs
and use them to call the webservice method

its simpler and easier, all the packaging and trasport is taken care by it


0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
Comment Utility
To get the exact SOAP action check your WSDL, or better search for "soapAction" in your WSDL you will find the exact Soap action you need to use for invocation.
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
Comment Utility
The way to add soapAction's in axis is options.setAction("your url");

you may like to follow this

http://www.mail-archive.com/axis-user@ws.apache.org/msg13649.html
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 2

Author Comment

by:sandeep1984
Comment Utility
How to create a wsdl for my JWS.
0
 
LVL 2

Author Comment

by:sandeep1984
Comment Utility
I have installed the Service sing AdminClient as follows

I have copied MessageService.class to : CATALINA_HOME/webapps/axis/WEB-INF/classes.

Then I copied deploy.wsdd & undeploy.wsdd to : CATALINA_HOME/webapps/axis/WEB-INF.

deploy.wsdd:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

 <service name="MyService" provider="java:RPC">
  <parameter name="className" value="MessageService"/>
  <parameter name="allowedMethods" value="*"/>
 </service>
</deployment>

undeploy.wsdd:
<undeployment xmlns="http://xml.apache.org/axis/wsdd/">
 <service name="MessageService"/>
</undeployment>

Step 1: java -cp %CATALINA_HOME%\lib\axis.jar;%CATALINA_HOME%\lib\jaxrpc.jar;%CATALINA_HOME%\lib\commons-logging-1.1.jar;%CATALINA_HOME%\lib\commons-discovery-0.2.jar;%CATALINA_HOME%\lib\activation.jar;%CATALINA_HOME%\lib\mail.jar; org.apache.axis.client.AdminClient deploy.wsdd
Step 2 : REM java -cp %CATALINA_HOME%\lib\axis.jar;%CATALINA_HOME%\lib\jaxrpc.jar;%CATALINA_HOME%\lib\commons-logging-1.1.jar;%CATALINA_HOME%\lib\commons-discovery-0.2.jar;%CATALINA_HOME%\lib\activation.jar;%CATALINA_HOME%\lib\mail.jar; org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

Now I am getting this Error :
SEVERE: SAAJ0008: Bad Response; /axis/MessageService
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (404/axis/MessageService

Should I have to specify anything in web.xml file??
My Server Code : MessageService.java

import org.w3c.dom.Element;

import javax.xml.soap.SOAPEnvelope;

import javax.xml.soap.Name;

import javax.xml.soap.SOAPBody;

import javax.xml.soap.SOAPBodyElement;

import javax.xml.soap.SOAPHeader;

import javax.xml.soap.SOAPElement;
 

public class MessageService

{

	public Element[] echoElements(Element [] elems)

	{

		return elems;

	}

	

	public void process(SOAPEnvelope req, SOAPEnvelope resp) throws javax.xml.soap.SOAPException

	{

		try

		{

			SOAPBody body = resp.getBody();

			System.out.println("\n\n");

			System.out.println(body);

			System.out.println("\n\n");

			Name ns0 =  resp.createName("TestNS0", "ns0", "http://example.com");

			Name ns1 =  resp.createName("TestNS1", "ns1", "http://example.com");

			SOAPElement bodyElmnt = body.addBodyElement(ns0);

			SOAPElement el = bodyElmnt.addChildElement(ns1);

			el.addTextNode("TEST RESPONSE");

		}

		catch(Exception exp)

		{

			System.out.println("Exception while receiving the request");

			exp.printStackTrace();

		}

	}

}
 

Client Code : TestClient

import java.io.ByteArrayInputStream;
 

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import javax.xml.soap.MessageFactory;

import javax.xml.soap.SOAPEnvelope;

import javax.xml.soap.SOAPMessage;

import javax.xml.soap.SOAPPart;

import javax.xml.soap.SOAPConnection;

import javax.xml.soap.MimeHeaders;

import javax.xml.soap.SOAPConnectionFactory;

import javax.xml.soap.SOAPBodyElement;

import javax.xml.soap.SOAPBody;

import javax.xml.soap.SOAPFactory;

import javax.xml.soap.Name;
 

public class TestClient

{

	public static void main(String [] args)

	{

		try

		{

			String		xmlString		=	"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +

								            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +

								            "                   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +

								            "                   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +

								            " <soapenv:Header>\n" +

								            "  <shw:Hello xmlns:shw=\"http://localhost:8080/axis/MessageService\">\n" +

								            "    <shw:Myname>Tony</shw:Myname>\n" +

								            "  </shw:Hello>\n" +

								            " </soapenv:Header>\n" +

								            " <soapenv:Body>\n" +

								            "  <shw:process xmlns:shw=\"http://localhost:8080/axis/MessageService\">\n" +

								            "    <shw:City>GENT</shw:City>\n" +

								            "  </shw:process>\n" +

								            " </soapenv:Body>\n" +

								            "</soapenv:Envelope>";

			

			MessageFactory	mf			=	MessageFactory.newInstance();

			

			SOAPConnection	conn		=	SOAPConnectionFactory.newInstance().createConnection();

			MimeHeaders		h			=	new MimeHeaders();

			SOAPMessage		smsg		=	mf.createMessage(h, new ByteArrayInputStream(xmlString.getBytes()));

			h.addHeader(Call.SOAPACTION_USE_PROPERTY, "true");

			h.addHeader(Call.SOAPACTION_URI_PROPERTY, "http://localhost:8080/axis/MessageService");

			SOAPMessage		response	=	conn.call(smsg, "http://localhost:8080/axis/MessageService");

			System.out.println("Response : " + response.getSOAPBody());

		}

		catch (Exception e)

		{

			System.err.println(e.toString());

		}

	}

}

Open in new window

0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
Comment Utility
Sandeep, if you seriously want aviod all these headaches of dealing with SOAP messages and header better use axis Eclipse plugin or Eclipse WTP it solves you problem 90% you just need to do you basic stuff.

if you still want to continue in the same above way, first of check if your web service is up and running.  

got to : http://localhost:8080/axis/services

let me know if you can see your MessagingService there, else we can start all over from the start.

0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
Comment Utility
Also note that you are using Jax:RPC which is not very compatible or preferable :)

Take look at the simplest way of creating a web service using Eclipse WTP it take hardly 5 mins :)

http://www.webagesolutions.com/knowledgebase/javakb/jkb004/WTP_demo.htm
0
 
LVL 2

Author Comment

by:sandeep1984
Comment Utility
I have changed it to   provider="java:MSG"
In axis services list, I can see the service running.
0
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 500 total points
Comment Utility
did u try to invoke the web service?

if you are using eclipse can use Eclipse web service exloprer which is a generic web service client for testing your web service

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jst.ws.consumption.ui.doc.user/tasks/ttestwsdl.html
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
Comment Utility
May I know why C grade??
0
 
LVL 2

Author Comment

by:sandeep1984
Comment Utility
Sorry mate. I wanted to give you B, but by mistake.
Thanks for your answers.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WCAG audit tools 1 51
wordmultiple challenge 12 89
HashMap Vs TreeMap 12 48
create a gui in perl 3 42
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now