axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "sumedha rubasinghe" <sumedh...@gmail.com>
Subject Re: Running SAAJ problem
Date Tue, 19 Jun 2007 10:52:57 GMT
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 <jowen4077@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 <jowen4077@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
>
>
Mime
View raw message