axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cha...@apache.org
Subject svn commit: r398923 - in /webservices/axis2/trunk/java: modules/core/src/org/apache/axis2/transport/mail/server/ modules/integration/test/org/apache/axis2/mail/ xdocs/latest/
Date Tue, 02 May 2006 12:09:26 GMT
Author: chamil
Date: Tue May  2 05:08:36 2006
New Revision: 398923

URL: http://svn.apache.org/viewcvs?rev=398923&view=rev
Log:
Changes to docs and made the MailCharSetEncodingTest to run. 
Some enhancements were also done to the MailServer.

Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mail/MailCharSetEncodingTest.java
    webservices/axis2/trunk/java/xdocs/latest/mail-transport.html

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java?rev=398923&r1=398922&r2=398923&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java
Tue May  2 05:08:36 2006
@@ -29,13 +29,6 @@
             throws AxisFault {
         this.configurationContext = configurationContext;
 
-        try {
-            log.info("Sleeping for a bit to let the engine start up.");
-            Thread.sleep(2000);
-        } catch (InterruptedException e1) {
-            log.error(e1);
-        }
-
         st = new Storage();
 
         // Start up the two servers and lets have some fun. - CT
@@ -43,6 +36,12 @@
         smtpServer.start();
         pop3Server = new POP3Server(st, popPort);
         pop3Server.start();
+        try {
+            log.info("Sleeping for a bit to let the mail server start up.");
+            Thread.sleep(2000);
+        } catch (InterruptedException e1) {
+            log.error(e1);
+        } 
     }
 
     public MailServer(String dir, int popPort, int smtpPort) throws AxisFault {
@@ -66,6 +65,12 @@
         smtpServer.start();
         pop3Server = new POP3Server(st, popPort);
         pop3Server.start();
+        try {
+            log.info("Sleeping for a bit to let the engine start up.");
+            Thread.sleep(2000);
+        } catch (InterruptedException e1) {
+            log.error(e1);
+        }
     }
 
     public static void main(String args[]) {
@@ -94,5 +99,11 @@
     public void stop() throws AxisFault {
         smtpServer.stopServer();
         pop3Server.stopServer();
+        try {
+            log.info("Giving some time for the sockets to close.");
+            Thread.sleep(2000);
+        } catch (InterruptedException e1) {
+            log.error(e1);
+        }
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java?rev=398923&r1=398922&r2=398923&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java
Tue May  2 05:08:36 2006
@@ -90,6 +90,7 @@
             synchronized (this) {
                 running = false;
                 ss.close();
+                ss = null;
             }
         } catch (IOException e) {
             throw new AxisFault(e);

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mail/MailCharSetEncodingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mail/MailCharSetEncodingTest.java?rev=398923&r1=398922&r2=398923&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mail/MailCharSetEncodingTest.java
(original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mail/MailCharSetEncodingTest.java
Tue May  2 05:08:36 2006
@@ -32,8 +32,10 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.description.OutInAxisOperation;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.Echo;
@@ -51,12 +53,14 @@
  */
 public class MailCharSetEncodingTest extends TestCase {
 
-    private EndpointReference targetEPR = new EndpointReference("foo@127.0.0.1"
+    private EndpointReference targetEPR = new EndpointReference("mail:foo@127.0.0.1"
             + "/axis2/services/EchoXMLService/echoOMElement");
 
     private Log log = LogFactory.getLog(getClass());
 
-    private QName serviceName = new QName("EchoXMLService");
+    private String stringServiceName = "EchoXMLService";
+
+    private QName serviceName = new QName(stringServiceName);
 
     private QName operationName = new QName("echoOMElement");
 
@@ -72,103 +76,94 @@
 
     ConfigurationContext clientConfigContext;
 
-    ConfigurationContext configContext;
+    ConfigurationContext serverConfigContext;
 
     public MailCharSetEncodingTest() {
         super(MailCharSetEncodingTest.class.getName());
     }
 
     protected void setUp() throws Exception {
-        configContext = UtilsMailServer.start();
-
-        AxisService service = Utils.createSimpleService(serviceName,
-                Echo.class.getName(), operationName);
-        configContext.getAxisConfiguration().addService(service);
+    	    serverConfigContext = UtilsMailServer.start();
+        if (serverConfigContext.getAxisConfiguration().getService(stringServiceName) == null){
+		    AxisService service = Utils.createSimpleService(serviceName,
+		            Echo.class.getName(), operationName);
+		    serverConfigContext.getAxisConfiguration().addService(service);
+        }
 
         SimpleMailListener ml = new SimpleMailListener();
 
-        ml.init(configContext, configContext.getAxisConfiguration()
+        ml.init(serverConfigContext, serverConfigContext.getAxisConfiguration()
                 .getTransportIn(new QName(Constants.TRANSPORT_MAIL)));
         ml.start();
 
     }
 
+    protected void tearDown() throws Exception {
+        UtilsMailServer.stop();
+    }
+
     public void runTest(String value) throws Exception {
         finish = false;
         resultElem = null;
         envelope = null;
-        try {
-            if (clientConfigContext == null) {
-                clientConfigContext = UtilsMailServer
-                        .createClientConfigurationContext();
-                engineRegistry = clientConfigContext.getAxisConfiguration();
+        ConfigurationContext configContext = UtilsMailServer
+                .createClientConfigurationContext();
+        AxisService service = null;
+        AxisOperation axisOperation = null;
+        if (configContext.getAxisConfiguration().getService(stringServiceName) != null){
+            configContext.getAxisConfiguration().removeService(stringServiceName);
+        }
+        service = new AxisService(serviceName.getLocalPart());
+        axisOperation = new OutInAxisOperation();
+        axisOperation.setName(operationName);
+        axisOperation.setMessageReceiver(new MessageReceiver() {
+            public void receive(MessageContext messageCtx) {
+                envelope = messageCtx.getEnvelope();
+            }
+        });
+        service.addOperation(axisOperation);
+        configContext.getAxisConfiguration().addService(service);
+
+        Options options = new Options();
+        options.setTo(targetEPR);
+        options.setAction(operationName.getLocalPart());
+        options.setTransportInProtocol(Constants.TRANSPORT_MAIL);
+        options.setUseSeparateListener(true);
+
+        Callback callback = new Callback() {
+            public void onComplete(AsyncResult result) {
+                resultElem = result.getResponseEnvelope();
+                finish = true;
             }
-            AxisService clientService = new AxisService(
-                    serviceName.getLocalPart());
-            AxisOperation clientOperation = new OutInAxisOperation(
-            );
-            clientOperation.setName(operationName);
-            clientOperation.setMessageReceiver(new MessageReceiver() {
-                public void receive(MessageContext messageCtx) {
-                    envelope = messageCtx.getEnvelope();
-                }
-            });
-            engineRegistry.removeService(serviceName.getLocalPart());
-            clientService.addOperation(clientOperation);
-            engineRegistry.addService(clientService);
-            clientServiceContext = Utils.fillContextInformation(clientService, clientConfigContext);
-
-
-            Options options = new Options();
-            options.setTo(targetEPR);
-            options.setTransportInProtocol(Constants.TRANSPORT_MAIL);
-            options.setUseSeparateListener(true);
-            Callback callback = new Callback() {
-                public void onComplete(AsyncResult result) {
-                    resultElem = result.getResponseEnvelope();
-                    finish = true;
-                }
-
-                public void onError(Exception e) {
-                    log.error(e.getMessage(), e);
-                    finish = true;
-                }
-            };
-            ServiceClient sender = new ServiceClient(clientConfigContext, clientService);
-            sender.setOptions(options);
-            options.setTo(targetEPR);
-            sender.sendReceiveNonBlocking(operationName,createEnvelope(value), callback);
-
-            int index = 0;
-            while (!finish) {
-                Thread.sleep(1000);
-                index++;
-                if (index > 10) {
-                    throw new AxisFault(
-                            "Async response is taking too long[10s+]. Server is being shut
down.");
-                }
+
+            public void onError(Exception e) {
+                log.info(e.getMessage());
+                finish = true;
             }
-            // call.close();
-            assertNotNull("Result is null", resultElem);
-            String result = ((OMElement) resultElem.getFirstOMChild()
-                    .getNextOMSibling()).getFirstElement().getFirstElement()
-                    .getText();
-
-            assertNotNull("Result value is null", result);
-
-            assertEquals("Expected result not received.", value, result);
-
-        } catch (AxisFault e) {
-            log.error(e, e);
-            throw e;
-        } catch (InterruptedException e) {
-            log.error(e, e);
-            throw e;
-        } catch (Exception e) {
-            log.error(e, e);
-            throw e;
+        };
 
+        ServiceClient sender = new ServiceClient(configContext, service);
+        sender.setOptions(options);
+        //options.setTo(targetEPR);
+        sender.sendReceiveNonBlocking(operationName, createEnvelope(value), callback);
+
+        int index = 0;
+        while (!finish) {
+            Thread.sleep(1000);
+            index++;
+            if (index > 10) {
+                throw new AxisFault(
+                        "Server was shutdown as the async response is taking too long to
complete.");
+            }
         }
+        assertNotNull("Result is null", resultElem);
+        String result = ((OMElement) resultElem.getFirstOMChild()
+                .getNextOMSibling()).getFirstElement().getFirstElement()
+                .getText();
+
+        assertNotNull("Result value is null", result);
+        assertEquals("Expected result not received.", value, result);
+
     }
 
     public void testSimpleString() throws Exception {
@@ -189,37 +184,6 @@
 
     public void testStringWithLeadingAndTrailingSpaces() throws Exception {
         runTest("          centered          ");
-    }
-
-    public void testWhitespace() throws Exception {
-        runTest(" \n \t "); // note: \r fails
-    }
-
-    public void testFrenchAccents() throws Exception {
-        runTest("\u00e0\u00e2\u00e4\u00e7\u00e8\u00e9\u00ea\u00eb\u00ee\u00ef\u00f4\u00f6\u00f9\u00fb\u00fc");
-    }
-
-    public void testGermanUmlauts() throws Exception {
-        runTest(" Some text \u00df with \u00fc special \u00f6 chars \u00e4.");
-    }
-
-    public void testWelcomeUnicode() throws Exception {
-        // welcome in several languages
-        runTest("Chinese (trad.) : \u6b61\u8fce  ");
-    }
-
-    public void testWelcomeUnicode2() throws Exception {
-        // welcome in several languages
-        runTest("Greek : \u03ba\u03b1\u03bb\u03ce\u03c2 \u03bf\u03c1\u03af\u03c3\u03b1\u03c4\u03b5");
-    }
-
-    public void testWelcomeUnicode3() throws Exception {
-        // welcome in several languages
-        runTest("Japanese : \u3088\u3046\u3053\u305d");
-    }
-
-    protected void tearDown() throws Exception {
-        UtilsMailServer.stop();
     }
 
     private OMElement createEnvelope(String text) {

Modified: webservices/axis2/trunk/java/xdocs/latest/mail-transport.html
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/xdocs/latest/mail-transport.html?rev=398923&r1=398922&r2=398923&view=diff
==============================================================================
--- webservices/axis2/trunk/java/xdocs/latest/mail-transport.html (original)
+++ webservices/axis2/trunk/java/xdocs/latest/mail-transport.html Tue May  2 05:08:36 2006
@@ -89,17 +89,18 @@
         // Start the default mail listener. It will starting poling for mail
         // using the configuration from the XML file.
         SimpleMailListener ml = new SimpleMailListener();
-        ml.init(configContext, configContext.getAxisConfiguration()
-                .getTransportIn(new QName(Constants.TRANSPORT_MAIL)));
+        ml.init(configContext,
+                configContext.getAxisConfiguration().getTransportIn(
+                        new QName(Constants.TRANSPORT_MAIL)));
         ml.start();
 
+        private QName serviceName = new QName("EchoXMLService");
+        private QName operationName = new QName("echoOMElement");
+    
         // Setup a service that will echo what we send to the server.
-        AxisService axisService = Utils.createSimpleService(serviceName,
-                Echo.class.getName(), new QName("echoOMElement"));
-        configContext.getAxisConfiguration().addService(axisService);
-        Utils.resolvePhases(configContext.getAxisConfiguration(), axisService);
-        ServiceContext serviceContext = configContext
-                .createServiceContext(new QName("EchoXMLService"));</pre>
+        AxisService service = Utils.createSimpleService(serviceName, Echo.class
+                .getName(), operationName);
+        serverConfigContext.getAxisConfiguration().addService(service);</pre>
 </source>
 <p>This code sets up your Axis2 server working through mail, with a single
 service. If you need to have a look under the hood check out the MailServer
@@ -109,57 +110,60 @@
 call the axisService that was setup on the previous code listing.</p>
 <source><pre>        ConfigurationContext configContext = UtilsMailServer
                 .createClientConfigurationContext();
-        AxisService axisService = new AxisService(serviceName);
-        AxisOperation axisOperation = new AxisOperation(operationName);
+        AxisService service = new AxisService(serviceName.getLocalPart());
+        AxisOperation axisOperation = new OutInAxisOperation();
+        axisOperation.setName(operationName);
         axisOperation.setMessageReceiver(new MessageReceiver() {
-                public void receive(MessageContext messgeCtx) throws AxisFault {
-                        envelope = messgeCtx.getEnvelope();
-                }
+            public void receive(MessageContext messageCtx) {
+                envelope = messageCtx.getEnvelope();
+            }
         });
-        axisService.addOperation(axisOperation);
-        configContext.getAxisConfiguration().addService(axisService);
-        Utils.resolvePhases(configContext.getAxisConfiguration(), axisService);
-        ServiceContext serviceContext = configContext
-                .createServiceContext(serviceName);
-                
+        service.addOperation(axisOperation);
+        configContext.getAxisConfiguration().addService(service);
+        ServiceContext serviceContext = new ServiceGroupContext(configContext,
+        		(AxisServiceGroup) service.getParent()).getServiceContext(service);
+
         Options options = new Options();
         options.setTo(targetEPR);
+        options.setAction(operationName.getLocalPart());
         options.setTransportInProtocol(Constants.TRANSPORT_MAIL);
         options.setUseSeparateListener(true);
-        // Create a callback to set to the axisService invocation.
+
         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 onComplete(AsyncResult result) {
+                try {
+                    result.getResponseEnvelope().serializeAndConsume(
+                            XMLOutputFactory.newInstance()
+                                    .createXMLStreamWriter(System.out));
+                } catch (XMLStreamException e) {
+                    onError(e);
+                } finally {
+                    finish = true;
                 }
-                public void reportError(Exception e) {
-                        log.info(e.getMessage());
-                        finish = true;
-                }
-         };
+            }
+
+            public void onError(Exception e) {
+                log.info(e.getMessage());
+                finish = true;
+            }
+        };
 
-        ServiceClient sender = new ServiceClient(configContext, axisService);
+        ServiceClient sender = new ServiceClient(configContext, service);
         sender.setOptions(options);
-        options.setTo(targetEPR);
-        // Call the service and start poling for the reply from the server.
-        sender.sendReceiveNonBlocking(operationName.getLocalPart(), createEnvelope(), callback);
+        //options.setTo(targetEPR);
+        sender.sendReceiveNonBlocking(operationName, createEnvelope(), callback);
 
         int index = 0;
         while (!finish) {
-                Thread.sleep(1000);
-                index++;
-                if (index &gt; 10) {
-                        throw new AxisFault(
-                                "Server is being shutdown as the Async response is taking
too long.");
-                }
-        }</pre>
+            Thread.sleep(1000);
+            index++;
+            if (index > 10) {
+                throw new AxisFault(
+                        "Server was shutdown as the async response is taking too long to
complete.");
+            }
+        }
+
+    }</pre>
 </source>
 <p>This will call the service that was setup on the server and will poll the
 mail server till the response is received.Thats all there is to it. Please do
@@ -173,8 +177,8 @@
 use server@somewhere.org and client@somewhere.org as the server and the
 client email addresses. Now that we have the email addresses you will have to
 set up the client and the server with Mail Transport <a
-href="http://ws.apache.org/axis2/mail-transport.html"
-target="_blank">introduction document</a>.</p>
+href="mail-configuration.html"
+target="_blank">configuration document</a>.</p>
 
 <p>When calling the generic mail server the client side code will remain the
 same and there will be some modification to the server-side code.</p>
@@ -184,22 +188,24 @@
         // address to listen to from the configuration file.
         File file = new File(MAIL_TRANSPORT_SERVER_ENABLED_REPO_PATH);
         ConfigurationContextFactory builder = new ConfigurationContextFactory();
-        ConfigurationContext configContextbuilder
+        ConfigurationContext configContext = configContextbuilder
                 .buildConfigurationContext(file.getAbsolutePath());
 
-        // Startup the default mail server and start listening to a 
-        // mail address.
+        // Start the default mail listener. It will starting poling for mail
+        // using the configuration from the XML file.
         SimpleMailListener ml = new SimpleMailListener();
-        ml.init(configContext, configContext.getAxisConfiguration()
-                .getTransportIn(new QName(Constants.TRANSPORT_MAIL)));
+        ml.init(configContext,
+                configContext.getAxisConfiguration().getTransportIn(
+                        new QName(Constants.TRANSPORT_MAIL)));
         ml.start();
 
-        // Setup a simple service.
-        AxisService axisService = Utils.createSimpleService(serviceName,
-                Echo.class.getName(), operationName);
-        configContext.getAxisConfiguration().addService(axisService);
-        Utils.resolvePhases(configContext.getAxisConfiguration(), axisService);
-        ServiceContext serviceContext = configContext.createServiceContext(serviceName);</pre>
+        private QName serviceName = new QName("EchoXMLService");
+        private QName operationName = new QName("echoOMElement");
+    
+        // Setup a service that will echo what we send to the server.
+        AxisService service = Utils.createSimpleService(serviceName, Echo.class
+                .getName(), operationName);
+        serverConfigContext.getAxisConfiguration().addService(service);</pre>
 </source>
 <p>Note that a separate ConfigurationContext needs to be created and used.</p>
 <a name="mailet"></a>



Mime
View raw message