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 he...@apache.org on 2005/06/07 05:21:02 UTC

svn commit: r188675 - in /webservices/axis/trunk/java/modules: core/src/org/apache/axis/transport/http/ core/src/org/apache/axis/transport/mail/ samples/ samples/test/org/apache/axis/mail/

Author: hemapani
Date: Mon Jun  6 20:21:00 2005
New Revision: 188675

URL: http://svn.apache.org/viewcvs?rev=188675&view=rev
Log:
fix a bug in mail transport, add a  testcases, final cleanups for http server

Added:
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailRequestResponseRawXMLTest.java
Modified:
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/MailTransportSender.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/SimpleMailListener.java
    webservices/axis/trunk/java/modules/samples/project.xml
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailOneWayRawXMLTest.java

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java?rev=188675&r1=188674&r2=188675&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java Mon Jun  6 20:21:00 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.axis.transport.http;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
@@ -277,12 +278,12 @@
      */
     public static void main(String[] args) throws Exception {
         if (args.length != 2) {
-            System.out.println("SimpeHttpReciver repositoryLocation port");
+            System.out.println("SimpleHTTPServer repositoryLocation port");
         }
         ServerSocket serverSoc = null;
         serverSoc = new ServerSocket(Integer.parseInt(args[1]));
         SimpleHTTPServer reciver = new SimpleHTTPServer(args[0], serverSoc);
-
+        System.out.println("starting SimpleHTTPServer in port "+args[1]+ " using the repository "+ new File(args[0]).getAbsolutePath());
         reciver.setServerSocket(serverSoc);
         Thread thread = new Thread(reciver);
         thread.setDaemon(true);

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/MailTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/MailTransportSender.java?rev=188675&r1=188674&r2=188675&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/MailTransportSender.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/MailTransportSender.java Mon Jun  6 20:21:00 2005
@@ -20,6 +20,7 @@
 import java.io.OutputStreamWriter;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
+import java.io.StringWriter;
 import java.io.Writer;
 
 import org.apache.axis.addressing.EndpointReference;
@@ -35,7 +36,7 @@
     private String password;
     private String smtpPort = "25";
 
-    private PipedInputStream in;
+    private StringWriter w; 
 
     public MailTransportSender() {
 
@@ -56,22 +57,23 @@
                     //TODO this is just a temporary hack, fix this to use input streams
                     
                 
-                    byte[] message = new byte[in.available()];
-                    in.read(message);
+                    
                 
                     String eprAddress = msgContext.getTo().getAddress();
                     int index = eprAddress.indexOf('/');
                     String subject = "";
                     String email = null;
-                    if(index > 0){
+                    if(index >= 0){
                         subject = eprAddress.substring(index+1);
                         email = eprAddress.substring(0,index);
+                    }else{
+                        email = eprAddress;
                     }
                 
                     System.out.println(subject);
                     System.out.println(email);
 
-                    sender.send(subject, email, new String(message));
+                    sender.send(subject, email, w.getBuffer().toString());
                 } else {
                     throw new AxisFault(
                         "user, port, host or password not set, "
@@ -96,17 +98,8 @@
     }
 
     protected Writer openTheConnection(EndpointReference epr) throws AxisFault {
-
-        try {
-
-            in = new PipedInputStream();
-            PipedOutputStream out = new PipedOutputStream(in);
-
-            return new OutputStreamWriter(out);
-        } catch (IOException e) {
-            throw new AxisFault(e);
-        }
-
+            w = new StringWriter();
+            return w;
     }
 
     //Output Stream based cases are not supported 

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/SimpleMailListener.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/SimpleMailListener.java?rev=188675&r1=188674&r2=188675&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/SimpleMailListener.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/mail/SimpleMailListener.java Mon Jun  6 20:21:00 2005
@@ -16,10 +16,14 @@
 
 package org.apache.axis.transport.mail;
 
+import java.io.File;
+
 import javax.mail.Flags;
 import javax.mail.Message;
 import javax.mail.internet.MimeMessage;
+import javax.xml.namespace.QName;
 
+import org.apache.axis.Constants;
 import org.apache.axis.addressing.AddressingConstants;
 import org.apache.axis.addressing.EndpointReference;
 import org.apache.axis.context.ConfigurationContext;
@@ -31,7 +35,6 @@
 import org.apache.axis.util.Utils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.net.pop3.POP3Client;
 
 /**
  * This is a simple implementation of an SMTP/POP3 server for processing SOAP
@@ -68,7 +71,7 @@
 
     private String replyTo;
 
-    public SimpleMailListener() throws AxisFault{
+    public SimpleMailListener() {
     }
 
     public SimpleMailListener(
@@ -144,12 +147,12 @@
         }
         while (!stopped) {
             try {
-                
+
                 EmailReceiver receiver = new EmailReceiver(user, host, port, password);
                 receiver.connect();
                 Message[] msgs = receiver.receive();
 
-                if (msgs != null && msgs.length>0) {
+                if (msgs != null && msgs.length > 0) {
                     System.out.println(msgs.length + " Message Found");
                     for (int i = 0; i < msgs.length; i++) {
                         MimeMessage msg = (MimeMessage) msgs[i];
@@ -161,9 +164,9 @@
                     }
 
                 }
-                
+
                 receiver.disconnect();
-               
+
             } catch (Exception e) {
                 //log.debug(Messages.getMessage("exception00"), e); TODO Issue
                 // #1 CT 07-Feb-2005.
@@ -224,39 +227,27 @@
     /**
      * Server process.
      */
-    public static void main(String args[]) {
-        boolean optDoThreads = true;
-        String optHostName = "localhost";
-        boolean optUseCustomPort = false;
-        int optCustomPortToUse = 0;
-        String optDir = "/home/chamil/temp";
-        String optUserName = "server";
-        String optPassword = "server";
-        System.out.println("Starting the mail listner");
-        // Options object is not used for now. Hard coded values will be used.
-        // TODO have to meke this a bit more generic. CT 07-Feb-2005.
-        //Options opts = null;
-
-        /*
-         * try { opts = new Options(args); } catch (MalformedURLException e) {
-         * log.error(Messages.getMessage("malformedURLException00"), e); return; }
-         */
-        try {
-            doThreads = optDoThreads; //(opts.isFlagSet('t') > 0);
-            String host = optHostName; //opts.getHost();
-            String port = String.valueOf(((optUseCustomPort) ? optCustomPortToUse : 110));
-            POP3Client pop3 = new POP3Client();
-            SimpleMailListener sas =
-                new SimpleMailListener(host, port, optUserName, optPassword, optDir);
-            sas.start();
-        } catch (Exception e) {
-            // log.error(Messages.getMessage("exception00"), e); TODO Issue #1
-            // CT 07-Feb-2005.
-            log.error(
-                "An error occured in the main method of SimpleMailListner. TODO Detailed error message needs to be inserted here.");
-            return;
+    public static void main(String args[]) throws AxisFault {
+        if (args.length != 1) {
+            System.out.println("java SimpleMailListener <repository>");
+        } else {
+            ConfigurationContextFactory builder = new ConfigurationContextFactory();
+            ConfigurationContext configurationContext = builder.buildEngineContext(args[0]);
+            SimpleMailListener sas = new SimpleMailListener();
+            TransportInDescription transportIn =
+                configurationContext.getAxisConfiguration().getTransportIn(
+                    new QName(Constants.TRANSPORT_MAIL));
+            if (transportIn != null) {
+                sas.init(configurationContext, transportIn);
+                System.out.println(
+                    "Starting the SimpleMailListener with repository "
+                        + new File(args[0]).getAbsolutePath());
+                sas.start();
+            } else {
+                System.out.println(
+                    "Startup failed, mail transport not configured, Configure the mail trnasport in the server.xml file");
+            }
         }
-
     }
     /* (non-Javadoc)
      * @see org.apache.axis.transport.TransportListener#init(org.apache.axis.context.ConfigurationContext, org.apache.axis.description.TransportInDescription)
@@ -290,7 +281,7 @@
      */
     public EndpointReference replyToEPR(String serviceName) throws AxisFault {
         // TODO Auto-generated method stub
-        return new EndpointReference(AddressingConstants.WSA_REPLY_TO, replyTo);
+        return new EndpointReference(AddressingConstants.WSA_REPLY_TO, replyTo+"/services/"+serviceName);
     }
 
 }

Modified: webservices/axis/trunk/java/modules/samples/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/project.xml?rev=188675&r1=188674&r2=188675&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/project.xml (original)
+++ webservices/axis/trunk/java/modules/samples/project.xml Mon Jun  6 20:21:00 2005
@@ -125,6 +125,8 @@
 		<exclude>**/*InteropStubTest.java</exclude>
 		<exclude>**/*MailEchoRawXMLTest.java</exclude> 
 		<exclude>**/*MailOneWayRawXMLTest.java</exclude> 
+				<exclude>**/*MailRequestResponseRawXMLTest.java</exclude> 
+		
 		
       </excludes>
      <includes>

Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailOneWayRawXMLTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailOneWayRawXMLTest.java?rev=188675&r1=188674&r2=188675&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailOneWayRawXMLTest.java (original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailOneWayRawXMLTest.java Mon Jun  6 20:21:00 2005
@@ -19,24 +19,18 @@
 //todo
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
 
 import junit.framework.TestCase;
 
 import org.apache.axis.Constants;
 import org.apache.axis.addressing.AddressingConstants;
 import org.apache.axis.addressing.EndpointReference;
-import org.apache.axis.clientapi.AsyncResult;
-import org.apache.axis.clientapi.Callback;
 import org.apache.axis.clientapi.MessageSender;
 import org.apache.axis.context.ConfigurationContext;
 import org.apache.axis.context.ConfigurationContextFactory;
 import org.apache.axis.context.MessageContext;
 import org.apache.axis.context.ServiceContext;
-import org.apache.axis.deployment.DeploymentException;
 import org.apache.axis.description.OperationDescription;
-import org.apache.axis.description.Parameter;
 import org.apache.axis.description.ParameterImpl;
 import org.apache.axis.description.ServiceDescription;
 import org.apache.axis.description.TransportInDescription;

Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailRequestResponseRawXMLTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailRequestResponseRawXMLTest.java?rev=188675&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailRequestResponseRawXMLTest.java (added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/mail/MailRequestResponseRawXMLTest.java Mon Jun  6 20:21:00 2005
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2004,2005 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.axis.mail;
+
+//todo
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.TestCase;
+
+import org.apache.axis.Constants;
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.clientapi.AsyncResult;
+import org.apache.axis.clientapi.Callback;
+import org.apache.axis.context.ConfigurationContext;
+import org.apache.axis.context.ConfigurationContextFactory;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.context.ServiceContext;
+import org.apache.axis.description.OperationDescription;
+import org.apache.axis.description.ParameterImpl;
+import org.apache.axis.description.ServiceDescription;
+import org.apache.axis.description.TransportInDescription;
+import org.apache.axis.description.TransportOutDescription;
+import org.apache.axis.engine.AxisConfiguration;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.engine.Echo;
+import org.apache.axis.engine.MessageReceiver;
+import org.apache.axis.om.OMAbstractFactory;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.soap.SOAPEnvelope;
+import org.apache.axis.transport.mail.MailTransportSender;
+import org.apache.axis.transport.mail.SimpleMailListener;
+import org.apache.axis.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class MailRequestResponseRawXMLTest extends TestCase {
+    private EndpointReference targetEPR =
+        new EndpointReference(
+            AddressingConstants.WSA_TO,
+            "axis2-server@127.0.0.1" + "/axis/services/EchoXMLService/echoOMElement");
+    private Log log = LogFactory.getLog(getClass());
+    private QName serviceName = new QName("EchoXMLService");
+    private QName operationName = new QName("echoOMElement");
+    private QName transportName = new QName("http://localhost/my", "NullTransport");
+
+    private AxisConfiguration engineRegistry;
+    private MessageContext mc;
+
+    private SOAPEnvelope envelope;
+
+    private boolean finish = false;
+
+    public MailRequestResponseRawXMLTest() {
+        super(MailRequestResponseRawXMLTest.class.getName());
+    }
+
+    public MailRequestResponseRawXMLTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        SimpleMailListener ml = new SimpleMailListener();
+
+        ConfigurationContext configContext = createServerConfigurationContext();
+        ml.init(
+            configContext,
+            configContext.getAxisConfiguration().getTransportIn(
+                new QName(Constants.TRANSPORT_MAIL)));
+        ml.start();
+        configContext.getAxisConfiguration().engageModule(new QName(Constants.MODULE_ADDRESSING));
+        ServiceDescription service =
+            Utils.createSimpleService(serviceName, Echo.class.getName(), operationName);
+        configContext.getAxisConfiguration().addService(service);
+        Utils.resolvePhases(configContext.getAxisConfiguration(), service);
+        ServiceContext serviceContext = configContext.createServiceContext(serviceName);
+    }
+
+    protected void tearDown() throws Exception {
+    }
+
+    private OMElement createEnvelope() {
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+        OMElement method = fac.createOMElement("echoOMElement", omNs);
+        OMElement value = fac.createOMElement("myValue", omNs);
+        value.addChild(fac.createText(value, "Isaac Assimov, the foundation Sega"));
+        method.addChild(value);
+
+        return method;
+    }
+
+    public void testEchoXMLCompleteASync() throws Exception {
+
+        ConfigurationContext configContext = createClientConfigurationContext();
+        ServiceDescription service = new ServiceDescription(serviceName);
+        OperationDescription operation = new OperationDescription(operationName);
+        operation.setMessageReciever(new MessageReceiver() {
+            public void recieve(MessageContext messgeCtx) throws AxisFault {
+                envelope = messgeCtx.getEnvelope();
+            }
+        });
+        service.addOperation(operation);
+        configContext.getAxisConfiguration().addService(service);
+        Utils.resolvePhases(configContext.getAxisConfiguration(), service);
+        ServiceContext serviceContext = configContext.createServiceContext(serviceName);
+
+        org.apache.axis.clientapi.Call call = new org.apache.axis.clientapi.Call(serviceContext);
+        call.engageModule(new QName(Constants.MODULE_ADDRESSING));
+
+        try {
+            call.setTo(targetEPR);
+            call.setTransportInfo(Constants.TRANSPORT_MAIL, Constants.TRANSPORT_MAIL, true);
+            Callback callback = new Callback() {
+                public void onComplete(AsyncResult result) {
+                    try {
+                        result.getResponseEnvelope().serialize(
+                            XMLOutputFactory.newInstance().createXMLStreamWriter(System.out));
+                    } catch (XMLStreamException e) {
+                        reportError(e);
+                    } finally {
+                        finish = true;
+                    }
+                }
+
+                public void reportError(Exception e) {
+                    e.printStackTrace();
+                    finish = true;
+                }
+            };
+
+            call.invokeNonBlocking(operationName.getLocalPart(), createEnvelope(), callback);
+            int index = 0;
+            while (!finish) {
+                Thread.sleep(1000);
+                index++;
+//                if (index > 10) {
+//                    throw new AxisFault("Server is shutdown as the Async response take too longs time");
+//                }
+            }
+        } finally {
+            call.close();
+        }
+
+    }
+    public ConfigurationContext createServerConfigurationContext() throws Exception {
+        ConfigurationContextFactory builder = new ConfigurationContextFactory();
+        ConfigurationContext configContext =
+            builder.buildEngineContext(org.apache.axis.Constants.TESTING_REPOSITORY);
+
+        TransportInDescription transportIn =
+            new TransportInDescription(new QName(Constants.TRANSPORT_MAIL));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.host", "127.0.0.1"));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.user", "axis2-server"));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.password", "axis2"));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.port", "110"));
+        transportIn.addParameter(
+            new ParameterImpl("transport.mail.replyToAddress", "axis2-server@127.0.0.1"));
+        transportIn.setReciver(new SimpleMailListener());
+
+        TransportOutDescription transportOut =
+            new TransportOutDescription(new QName(Constants.TRANSPORT_MAIL));
+
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.host", "127.0.0.1"));
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.user", "axis2-server"));
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.password", "axis2"));
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.port", "25"));
+        transportOut.setSender(new MailTransportSender());
+
+        configContext.getAxisConfiguration().addTransportIn(transportIn);
+        configContext.getAxisConfiguration().addTransportOut(transportOut);
+        return configContext;
+    }
+
+    public ConfigurationContext createClientConfigurationContext() throws Exception {
+        ConfigurationContextFactory builder = new ConfigurationContextFactory();
+        ConfigurationContext configContext =
+            builder.buildEngineContext(org.apache.axis.Constants.TESTING_REPOSITORY);
+
+        TransportInDescription transportIn =
+            new TransportInDescription(new QName(Constants.TRANSPORT_MAIL));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.host", "127.0.0.1"));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.user", "axis2-client"));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.password", "axis2"));
+        transportIn.addParameter(new ParameterImpl("transport.mail.pop3.port", "110"));
+        transportIn.addParameter(
+            new ParameterImpl("transport.mail.replyToAddress", "axis2-client@127.0.0.1"));
+        transportIn.setReciver(new SimpleMailListener());
+
+        TransportOutDescription transportOut =
+            new TransportOutDescription(new QName(Constants.TRANSPORT_MAIL));
+
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.host", "127.0.0.1"));
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.user", "axis2-client"));
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.password", "axis2"));
+        transportOut.addParameter(new ParameterImpl("transport.mail.smtp.port", "25"));
+        transportOut.setSender(new MailTransportSender());
+
+        configContext.getAxisConfiguration().addTransportIn(transportIn);
+        configContext.getAxisConfiguration().addTransportOut(transportOut);
+        return configContext;
+    }
+
+}