[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help Needed with SOAP And Apache Axis

Posted on 2008-06-11
15
Medium Priority
?
3,953 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
ID: 21758516
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
ID: 21758967
setProperty method s not available in MimeHeaders class.
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 21759056
sorry its addHeader()
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:sandeep1984
ID: 21759171
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
ID: 21759697
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
ID: 21760406
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
ID: 21760482
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
 
LVL 2

Author Comment

by:sandeep1984
ID: 21766242
How to create a wsdl for my JWS.
0
 
LVL 2

Author Comment

by:sandeep1984
ID: 21766465
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
ID: 21796681
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
ID: 21796712
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
ID: 21799602
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 1000 total points
ID: 21799636
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
ID: 21864575
May I know why C grade??
0
 
LVL 2

Author Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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
Course of the Month18 days, 15 hours left to enroll

834 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