Link to home
Create AccountLog in
Avatar of sandeep1984
sandeep1984Flag for India

asked on

Help Needed with SOAP And Apache Axis

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

Avatar of mukundha_expert
mukundha_expert

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>");
Avatar of sandeep1984

ASKER

setProperty method s not available in MimeHeaders class.
sorry its addHeader()
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

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


Avatar of Siva Prasanna Kumar
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.
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
How to create a wsdl for my JWS.
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

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.

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
I have changed it to   provider="java:MSG"
In axis services list, I can see the service running.
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
May I know why C grade??
Sorry mate. I wanted to give you B, but by mistake.
Thanks for your answers.