You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Joe Nathan <jo...@yahoo.com> on 2007/06/18 01:45:44 UTC
Running SAAJ problem
Hi,
I am running Axis2 under Tomcat.
I got a problem SAAJ client work.
POJO SOAP class is, say, "SoapService", method is "mymethod".
>From a Tomcat servlet, it calls a SOAP service serviced under
the same Tomcat instance. However I keep getting the following
error message;
----------------------------------------------------------------------------------
SEVERE: Exception occurred while trying to invoke service method input
org.apache.axis2.AxisFault: namespace mismatch require http://localhost/xsd
found http://localhost/axis2/services/SoapService
at
org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:103)
at
org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.receive(AbstractInOutSyncMessageReceiver.java:39)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:144)
at
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(
--------------------------------------------------------------------------------------
The SAAJ program part is as follows;
---------------------------------------------------------------------------------
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();
QName bodyName = new QName("http://localhost/axis2/services/SoapService",
"mymethod", "m");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
QName name = new QName("vinput");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("12667");
URL endpoint = new
URL("http://localhost/axis2/services/SoapService/mymethod");
SOAPMessage sresponse = connection.call(message, endpoint);
connection.close();
---------------------------------------------------------------------------------------
Can you tell me what am I doing wrong?
SOAP works if I try from web-browsers with the followin urls;
http://localhost/axis2/services/listServices
http://localhost/axis2/services/SoapService?wsdl
http://localhost/axis2/services/SoapService?xsd
http://localhost/axis2/services/SoapService/mymethod?vinput=15256
Thanks in advance.
Joe.
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11168244
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: Running SAAJ problem
Posted by Joe Nathan <jo...@yahoo.com>.
Exactly! I tried on Axis POJO this, but it ended up with fatal error! I think
Axis does not do proper marshalling for special characters inside xml codes.
Joe,
sumedha rubasinghe-2 wrote:
>
> Hi Joe,
> Good to hear that you got it working!!!
> Are you referring to passing a String (which is an XML) to a method in
> POJO
> & getting a return String (which is also a XML) ?
>
> eg:
>
> class MyService{
>
> public String myMethod(String xml){
> //do something
>
> }
> }
>
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11207308
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: Running SAAJ problem
Posted by Joe Nathan <jo...@yahoo.com>.
This is one thing that embaffled me and must be an API design mistake!
Basically SOAP is RPC. There should be a standard API for getting
return value!
Regards,
Joe.
sumedha rubasinghe-2 wrote:
>
> Hi Joe,
> Quote : "Of course QName qualified does not work on Axis. I am concerned
> about compatibility with others!"
>
> Try something like the following code.
> SOAPBody soapBody = sresponse.getSOAPBody();
> QName bodyQName = new
> QName("http://ws.apache.org/axis2/xsd","mymethodResponse",
> "m");
> Iterator childElements = soapBody.getChildElements(bodyQName);
> SOAPBodyElement element = (SOAPBodyElement)childElements.next();
>
> You need to give correct value for localpart ("mymethodResponse").
>
> ----------------------------------------------------------------------------------------------------------
> Quote : "However I am not sure whether Axis is adding one more xml layer
> in
> returnining result values."
>
> You can try accessing a simple .NET or any other WS using axis. It works
> seamlessly.
>
> /sumedha
>
>
>
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11228676
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: Running SAAJ problem
Posted by sumedha rubasinghe <su...@gmail.com>.
Hi Joe,
Quote : "Of course QName qualified does not work on Axis. I am concerned
about compatibility with others!"
Try something like the following code.
SOAPBody soapBody = sresponse.getSOAPBody();
QName bodyQName = new
QName("http://ws.apache.org/axis2/xsd","mymethodResponse",
"m");
Iterator childElements = soapBody.getChildElements(bodyQName);
SOAPBodyElement element = (SOAPBodyElement)childElements.next();
You need to give correct value for localpart ("mymethodResponse").
----------------------------------------------------------------------------------------------------------
Quote : "However I am not sure whether Axis is adding one more xml layer in
returnining result values."
You can try accessing a simple .NET or any other WS using axis. It works
seamlessly.
/sumedha
On 6/21/07, Joe Nathan <jo...@yahoo.com> wrote:
>
>
> Actually, I can pass simply assigning xml strings to arguments and
> returning.
> However I am not sure whether Axis is adding one more xml layer in
> returnining result values. Confusion came from this! To get result
> from Axis, I use this;
>
> -----------------------------------------------------------------------------
> SOAPBody soapBody = sresponse.getSOAPBody();
> SOAPBodyElement node =
> (SOAPBodyElement)soapBody.getFirstChild().getFirstChild();
> msg = node.getValue();
>
> -----------------------------------------------------------------------------
> But Sun's J2EE tutorial has the following sample code. Notice that
> there is one extra layer in Axis return objects! Of course QName
> qualified does not work on Axis. I am concerned about compatibility
> with others!
>
> -----------------------------------------------------------------------------
> QName bodyName = new QName("http://ws.apache.org/axis2/xsd",
> "mymethod", "m");
> ...
> SOAPBody soapBody = sresponse.getSOAPBody();
> Iterator iterator = soapBody.getChildElements(bodyName);
> bodyElement = (SOAPBodyElement)iterator.next();
> msg = bodyElement.getValue();
>
> -----------------------------------------------------------------------------
>
> Kind regards,
>
>
>
>
>
> sumedha rubasinghe-2 wrote:
> >
> > Hi Joe,
> > Good to hear that you got it working!!!
> > Are you referring to passing a String (which is an XML) to a method in
> > POJO
> > & getting a return String (which is also a XML) ?
> >
>
> --
> View this message in context:
> http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11223090
> Sent from the Axis - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>
Re: Running SAAJ problem
Posted by Joe Nathan <jo...@yahoo.com>.
Actually, I can pass simply assigning xml strings to arguments and returning.
However I am not sure whether Axis is adding one more xml layer in
returnining result values. Confusion came from this! To get result
from Axis, I use this;
-----------------------------------------------------------------------------
SOAPBody soapBody = sresponse.getSOAPBody();
SOAPBodyElement node =
(SOAPBodyElement)soapBody.getFirstChild().getFirstChild();
msg = node.getValue();
-----------------------------------------------------------------------------
But Sun's J2EE tutorial has the following sample code. Notice that
there is one extra layer in Axis return objects! Of course QName
qualified does not work on Axis. I am concerned about compatibility
with others!
-----------------------------------------------------------------------------
QName bodyName = new QName("http://ws.apache.org/axis2/xsd",
"mymethod", "m");
...
SOAPBody soapBody = sresponse.getSOAPBody();
Iterator iterator = soapBody.getChildElements(bodyName);
bodyElement = (SOAPBodyElement)iterator.next();
msg = bodyElement.getValue();
-----------------------------------------------------------------------------
Kind regards,
sumedha rubasinghe-2 wrote:
>
> Hi Joe,
> Good to hear that you got it working!!!
> Are you referring to passing a String (which is an XML) to a method in
> POJO
> & getting a return String (which is also a XML) ?
>
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11223090
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: Running SAAJ problem
Posted by sumedha rubasinghe <su...@gmail.com>.
Hi Joe,
Good to hear that you got it working!!!
Are you referring to passing a String (which is an XML) to a method in POJO
& getting a return String (which is also a XML) ?
eg:
class MyService{
public String myMethod(String xml){
//do something
}
}
On 6/20/07, Joe Nathan <jo...@yahoo.com> wrote:
>
>
> It works now, Thanks for the help!
>
> The problem was with this;
>
> QName bodyName = new QName("http://ws.apache.org/axis2/xsd",
> "xxxxx", "m");
>
> It works after coding exactly like that. I could not found any SAAJ
> example
> on Axis. So I started from Sun J2EE tutorial, get confused and wasted so
> much time. There are examples on soon-to-be deprecated methods, not
> on SAAJ. A simple example could make difference!
>
> By the way, I have another problem. How cannot I pass XML strings to
> POJO methods and get returns in XML as well? I mean without using
> attachments which will complicate things. I am primarily targeting
> calls from .NET and PHP.
>
> Regards,
> Joe.
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11206864
> Sent from the Axis - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>
Re: Running SAAJ problem
Posted by Joe Nathan <jo...@yahoo.com>.
It works now, Thanks for the help!
The problem was with this;
QName bodyName = new QName("http://ws.apache.org/axis2/xsd",
"xxxxx", "m");
It works after coding exactly like that. I could not found any SAAJ example
on Axis. So I started from Sun J2EE tutorial, get confused and wasted so
much time. There are examples on soon-to-be deprecated methods, not
on SAAJ. A simple example could make difference!
By the way, I have another problem. How cannot I pass XML strings to
POJO methods and get returns in XML as well? I mean without using
attachments which will complicate things. I am primarily targeting
calls from .NET and PHP.
Regards,
Joe.
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11206864
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: Running SAAJ problem
Posted by sumedha rubasinghe <su...@gmail.com>.
Hi Joe,
I have not tested this on JDK 1.6.
But I can confirm that this is working on jdk 1.5 using the Axis2 1.2 build
(April 27 2007).
Please find the attached service.xml file,client program,service class &
WDSL. (Note that I have not used a custom WSDL & this is the auto generated
WSDL)
Please try using the attached artifacts & testing your scenario.
Thanks
/sumedha
On 6/19/07, Joe Nathan <jo...@yahoo.com> wrote:
>
>
> I use the followings;
> - Apache Tomcat 6.0 S
> - Axis2 1.2 build (April 27 2007)
> - JDK 1.6.0
>
> Can you explain the relationship between urls in?
> - services.xml
> - QName bodyName = new QName("http://SoapService/xsd
> ", "evaluatexml",
> "m");
>
> If I use the following URLs from browsers;
>
> http://localhost/axis2/services/listServices
> http://localhost/axis2/services/SoapService?wsdl
> http://localhost/axis2/services/SoapService?xsd
>
> All works fine;
>
> Regards.
>
>
>
>
>
>
> sumedha rubasinghe-2 wrote:
> >
> > Hi joe,
> > I tried to regenerate what you have explained. But it is working for me.
> > And I could not find anything wrong in you code either. :-)
> >
> > Could you tell me the version of Axis2 your using? (I am working on
> > trunk).
> >
> > At the same time, If you have a source distribution, following test case
> > contains several examples of using SAAJ.
> > modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java
> > I have also attached the latest version of the class.
> >
> > Thank you.
> > /sumedha
> >
> >
> > On 6/18/07, Joe Nathan <jo...@yahoo.com> wrote:
> >>
> >>
> >> Thanks for the reply.
> >>
> >> My WEB-INF/services.xml is like this;
> >> ------------------------------------------------
> >> <service name="SoapService" scope="application">
> >> <description>RME Soap Service</description>
> >> <messageReceivers>
> >> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
> >> class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
> >> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
> >> class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
> >> </messageReceivers>
> >> <schema
> >> schemaNamespace="http://localhost/axis2/services/SoapService?xsd
> >> "
> >> />
> >> <parameter name="ServiceClass">SoapService</parameter>
> >> </service>
> >>
> ------------------------------------------------------------------------
> >>
> >> Relevant part of wsdl query with
> >> "http://localhost/axis2/services/SoapService?wsdl"
> >> is like this;
> >>
> ------------------------------------------------------------------------
> >> <wsdl:documentation>SoapService</wsdl:documentation>
> >> - <wsdl:types>
> >> - <xs:schema xmlns:ns="http://localhost/axis2/services/SoapService?xsd"
> >> attributeFormDefault="qualified" elementFormDefault="qualified"
> >> targetNamespace="http://localhost/axis2/services/SoapService?xsd">
> >> - <xs:element name="mymethod">
> >> - <xs:complexType>
> >>
> >>
> >>
> ----------------------------------------------------------------------------
> >>
> >> The client SAAJ is;
> >>
> >> ========================================================
> >> QName bodyName = new QName("http://localhost/axis2/services/SoapService
> ",
> >> "mymethod", "m");
> >> SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
> >>
> >> QName name = new QName("vinput");
> >> SOAPElement symbol = bodyElement.addChildElement(name);
> >> symbol.addTextNode("12667");
> >>
> >> URL endpoint = new
> >> URL(" http://localhost/axis2/services/SoapService/mymethod");
> >> SOAPMessage sresponse = connection.call(message, endpoint);
> >> connection.close();
> >> =====================================================
> >>
> >> I build an .aar file and place it to WEB-INF/services of Axis2 inflated
> >> directory. It works from browser URL queries, not from client programs!
> >>
> >> Thanks in advance!
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11170506
> >> Sent from the Axis - Dev mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> >> For additional commands, e-mail: axis-dev-help@ws.apache.org
> >>
> >>
> >
> > /*
> > * Copyright 2006 The Apache Software Foundation.
> > *
> > * Licensed under the Apache License, Version 2.0 (the "License");
> > * you may not use this file except in compliance with the License.
> > * You may obtain a copy of the License at
> > *
> > * http://www.apache.org/licenses/LICENSE-2.0
> > *
> > * Unless required by applicable law or agreed to in writing, software
> > * distributed under the License is distributed on an "AS IS" BASIS,
> > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> > implied.
> > * See the License for the specific language governing permissions and
> > * limitations under the License.
> > */
> > package org.apache.axis2.saaj.integration;
> >
> > import junit.extensions.TestSetup;
> > import junit.framework.Test;
> > import junit.framework.TestCase;
> > import junit.framework.TestSuite;
> > import org.apache.axis2.description.AxisService;
> > import org.apache.axis2.description.Parameter;
> > import org.apache.axis2.util.Utils;
> >
> > import javax.activation.DataHandler;
> > import javax.activation.FileDataSource;
> > import javax.xml.namespace.QName;
> > import javax.xml.soap.AttachmentPart;
> > import javax.xml.soap.MessageFactory;
> > import javax.xml.soap.MimeHeaders;
> > import javax.xml.soap.Name;
> > import javax.xml.soap.SOAPBody;
> > import javax.xml.soap.SOAPBodyElement;
> > import javax.xml.soap.SOAPConnection;
> > import javax.xml.soap.SOAPConnectionFactory;
> > import javax.xml.soap.SOAPElement;
> > import javax.xml.soap.SOAPEnvelope;
> > import javax.xml.soap.SOAPException;
> > import javax.xml.soap.SOAPHeader;
> > import javax.xml.soap.SOAPHeaderElement;
> > import javax.xml.soap.SOAPMessage;
> > import javax.xml.soap.SOAPPart;
> > import java.io.ByteArrayInputStream;
> > import java.io.ByteArrayOutputStream;
> > import java.io.File;
> > import java.io.FileInputStream;
> > import java.io.FileOutputStream;
> > import java.io.IOException;
> > import java.util.Iterator;
> >
> > public class IntegrationTest extends TestCase {
> >
> > static int port;
> > public static final QName SERVICE_NAME = new QName("Echo");
> > public static final QName OPERATION_NAME = new QName("echo");
> >
> > public static final String SAAJ_REPO =
> > System.getProperty("basedir", ".") + "/" +
> > "target/test-resources/saaj-repo";
> >
> > public IntegrationTest(String name) {
> > super(name);
> > }
> >
> > protected static String getAddress() {
> > return "http://127.0.0.1:" +
> > port +
> > "/axis2/services/Echo";
> > }
> >
> > public static Test suite() {
> > return new TestSetup(new TestSuite(IntegrationTest.class)) {
> > public void setUp() throws Exception {
> > port = UtilServer.start(SAAJ_REPO);
> > Parameter eneblemtom = new Parameter("enableMTOM",
> > "true");
> >
> > UtilServer.getConfigurationContext().getAxisConfiguration()
> > .addParameter(eneblemtom);
> > }
> >
> > public void tearDown() throws Exception {
> > UtilServer.stop();
> > }
> > };
> > }
> >
> > protected void setUp() throws Exception {
> > final AxisService service =
> > Utils.createSimpleService(SERVICE_NAME,
> >
> > EchoService.class.getName(),
> >
> > OPERATION_NAME);
> > UtilServer.deployService(service);
> > }
> >
> > protected void tearDown() throws Exception {
> > UtilServer.unDeployService(SERVICE_NAME);
> > UtilServer.unDeployClientService();
> > }
> >
> >
> > public void testSendReceiveMessageWithEmptyNSPrefix() {
> > try {
> > MessageFactory mf = MessageFactory.newInstance();
> > SOAPMessage request = mf.createMessage();
> >
> > SOAPPart sPart = request.getSOAPPart();
> > SOAPEnvelope env = sPart.getEnvelope();
> > SOAPBody body = env.getBody();
> >
> > //Namespace prefix is empty
> > body.addBodyElement(new
> > QName("http://fakeNamespace2.org","echo"))
> >
> .addTextNode("This is some text");
> >
> > SOAPConnection sCon =
> > SOAPConnectionFactory.newInstance().createConnection();
> > SOAPMessage response = sCon.call(request, getAddress());
> > assertFalse(response.getAttachments().hasNext());
> > assertEquals(0, response.countAttachments());
> >
> > String requestStr = printSOAPMessage(request);
> > String responseStr = printSOAPMessage(response);
> > assertTrue(responseStr.indexOf("echo") > -1);
> > sCon.close();
> > } catch (SOAPException e) {
> > e.printStackTrace();
> > fail("Unexpected Exception while running test: " + e);
> > } catch (IOException e) {
> > fail("Unexpected Exception while running test: " + e);
> > }
> > }
> >
> >
> > public void testSendReceiveSimpleSOAPMessage() {
> > try {
> > MessageFactory mf = MessageFactory.newInstance();
> > SOAPMessage request = mf.createMessage();
> >
> > createSimpleSOAPPart(request);
> >
> > SOAPConnection sCon =
> > SOAPConnectionFactory.newInstance().createConnection();
> > SOAPMessage response = sCon.call(request, getAddress());
> > assertFalse(response.getAttachments().hasNext());
> > assertEquals(0, response.countAttachments());
> >
> > String requestStr = printSOAPMessage(request);
> > String responseStr = printSOAPMessage(response);
> > assertTrue(responseStr.indexOf("echo") != -1);
> > sCon.close();
> > } catch (SOAPException e) {
> > e.printStackTrace();
> > fail("Unexpected Exception while running test: " + e);
> > } catch (IOException e) {
> > fail("Unexpected Exception while running test: " + e);
> > }
> > }
> >
> > private String printSOAPMessage(final SOAPMessage msg) throws
> > SOAPException, IOException {
> > ByteArrayOutputStream baos = new ByteArrayOutputStream();
> > msg.writeTo(baos);
> > String responseStr = baos.toString();
> >
> >
> > System.out.println
> ("\n\n----------------------Message-------------------------\n"
> > +
> > responseStr);
> >
> > System.out.println
> ("-------------------------------------------------------\n\n");
> > assertTrue(responseStr.indexOf("This is some text") != -1);
> > return responseStr;
> > }
> >
> > public void testSendReceiveMessageWithAttachment() throws Exception
> {
> > MessageFactory mf = MessageFactory.newInstance();
> > SOAPMessage request = mf.createMessage();
> >
> > //create the SOAPPart
> > createSOAPPart(request);
> >
> > //Attach a text/plain object with the SOAP request
> > String sampleMessage = "Sample Message: Hello World!";
> > AttachmentPart textAttach =
> > request.createAttachmentPart(sampleMessage, "text/plain");
> > textAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
> > textAttach.setContentId("submitSampleText@apache.org");
> > request.addAttachmentPart(textAttach);
> >
> > //Attach a java.awt.Image object to the SOAP request
> > String jpgfilename = System.getProperty("basedir", ".") + "/" +
> > "test-resources/axis2.jpg";
> > File myfile = new File(jpgfilename);
> > FileDataSource fds = new FileDataSource(myfile);
> > DataHandler imageDH = new DataHandler(fds);
> > AttachmentPart jpegAttach = request.createAttachmentPart
> (imageDH);
> > jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
> > jpegAttach.setContentId("submitSampleImage@apache.org");
> > jpegAttach.setContentType("image/jpg");
> > request.addAttachmentPart(jpegAttach);
> >
> > SOAPConnection sCon =
> > SOAPConnectionFactory.newInstance().createConnection();
> > SOAPMessage response = sCon.call(request, getAddress());
> >
> > int attachmentCount = response.countAttachments();
> > assertTrue(attachmentCount == 2);
> >
> > Iterator attachIter = response.getAttachments();
> >
> > int i = 0;
> > while (attachIter.hasNext()) {
> > AttachmentPart attachment =
> (AttachmentPart)attachIter.next();
> > final Object content =
> > attachment.getDataHandler().getContent();
> > if (content instanceof String) {
> > assertEquals(sampleMessage, (String)content);
> > } else if (content instanceof ByteArrayInputStream) {
> > ByteArrayInputStream bais =
> (ByteArrayInputStream)content;
> > byte[] b = new byte[15000];
> > final int lengthRead = bais.read(b);
> > FileOutputStream fos =
> > new FileOutputStream(new
> > File(System.getProperty("basedir", ".") + "/" +
> > "target/test-resources/result" + (i++) +
> > ".jpg"));
> > fos.write(b, 0, lengthRead);
> > fos.flush();
> > fos.close();
> >
> >
> > assertTrue(attachment.getContentType().equals("image/jpeg")
> > ||
> > attachment.getContentType().equals("text/plain"));
> > }
> > }
> >
> > sCon.close();
> >
> > }
> >
> > public void testSendReceiveNonRefAttachment() throws Exception {
> > MessageFactory mf = MessageFactory.newInstance();
> > SOAPMessage request = mf.createMessage();
> >
> > //create the SOAPPart
> > createSimpleSOAPPart(request);
> >
> > //Attach a text/plain object with the SOAP request
> > String sampleMessage = "Sample Message: Hello World!";
> > AttachmentPart textAttach =
> > request.createAttachmentPart(sampleMessage, "text/plain");
> > request.addAttachmentPart(textAttach);
> >
> > //Attach a java.awt.Image object to the SOAP request
> > String jpgfilename =
> > System.getProperty("basedir", ".") + "/" +
> > "target/test-resources/axis2.jpg";
> > File myfile = new File(jpgfilename);
> > FileDataSource fds = new FileDataSource(myfile);
> > DataHandler imageDH = new DataHandler(fds);
> > AttachmentPart jpegAttach = request.createAttachmentPart
> (imageDH);
> > jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
> > jpegAttach.setContentType("image/jpg");
> > request.addAttachmentPart(jpegAttach);
> >
> >
> > SOAPConnection sCon =
> > SOAPConnectionFactory.newInstance().createConnection();
> > SOAPMessage response = sCon.call(request, getAddress());
> >
> > int attachmentCount = response.countAttachments();
> > assertTrue(attachmentCount == 2);
> >
> > Iterator attachIter = response.getAttachments();
> >
> > while (attachIter.hasNext()) {
> > AttachmentPart attachment =
> (AttachmentPart)attachIter.next();
> > final Object content =
> > attachment.getDataHandler().getContent();
> > if (content instanceof String) {
> > assertEquals(sampleMessage, (String)content);
> > } else if (content instanceof ByteArrayInputStream) {
> > ByteArrayInputStream bais =
> (ByteArrayInputStream)content;
> > byte[] b = new byte[15000];
> > final int lengthRead = bais.read(b);
> > FileOutputStream fos =
> > new FileOutputStream(new
> > File(System.getProperty("basedir", ".") + "/" +
> >
> > "target/target/test-resources/axis2.jpg"));
> > fos.write(b, 0, lengthRead);
> > fos.flush();
> > fos.close();
> >
> >
> > assertTrue(attachment.getContentType().equals("image/jpeg")
> > ||
> > attachment.getContentType().equals("text/plain"));
> > }
> > }
> >
> > sCon.close();
> > }
> >
> > private void createSOAPPart(SOAPMessage message) throws
> SOAPException
> > {
> > SOAPPart sPart = message.getSOAPPart();
> > SOAPEnvelope env = sPart.getEnvelope();
> > SOAPBody body = env.getBody();
> >
> > final SOAPHeader soapHeader = env.getHeader();
> > soapHeader
> > .addHeaderElement(env.createName("TestHeader1", "swa",
> > "http://fakeNamespace.org"));
> > soapHeader
> > .addHeaderElement(env.createName("TestHeader2", "swa",
> > "http://fakeNamespace.org"));
> > final SOAPHeaderElement headerEle3 =
> > soapHeader.addHeaderElement(
> > env.createName("TestHeader3", "swa",
> > "http://fakeNamespace.org"));
> > final SOAPElement ch1 = headerEle3.addChildElement("he3",
> "swa");
> > ch1.addTextNode("Im Header Element of header3");
> >
> > Name ns = env.createName("echo", "swa",
> > "http://fakeNamespace.org");
> > SOAPBodyElement bodyElement = body.addBodyElement(ns);
> >
> > Name nameMain = env.createName("internal");
> > SOAPElement mainChildEle = bodyElement.addChildElement
> (nameMain);
> >
> > Name ns2 = env.createName("text");
> > SOAPElement textReference = mainChildEle.addChildElement(ns2);
> > Name hrefAttr = env.createName("href");
> > textReference.addAttribute(hrefAttr,
> > "cid:submitSampleText@apache.org");
> >
> > Name ns3 = env.createName("image");
> > SOAPElement imageReference = mainChildEle.addChildElement(ns3);
> > Name ns31 = env.createName("inner");
> > final SOAPElement img = imageReference.addChildElement(ns31);
> > img.addAttribute(hrefAttr, "cid:submitSampleImage@apache.org");
> >
> > Name ns4 = env.createName("plaintxt");
> > SOAPElement plainTxt = mainChildEle.addChildElement(ns4);
> > plainTxt.addTextNode("This is simple plain text");
> >
> > Name ns5 = env.createName("nested");
> > SOAPElement nested = mainChildEle.addChildElement(ns5);
> > nested.addTextNode("Nested1 Plain Text");
> > Name ns6 = env.createName("nested2");
> > SOAPElement nested2 = nested.addChildElement(ns6);
> > nested2.addTextNode("Nested2 Plain Text");
> > }
> >
> > private void createSimpleSOAPPart(SOAPMessage message) throws
> > SOAPException {
> > SOAPPart sPart = message.getSOAPPart();
> > SOAPEnvelope env = sPart.getEnvelope();
> > SOAPBody body = env.getBody();
> > SOAPHeader header = env.getHeader();
> > header.addHeaderElement(env.createName("Header1",
> > "pref",
> >
> > "http://test.apach.org/test"))
> > .addTextNode("This is header1");
> >
> > Name ns = env.createName("echo", "swa2",
> > "http://fakeNamespace2.org");
> > final SOAPBodyElement bodyElement = body.addBodyElement(ns);
> > Name ns2 = env.createName("something");
> > final SOAPElement ele1 = bodyElement.addChildElement(ns2);
> > ele1.addTextNode("This is some text");
> >
> > Name ns3 = env.createName("ping", "swa3",
> > "http://fakeNamespace3.org");
> > final SOAPBodyElement bodyElement2 = body.addBodyElement(ns3);
> > Name ns4 = env.createName("another");
> > final SOAPElement ele2 = bodyElement2.addChildElement(ns4);
> > ele2.addTextNode("This is another text");
> > }
> >
> >
> > public void testSendReceive_ISO88591_EncodedSOAPMessage() {
> > try{
> > MimeHeaders mimeHeaders = new MimeHeaders();
> > mimeHeaders.addHeader("Content-Type", "text/xml;
> > charset=iso-8859-1");
> >
> > FileInputStream fileInputStream = new
> > FileInputStream(System.getProperty("basedir", ".") +
> > "/test-resources" + File.separator +
> > "soap-part-iso-8859-1.xml");
> > SOAPMessage requestMessage =
> > MessageFactory.newInstance().createMessage(mimeHeaders,fileInputStream);
> >
> >
> > SOAPConnection sCon =
> > SOAPConnectionFactory.newInstance().createConnection();
> > SOAPMessage response = sCon.call(requestMessage,
> > getAddress());
> > assertFalse(response.getAttachments().hasNext());
> > assertEquals(0, response.countAttachments());
> >
> > printSOAPMessage(requestMessage);
> > String responseStr = printSOAPMessage(response);
> > assertTrue(responseStr.indexOf("This is some text.Here are
> > some special chars : öÆÚÂÂ(r)¤") != -1);
> > assertTrue(responseStr.indexOf("echo") != -1);
> > sCon.close();
> > } catch (SOAPException e) {
> > e.printStackTrace();
> > fail("Unexpected Exception while running test: " + e);
> > } catch (IOException e) {
> > fail("Unexpected Exception while running test: " + e);
> > }
> > }
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-dev-help@ws.apache.org
> >
>
> --
> View this message in context:
> http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11188078
> Sent from the Axis - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>
Re: Running SAAJ problem
Posted by Joe Nathan <jo...@yahoo.com>.
I use the followings;
- Apache Tomcat 6.0 S
- Axis2 1.2 build (April 27 2007)
- JDK 1.6.0
Can you explain the relationship between urls in?
- services.xml
- QName bodyName = new QName("http://SoapService/xsd", "evaluatexml",
"m");
If I use the following URLs from browsers;
http://localhost/axis2/services/listServices
http://localhost/axis2/services/SoapService?wsdl
http://localhost/axis2/services/SoapService?xsd
All works fine;
Regards.
sumedha rubasinghe-2 wrote:
>
> Hi joe,
> I tried to regenerate what you have explained. But it is working for me.
> And I could not find anything wrong in you code either. :-)
>
> Could you tell me the version of Axis2 your using? (I am working on
> trunk).
>
> At the same time, If you have a source distribution, following test case
> contains several examples of using SAAJ.
> modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java
> I have also attached the latest version of the class.
>
> Thank you.
> /sumedha
>
>
> On 6/18/07, Joe Nathan <jo...@yahoo.com> wrote:
>>
>>
>> Thanks for the reply.
>>
>> My WEB-INF/services.xml is like this;
>> ------------------------------------------------
>> <service name="SoapService" scope="application">
>> <description>RME Soap Service</description>
>> <messageReceivers>
>> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
>> class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
>> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
>> class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
>> </messageReceivers>
>> <schema
>> schemaNamespace="http://localhost/axis2/services/SoapService?xsd
>> "
>> />
>> <parameter name="ServiceClass">SoapService</parameter>
>> </service>
>> ------------------------------------------------------------------------
>>
>> Relevant part of wsdl query with
>> "http://localhost/axis2/services/SoapService?wsdl"
>> is like this;
>> ------------------------------------------------------------------------
>> <wsdl:documentation>SoapService</wsdl:documentation>
>> - <wsdl:types>
>> - <xs:schema xmlns:ns="http://localhost/axis2/services/SoapService?xsd"
>> attributeFormDefault="qualified" elementFormDefault="qualified"
>> targetNamespace="http://localhost/axis2/services/SoapService?xsd">
>> - <xs:element name="mymethod">
>> - <xs:complexType>
>>
>>
>> ----------------------------------------------------------------------------
>>
>> The client SAAJ is;
>>
>> ========================================================
>> QName bodyName = new QName("http://localhost/axis2/services/SoapService",
>> "mymethod", "m");
>> SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
>>
>> QName name = new QName("vinput");
>> SOAPElement symbol = bodyElement.addChildElement(name);
>> symbol.addTextNode("12667");
>>
>> URL endpoint = new
>> URL(" http://localhost/axis2/services/SoapService/mymethod");
>> SOAPMessage sresponse = connection.call(message, endpoint);
>> connection.close();
>> =====================================================
>>
>> I build an .aar file and place it to WEB-INF/services of Axis2 inflated
>> directory. It works from browser URL queries, not from client programs!
>>
>> Thanks in advance!
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11170506
>> Sent from the Axis - Dev mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-dev-help@ws.apache.org
>>
>>
>
> /*
> * Copyright 2006 The Apache Software Foundation.
> *
> * Licensed under the Apache License, Version 2.0 (the "License");
> * you may not use this file except in compliance with the License.
> * You may obtain a copy of the License at
> *
> * http://www.apache.org/licenses/LICENSE-2.0
> *
> * Unless required by applicable law or agreed to in writing, software
> * distributed under the License is distributed on an "AS IS" BASIS,
> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> * See the License for the specific language governing permissions and
> * limitations under the License.
> */
> package org.apache.axis2.saaj.integration;
>
> import junit.extensions.TestSetup;
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
> import org.apache.axis2.description.AxisService;
> import org.apache.axis2.description.Parameter;
> import org.apache.axis2.util.Utils;
>
> import javax.activation.DataHandler;
> import javax.activation.FileDataSource;
> import javax.xml.namespace.QName;
> import javax.xml.soap.AttachmentPart;
> import javax.xml.soap.MessageFactory;
> import javax.xml.soap.MimeHeaders;
> import javax.xml.soap.Name;
> import javax.xml.soap.SOAPBody;
> import javax.xml.soap.SOAPBodyElement;
> import javax.xml.soap.SOAPConnection;
> import javax.xml.soap.SOAPConnectionFactory;
> import javax.xml.soap.SOAPElement;
> import javax.xml.soap.SOAPEnvelope;
> import javax.xml.soap.SOAPException;
> import javax.xml.soap.SOAPHeader;
> import javax.xml.soap.SOAPHeaderElement;
> import javax.xml.soap.SOAPMessage;
> import javax.xml.soap.SOAPPart;
> import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.util.Iterator;
>
> public class IntegrationTest extends TestCase {
>
> static int port;
> public static final QName SERVICE_NAME = new QName("Echo");
> public static final QName OPERATION_NAME = new QName("echo");
>
> public static final String SAAJ_REPO =
> System.getProperty("basedir", ".") + "/" +
> "target/test-resources/saaj-repo";
>
> public IntegrationTest(String name) {
> super(name);
> }
>
> protected static String getAddress() {
> return "http://127.0.0.1:" +
> port +
> "/axis2/services/Echo";
> }
>
> public static Test suite() {
> return new TestSetup(new TestSuite(IntegrationTest.class)) {
> public void setUp() throws Exception {
> port = UtilServer.start(SAAJ_REPO);
> Parameter eneblemtom = new Parameter("enableMTOM",
> "true");
>
> UtilServer.getConfigurationContext().getAxisConfiguration()
> .addParameter(eneblemtom);
> }
>
> public void tearDown() throws Exception {
> UtilServer.stop();
> }
> };
> }
>
> protected void setUp() throws Exception {
> final AxisService service =
> Utils.createSimpleService(SERVICE_NAME,
>
> EchoService.class.getName(),
>
> OPERATION_NAME);
> UtilServer.deployService(service);
> }
>
> protected void tearDown() throws Exception {
> UtilServer.unDeployService(SERVICE_NAME);
> UtilServer.unDeployClientService();
> }
>
>
> public void testSendReceiveMessageWithEmptyNSPrefix() {
> try {
> MessageFactory mf = MessageFactory.newInstance();
> SOAPMessage request = mf.createMessage();
>
> SOAPPart sPart = request.getSOAPPart();
> SOAPEnvelope env = sPart.getEnvelope();
> SOAPBody body = env.getBody();
>
> //Namespace prefix is empty
> body.addBodyElement(new
> QName("http://fakeNamespace2.org","echo"))
> .addTextNode("This is some text");
>
> SOAPConnection sCon =
> SOAPConnectionFactory.newInstance().createConnection();
> SOAPMessage response = sCon.call(request, getAddress());
> assertFalse(response.getAttachments().hasNext());
> assertEquals(0, response.countAttachments());
>
> String requestStr = printSOAPMessage(request);
> String responseStr = printSOAPMessage(response);
> assertTrue(responseStr.indexOf("echo") > -1);
> sCon.close();
> } catch (SOAPException e) {
> e.printStackTrace();
> fail("Unexpected Exception while running test: " + e);
> } catch (IOException e) {
> fail("Unexpected Exception while running test: " + e);
> }
> }
>
>
> public void testSendReceiveSimpleSOAPMessage() {
> try {
> MessageFactory mf = MessageFactory.newInstance();
> SOAPMessage request = mf.createMessage();
>
> createSimpleSOAPPart(request);
>
> SOAPConnection sCon =
> SOAPConnectionFactory.newInstance().createConnection();
> SOAPMessage response = sCon.call(request, getAddress());
> assertFalse(response.getAttachments().hasNext());
> assertEquals(0, response.countAttachments());
>
> String requestStr = printSOAPMessage(request);
> String responseStr = printSOAPMessage(response);
> assertTrue(responseStr.indexOf("echo") != -1);
> sCon.close();
> } catch (SOAPException e) {
> e.printStackTrace();
> fail("Unexpected Exception while running test: " + e);
> } catch (IOException e) {
> fail("Unexpected Exception while running test: " + e);
> }
> }
>
> private String printSOAPMessage(final SOAPMessage msg) throws
> SOAPException, IOException {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> msg.writeTo(baos);
> String responseStr = baos.toString();
>
>
> System.out.println("\n\n----------------------Message-------------------------\n"
> +
> responseStr);
>
> System.out.println("-------------------------------------------------------\n\n");
> assertTrue(responseStr.indexOf("This is some text") != -1);
> return responseStr;
> }
>
> public void testSendReceiveMessageWithAttachment() throws Exception {
> MessageFactory mf = MessageFactory.newInstance();
> SOAPMessage request = mf.createMessage();
>
> //create the SOAPPart
> createSOAPPart(request);
>
> //Attach a text/plain object with the SOAP request
> String sampleMessage = "Sample Message: Hello World!";
> AttachmentPart textAttach =
> request.createAttachmentPart(sampleMessage, "text/plain");
> textAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
> textAttach.setContentId("submitSampleText@apache.org");
> request.addAttachmentPart(textAttach);
>
> //Attach a java.awt.Image object to the SOAP request
> String jpgfilename = System.getProperty("basedir", ".") + "/" +
> "test-resources/axis2.jpg";
> File myfile = new File(jpgfilename);
> FileDataSource fds = new FileDataSource(myfile);
> DataHandler imageDH = new DataHandler(fds);
> AttachmentPart jpegAttach = request.createAttachmentPart(imageDH);
> jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
> jpegAttach.setContentId("submitSampleImage@apache.org");
> jpegAttach.setContentType("image/jpg");
> request.addAttachmentPart(jpegAttach);
>
> SOAPConnection sCon =
> SOAPConnectionFactory.newInstance().createConnection();
> SOAPMessage response = sCon.call(request, getAddress());
>
> int attachmentCount = response.countAttachments();
> assertTrue(attachmentCount == 2);
>
> Iterator attachIter = response.getAttachments();
>
> int i = 0;
> while (attachIter.hasNext()) {
> AttachmentPart attachment = (AttachmentPart)attachIter.next();
> final Object content =
> attachment.getDataHandler().getContent();
> if (content instanceof String) {
> assertEquals(sampleMessage, (String)content);
> } else if (content instanceof ByteArrayInputStream) {
> ByteArrayInputStream bais = (ByteArrayInputStream)content;
> byte[] b = new byte[15000];
> final int lengthRead = bais.read(b);
> FileOutputStream fos =
> new FileOutputStream(new
> File(System.getProperty("basedir", ".") + "/" +
> "target/test-resources/result" + (i++) +
> ".jpg"));
> fos.write(b, 0, lengthRead);
> fos.flush();
> fos.close();
>
>
> assertTrue(attachment.getContentType().equals("image/jpeg")
> ||
> attachment.getContentType().equals("text/plain"));
> }
> }
>
> sCon.close();
>
> }
>
> public void testSendReceiveNonRefAttachment() throws Exception {
> MessageFactory mf = MessageFactory.newInstance();
> SOAPMessage request = mf.createMessage();
>
> //create the SOAPPart
> createSimpleSOAPPart(request);
>
> //Attach a text/plain object with the SOAP request
> String sampleMessage = "Sample Message: Hello World!";
> AttachmentPart textAttach =
> request.createAttachmentPart(sampleMessage, "text/plain");
> request.addAttachmentPart(textAttach);
>
> //Attach a java.awt.Image object to the SOAP request
> String jpgfilename =
> System.getProperty("basedir", ".") + "/" +
> "target/test-resources/axis2.jpg";
> File myfile = new File(jpgfilename);
> FileDataSource fds = new FileDataSource(myfile);
> DataHandler imageDH = new DataHandler(fds);
> AttachmentPart jpegAttach = request.createAttachmentPart(imageDH);
> jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
> jpegAttach.setContentType("image/jpg");
> request.addAttachmentPart(jpegAttach);
>
>
> SOAPConnection sCon =
> SOAPConnectionFactory.newInstance().createConnection();
> SOAPMessage response = sCon.call(request, getAddress());
>
> int attachmentCount = response.countAttachments();
> assertTrue(attachmentCount == 2);
>
> Iterator attachIter = response.getAttachments();
>
> while (attachIter.hasNext()) {
> AttachmentPart attachment = (AttachmentPart)attachIter.next();
> final Object content =
> attachment.getDataHandler().getContent();
> if (content instanceof String) {
> assertEquals(sampleMessage, (String)content);
> } else if (content instanceof ByteArrayInputStream) {
> ByteArrayInputStream bais = (ByteArrayInputStream)content;
> byte[] b = new byte[15000];
> final int lengthRead = bais.read(b);
> FileOutputStream fos =
> new FileOutputStream(new
> File(System.getProperty("basedir", ".") + "/" +
>
> "target/target/test-resources/axis2.jpg"));
> fos.write(b, 0, lengthRead);
> fos.flush();
> fos.close();
>
>
> assertTrue(attachment.getContentType().equals("image/jpeg")
> ||
> attachment.getContentType().equals("text/plain"));
> }
> }
>
> sCon.close();
> }
>
> private void createSOAPPart(SOAPMessage message) throws SOAPException
> {
> SOAPPart sPart = message.getSOAPPart();
> SOAPEnvelope env = sPart.getEnvelope();
> SOAPBody body = env.getBody();
>
> final SOAPHeader soapHeader = env.getHeader();
> soapHeader
> .addHeaderElement(env.createName("TestHeader1", "swa",
> "http://fakeNamespace.org"));
> soapHeader
> .addHeaderElement(env.createName("TestHeader2", "swa",
> "http://fakeNamespace.org"));
> final SOAPHeaderElement headerEle3 =
> soapHeader.addHeaderElement(
> env.createName("TestHeader3", "swa",
> "http://fakeNamespace.org"));
> final SOAPElement ch1 = headerEle3.addChildElement("he3", "swa");
> ch1.addTextNode("Im Header Element of header3");
>
> Name ns = env.createName("echo", "swa",
> "http://fakeNamespace.org");
> SOAPBodyElement bodyElement = body.addBodyElement(ns);
>
> Name nameMain = env.createName("internal");
> SOAPElement mainChildEle = bodyElement.addChildElement(nameMain);
>
> Name ns2 = env.createName("text");
> SOAPElement textReference = mainChildEle.addChildElement(ns2);
> Name hrefAttr = env.createName("href");
> textReference.addAttribute(hrefAttr,
> "cid:submitSampleText@apache.org");
>
> Name ns3 = env.createName("image");
> SOAPElement imageReference = mainChildEle.addChildElement(ns3);
> Name ns31 = env.createName("inner");
> final SOAPElement img = imageReference.addChildElement(ns31);
> img.addAttribute(hrefAttr, "cid:submitSampleImage@apache.org");
>
> Name ns4 = env.createName("plaintxt");
> SOAPElement plainTxt = mainChildEle.addChildElement(ns4);
> plainTxt.addTextNode("This is simple plain text");
>
> Name ns5 = env.createName("nested");
> SOAPElement nested = mainChildEle.addChildElement(ns5);
> nested.addTextNode("Nested1 Plain Text");
> Name ns6 = env.createName("nested2");
> SOAPElement nested2 = nested.addChildElement(ns6);
> nested2.addTextNode("Nested2 Plain Text");
> }
>
> private void createSimpleSOAPPart(SOAPMessage message) throws
> SOAPException {
> SOAPPart sPart = message.getSOAPPart();
> SOAPEnvelope env = sPart.getEnvelope();
> SOAPBody body = env.getBody();
> SOAPHeader header = env.getHeader();
> header.addHeaderElement(env.createName("Header1",
> "pref",
>
> "http://test.apach.org/test"))
> .addTextNode("This is header1");
>
> Name ns = env.createName("echo", "swa2",
> "http://fakeNamespace2.org");
> final SOAPBodyElement bodyElement = body.addBodyElement(ns);
> Name ns2 = env.createName("something");
> final SOAPElement ele1 = bodyElement.addChildElement(ns2);
> ele1.addTextNode("This is some text");
>
> Name ns3 = env.createName("ping", "swa3",
> "http://fakeNamespace3.org");
> final SOAPBodyElement bodyElement2 = body.addBodyElement(ns3);
> Name ns4 = env.createName("another");
> final SOAPElement ele2 = bodyElement2.addChildElement(ns4);
> ele2.addTextNode("This is another text");
> }
>
>
> public void testSendReceive_ISO88591_EncodedSOAPMessage() {
> try{
> MimeHeaders mimeHeaders = new MimeHeaders();
> mimeHeaders.addHeader("Content-Type", "text/xml;
> charset=iso-8859-1");
>
> FileInputStream fileInputStream = new
> FileInputStream(System.getProperty("basedir", ".") +
> "/test-resources" + File.separator +
> "soap-part-iso-8859-1.xml");
> SOAPMessage requestMessage =
> MessageFactory.newInstance().createMessage(mimeHeaders,fileInputStream);
>
>
> SOAPConnection sCon =
> SOAPConnectionFactory.newInstance().createConnection();
> SOAPMessage response = sCon.call(requestMessage,
> getAddress());
> assertFalse(response.getAttachments().hasNext());
> assertEquals(0, response.countAttachments());
>
> printSOAPMessage(requestMessage);
> String responseStr = printSOAPMessage(response);
> assertTrue(responseStr.indexOf("This is some text.Here are
> some special chars : öÃî¤") != -1);
> assertTrue(responseStr.indexOf("echo") != -1);
> sCon.close();
> } catch (SOAPException e) {
> e.printStackTrace();
> fail("Unexpected Exception while running test: " + e);
> } catch (IOException e) {
> fail("Unexpected Exception while running test: " + e);
> }
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11188078
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: Running SAAJ problem
Posted by sumedha rubasinghe <su...@gmail.com>.
Hi joe,
I tried to regenerate what you have explained. But it is working for me.
And I could not find anything wrong in you code either. :-)
Could you tell me the version of Axis2 your using? (I am working on trunk).
At the same time, If you have a source distribution, following test case
contains several examples of using SAAJ.
modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java
I have also attached the latest version of the class.
Thank you.
/sumedha
On 6/18/07, Joe Nathan <jo...@yahoo.com> wrote:
>
>
> Thanks for the reply.
>
> My WEB-INF/services.xml is like this;
> ------------------------------------------------
> <service name="SoapService" scope="application">
> <description>RME Soap Service</description>
> <messageReceivers>
> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
> class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
> class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
> </messageReceivers>
> <schema schemaNamespace="http://localhost/axis2/services/SoapService?xsd
> "
> />
> <parameter name="ServiceClass">SoapService</parameter>
> </service>
> ------------------------------------------------------------------------
>
> Relevant part of wsdl query with
> "http://localhost/axis2/services/SoapService?wsdl"
> is like this;
> ------------------------------------------------------------------------
> <wsdl:documentation>SoapService</wsdl:documentation>
> - <wsdl:types>
> - <xs:schema xmlns:ns="http://localhost/axis2/services/SoapService?xsd"
> attributeFormDefault="qualified" elementFormDefault="qualified"
> targetNamespace="http://localhost/axis2/services/SoapService?xsd">
> - <xs:element name="mymethod">
> - <xs:complexType>
>
>
> ----------------------------------------------------------------------------
>
> The client SAAJ is;
>
> ========================================================
> QName bodyName = new QName("http://localhost/axis2/services/SoapService",
> "mymethod", "m");
> SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
>
> QName name = new QName("vinput");
> SOAPElement symbol = bodyElement.addChildElement(name);
> symbol.addTextNode("12667");
>
> URL endpoint = new
> URL(" http://localhost/axis2/services/SoapService/mymethod");
> SOAPMessage sresponse = connection.call(message, endpoint);
> connection.close();
> =====================================================
>
> I build an .aar file and place it to WEB-INF/services of Axis2 inflated
> directory. It works from browser URL queries, not from client programs!
>
> Thanks in advance!
>
>
>
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11170506
> Sent from the Axis - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>
Re: Running SAAJ problem
Posted by Joe Nathan <jo...@yahoo.com>.
Thanks for the reply.
My WEB-INF/services.xml is like this;
------------------------------------------------
<service name="SoapService" scope="application">
<description>RME Soap Service</description>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
<schema schemaNamespace="http://localhost/axis2/services/SoapService?xsd"
/>
<parameter name="ServiceClass">SoapService</parameter>
</service>
------------------------------------------------------------------------
Relevant part of wsdl query with
"http://localhost/axis2/services/SoapService?wsdl"
is like this;
------------------------------------------------------------------------
<wsdl:documentation>SoapService</wsdl:documentation>
- <wsdl:types>
- <xs:schema xmlns:ns="http://localhost/axis2/services/SoapService?xsd"
attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://localhost/axis2/services/SoapService?xsd">
- <xs:element name="mymethod">
- <xs:complexType>
----------------------------------------------------------------------------
The client SAAJ is;
========================================================
QName bodyName = new QName("http://localhost/axis2/services/SoapService",
"mymethod", "m");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
QName name = new QName("vinput");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("12667");
URL endpoint = new
URL(" http://localhost/axis2/services/SoapService/mymethod");
SOAPMessage sresponse = connection.call(message, endpoint);
connection.close();
=====================================================
I build an .aar file and place it to WEB-INF/services of Axis2 inflated
directory. It works from browser URL queries, not from client programs!
Thanks in advance!
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11170506
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org
Re: Running SAAJ problem
Posted by sumedha rubasinghe <su...@gmail.com>.
Hi Joe,
Change the following line
QName bodyName = new
QName("http://localhost/axis2/services/SoapService","mymethod",
"m");
to
QName bodyName = new QName("http://localhost/xsd","mymethod", "m");
and it should work.
When calling a service from a client, you need to use the namespace
appearing in the wsdl. Check your wsdl. It must be having "
http://localhost/xsd".
/sumedha
On 6/18/07, Joe Nathan <jo...@yahoo.com> wrote:
>
>
> Hi,
>
> I am running Axis2 under Tomcat.
> I got a problem SAAJ client work.
> POJO SOAP class is, say, "SoapService", method is "mymethod".
> From a Tomcat servlet, it calls a SOAP service serviced under
> the same Tomcat instance. However I keep getting the following
> error message;
>
> ----------------------------------------------------------------------------------
> SEVERE: Exception occurred while trying to invoke service method input
> org.apache.axis2.AxisFault: namespace mismatch require
> http://localhost/xsd
> found http://localhost/axis2/services/SoapService
> at
> org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(
> RPCMessageReceiver.java:103)
> at
> org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.receive(
> AbstractInOutSyncMessageReceiver.java:39)
> at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:144)
> at
> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(
>
> --------------------------------------------------------------------------------------
>
> The SAAJ program part is as follows;
>
> ---------------------------------------------------------------------------------
> SOAPConnectionFactory soapConnectionFactory =
> SOAPConnectionFactory.newInstance();
> SOAPConnection connection = soapConnectionFactory.createConnection();
> MessageFactory factory = MessageFactory.newInstance();
> SOAPMessage message = factory.createMessage();
>
> SOAPHeader header = message.getSOAPHeader();
> SOAPBody body = message.getSOAPBody();
> header.detachNode();
>
> QName bodyName = new QName("http://localhost/axis2/services/SoapService",
> "mymethod", "m");
> SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
>
> QName name = new QName("vinput");
> SOAPElement symbol = bodyElement.addChildElement(name);
> symbol.addTextNode("12667");
>
> URL endpoint = new
> URL("http://localhost/axis2/services/SoapService/mymethod");
> SOAPMessage sresponse = connection.call(message, endpoint);
> connection.close();
>
> ---------------------------------------------------------------------------------------
>
> Can you tell me what am I doing wrong?
> SOAP works if I try from web-browsers with the followin urls;
>
> http://localhost/axis2/services/listServices
> http://localhost/axis2/services/SoapService?wsdl
> http://localhost/axis2/services/SoapService?xsd
> http://localhost/axis2/services/SoapService/mymethod?vinput=15256
>
> Thanks in advance.
>
> Joe.
> --
> View this message in context:
> http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11168244
> Sent from the Axis - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>
Re: Running SAAJ problem
Posted by Joe Nathan <jo...@yahoo.com>.
I am getting rather curious whther SAAJ works on Axis properly. I spent on
this issue for many days already. For simple things like this, I am
expecting to find quick examples and quick suggestions for quick fixes!
I am wondering,....
--
View this message in context: http://www.nabble.com/Running-SAAJ-problem-tf3937707.html#a11185190
Sent from the Axis - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org