Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 38677 invoked from network); 20 May 2005 11:11:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 May 2005 11:11:26 -0000 Received: (qmail 23115 invoked by uid 500); 20 May 2005 11:11:24 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 22856 invoked by uid 500); 20 May 2005 11:11:23 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 22843 invoked by uid 99); 20 May 2005 11:11:22 -0000 X-ASF-Spam-Status: No, hits=-9.7 required=10.0 tests=ALL_TRUSTED,NORMAL_HTTP_TO_IP,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 20 May 2005 04:11:13 -0700 Received: (qmail 38488 invoked by uid 65534); 20 May 2005 11:11:10 -0000 Message-ID: <20050520111110.38487.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r171100 - in /webservices/axis/trunk/java/modules: core/src/org/apache/axis/clientapi/ core/src/org/apache/axis/transport/ core/src/org/apache/axis/transport/http/ core/src/org/apache/axis/transport/mail/ core/src/org/apache/axis/transport/tcp/ core/test/org/apache/axis/transport/ samples/ samples/test/org/apache/axis/engine/ samples/test/org/apache/axis/integration/ Date: Fri, 20 May 2005 11:11:08 -0000 To: axis-cvs@ws.apache.org From: hemapani@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: hemapani Date: Fri May 20 04:11:07 2005 New Revision: 171100 URL: http://svn.apache.org/viewcvs?rev=3D171100&view=3Drev Log: add tcp and mail transport improvements Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/SimpleMailListener.java webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine= /TCPEchoRawXMLTest.java webservices/axis/trunk/java/modules/samples/test/org/apache/axis/integr= ation/UtilsTCPServer.java Removed: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/SimpleMailListner.java Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= InOnlyMEPClient.java webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= InOutMEPClient.java webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= Stub.java webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= TransportSender.java webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= http/HTTPTransportReceiver.java webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= http/HTTPTransportSender.java 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/MailConstants.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/MailWorker.java webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= tcp/TCPServer.java webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= tcp/TCPTransportSender.java webservices/axis/trunk/java/modules/core/test/org/apache/axis/transport= /SimpleMailListnerTest.java webservices/axis/trunk/java/modules/samples/project.xml webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine= /EchoRawXMLOnTwoChannelsTest.java webservices/axis/trunk/java/modules/samples/test/org/apache/axis/integr= ation/UtilServer.java Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/clie= ntapi/InOnlyMEPClient.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/clientapi/InOnlyMEPClient.java?rev=3D171100&r1=3D17109= 9&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= InOnlyMEPClient.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= InOnlyMEPClient.java Fri May 20 04:11:07 2005 @@ -80,7 +80,7 @@ =20 //TODO Fix this we support only the HTTP Sync cases, so we hardcod= e this HTTPTransportReceiver receiver =3D new HTTPTransportReceiver(); - receiver.invoke(response, sysContext); + receiver.checkForResponse(response, sysContext); SOAPEnvelope resenvelope =3D response.getEnvelope(); if (response!=3D null && resenvelope.getBody().hasFault()) { throw new AxisFault(resenvelope.getBody().getFault().getExcept= ion()); Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/clie= ntapi/InOutMEPClient.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/clientapi/InOutMEPClient.java?rev=3D171100&r1=3D171099= &r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= InOutMEPClient.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= InOutMEPClient.java Fri May 20 04:11:07 2005 @@ -18,8 +18,13 @@ package org.apache.axis.clientapi; =20 import java.io.IOException; +import java.io.Reader; =20 import javax.xml.namespace.QName; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; =20 import org.apache.axis.Constants; import org.apache.axis.addressing.EndpointReference; @@ -34,7 +39,9 @@ import org.apache.axis.engine.AxisEngine; import org.apache.axis.engine.AxisFault; import org.apache.axis.om.OMException; +import org.apache.axis.om.impl.llom.builder.StAXBuilder; import org.apache.axis.soap.SOAPEnvelope; +import org.apache.axis.soap.impl.llom.builder.StAXSOAPModelBuilder; import org.apache.axis.transport.http.HTTPTransportReceiver; import org.apache.wsdl.WSDLConstants; =20 @@ -58,21 +65,19 @@ * SMTP transport support only two channel case */ protected boolean useSeparateListener =3D false; - =20 + /** * The address the message should be send */ protected EndpointReference to; =20 - //variables use for internal implementations - =20 + /** * This is used for the Receiving the Async Messages=20 */ protected CallbackReceiver callbackReceiver; - =20 - =20 + /** * This accepts a ServiceContext, and the ServiceContext should have a= ll the parents set in to it right * Ideall this should be generated from a WSDL, we do not have it yet.=20 @@ -82,7 +87,7 @@ * ConfigurationContextFactory efac =3D new ConfigurationContextFacto= ry(); ConfigurationContext sysContext =3D efac.buildClientEngineContext(= null);=20 // above line "null" may be a file name if you know the client rep= ssitory - + =20 //create new service QName assumedServiceName =3D new QName("Your Service"); ServiceDescription axisService =3D new ServiceDescription(assumedS= erviceName); @@ -93,7 +98,7 @@ * *=20 * @param serviceContext - */ =20 + */ =20 public InOutMEPClient(ServiceContext serviceContext) { super(serviceContext, WSDLConstants.MEP_URI_OUT_IN); @@ -101,11 +106,11 @@ callbackReceiver =3D new CallbackReceiver(); } =20 -// this method is commented out, till we implemented it =20 -// public InOutMEPClient(String wsdlfile) { -// super(null, WSDLConstants.MEP_URI_OUT_IN); -// throw new UnsupportedOperationException(); -// } + // this method is commented out, till we implemented it =20 + // public InOutMEPClient(String wsdlfile) { + // super(null, WSDLConstants.MEP_URI_OUT_IN); + // throw new UnsupportedOperationException(); + // } =20 public MessageContext invokeBlocking(OperationDescription axisop, fina= l MessageContext msgctx) throws AxisFault { @@ -115,16 +120,7 @@ msgctx.setServiceContext(serviceContext); ConfigurationContext syscontext =3D serviceContext.getEngineContex= t(); =20 - if (senderTransport =3D=3D null) { - senderTransport =3D inferTransport(to); - } - final TransportInDescription transportIn =3D - syscontext.getEngineConfig().getTransportIn(new QName(senderTr= ansport)); - final TransportOutDescription transportOut =3D - syscontext.getEngineConfig().getTransportOut(new QName(listene= rTransport)); - - msgctx.setTransportIn(transportIn); - msgctx.setTransportOut(transportOut); + checkTransport(msgctx); =20 ConfigurationContext sysContext =3D serviceContext.getEngineContex= t(); AxisConfiguration registry =3D sysContext.getEngineConfig(); @@ -154,13 +150,20 @@ response.setOperationContext(msgctx.getOperationContext()); response.setServiceContext(msgctx.getServiceContext()); =20 - //TODO Fix this we support only the HTTP Sync cases, so we har= dcode this - HTTPTransportReceiver receiver =3D new HTTPTransportReceiver(); - receiver.invoke(response, sysContext); - SOAPEnvelope resenvelope =3D response.getEnvelope(); - if (resenvelope.getBody().hasFault()) { - throw new AxisFault(resenvelope.getBody().getFault().getEx= ception()); + SOAPEnvelope resenvelope =3D checkReturnChannel(response); + if (resenvelope !=3D null) { + response.setEnvelope(resenvelope); + engine =3D new AxisEngine(serviceContext.getEngineContext(= )); + engine.receive(response); + + resenvelope =3D response.getEnvelope(); + if (resenvelope.getBody().hasFault()) { + throw new AxisFault(resenvelope.getBody().getFault().g= etException()); + } + } else { + throw new AxisFault("Blocking invocation always expect a r= esponse"); } + response.getTransportOut().getSender().cleanUp(); return response; } catch (OMException e) { throw AxisFault.makeFault(e); @@ -181,27 +184,8 @@ final ConfigurationContext syscontext =3D serviceContext.getEn= gineContext(); =20 AxisEngine engine =3D new AxisEngine(syscontext); - - if (senderTransport =3D=3D null) { - senderTransport =3D inferTransport(to); - } - if(listenerTransport =3D=3D null){ - listenerTransport =3D senderTransport; - } - - - if(msgctx.getTransportIn() =3D=3D null){ - final TransportInDescription transportIn =3D - syscontext.getEngineConfig().getTransportIn(new QName(= senderTransport)); - msgctx.setTransportIn(transportIn); - } - if(msgctx.getTransportOut() =3D=3D null){ - final TransportOutDescription transportOut =3D - syscontext.getEngineConfig().getTransportOut(new QName= (listenerTransport)); - msgctx.setTransportOut(transportOut); - } - - + //TODO + checkTransport(msgctx); =20 if (useSeparateListener) { String messageID =3D String.valueOf(System.currentTimeMill= is()); @@ -209,10 +193,11 @@ axisop.setMessageReciever(callbackReceiver); callbackReceiver.addCallback(messageID, callback); msgctx.setReplyTo( - ListenerManager.replyToEPR( + ListenerManager.replyToEPR( serviceContext.getServiceConfig().getName().getLoc= alPart() + "/" - + axisop.getName().getLocalPart(),listenerTran= sport)); + + axisop.getName().getLocalPart(), + listenerTransport)); =20 } msgctx.setOperationContext(axisop.findOperationContext(msgctx,= serviceContext, false)); @@ -237,12 +222,20 @@ response.setOperationContext(msgctx.getOperati= onContext()); response.setServiceContext(msgctx.getServiceCo= ntext()); =20 - HTTPTransportReceiver receiver =3D new HTTPTra= nsportReceiver(); - receiver.invoke(response, syscontext); - SOAPEnvelope resenvelope =3D response.getEnvel= ope(); - AsyncResult asyncResult =3D new AsyncResult(); - asyncResult.setResult(resenvelope); - callback.onComplete(asyncResult); + SOAPEnvelope resenvelope =3D checkReturnChanne= l(response); + if (resenvelope !=3D null) { + response.setEnvelope(resenvelope); + AxisEngine engine =3D + new AxisEngine(serviceContext.getEngin= eContext()); + engine.receive(response); + + resenvelope =3D response.getEnvelope(); + AsyncResult asyncResult =3D new AsyncResul= t(); + asyncResult.setResult(resenvelope); + callback.onComplete(asyncResult); + } else { + throw new AxisFault("Blocking invocation a= lways expect a response"); + } } catch (AxisFault e) { callback.reportError(e); } @@ -251,6 +244,7 @@ }; (new Thread(newThread)).start(); } + msgctx.getTransportOut().getSender().cleanUp(); =20 } catch (OMException e) { throw AxisFault.makeFault(e); @@ -288,10 +282,13 @@ String listenerTransport, boolean useSeparateListener) throws AxisFault { + this.senderTransport =3D senderTransport; + this.listenerTransport =3D listenerTransport; =20 if (useSeparateListener || (senderTransport.equals(listenerTransport) - && Constants.TRANSPORT_HTTP.equals(senderTransport))) { + && (Constants.TRANSPORT_HTTP.equals(senderTransport) + || Constants.TRANSPORT_TCP.equals(senderTransport)))) { =20 this.useSeparateListener =3D useSeparateListener; } else { @@ -299,8 +296,67 @@ } =20 if (useSeparateListener =3D=3D true) { - ListenerManager.makeSureStarted(listenerTransport,serviceConte= xt.getEngineContext()); + ListenerManager.makeSureStarted(listenerTransport, serviceCont= ext.getEngineContext()); + } + } + + private SOAPEnvelope checkReturnChannel(MessageContext response) throw= s AxisFault { + SOAPEnvelope resenvelope =3D null; + try { + //TODO Fix this we support only the HTTP Sync cases, so we har= dcode this + if (Constants.TRANSPORT_HTTP.equals(listenerTransport)) { + HTTPTransportReceiver receiver =3D new HTTPTransportReceiv= er(); + resenvelope =3D + receiver.checkForResponse(response, serviceContext.get= EngineContext()); + } else if (Constants.TRANSPORT_TCP.equals(listenerTransport)) { + Reader in =3D (Reader) response.getProperty(MessageContext= .TRANSPORT_READER); + if(in !=3D null){ + XMLStreamReader xmlreader =3D XMLInputFactory.newInsta= nce().createXMLStreamReader(in); + StAXBuilder builder =3D new StAXSOAPModelBuilder(xmlre= ader); + resenvelope =3D (SOAPEnvelope) builder.getDocumentElem= ent(); + }else{ + throw new AxisFault("Sync invocation expect a proeprty= "+ MessageContext.TRANSPORT_READER + " set "); + } + } + } catch (XMLStreamException e) { + throw new AxisFault(e); + } catch (FactoryConfigurationError e) { + throw new AxisFault(e); + } + return resenvelope; + } + + private void checkTransport(MessageContext msgctx) throws AxisFault { + if (senderTransport =3D=3D null) { + senderTransport =3D inferTransport(to); + } + if (listenerTransport =3D=3D null) { + listenerTransport =3D senderTransport; + } + + if (msgctx.getTransportIn() =3D=3D null) { + final TransportInDescription transportIn =3D + serviceContext.getEngineContext().getEngineConfig().getTra= nsportIn( + new QName(senderTransport)); + if (transportIn !=3D null) { + msgctx.setTransportIn(transportIn); + } else { + throw new AxisFault("Unknown transport " + listenerTranspo= rt); + } + + } + if (msgctx.getTransportOut() =3D=3D null) { + final TransportOutDescription transportOut =3D + serviceContext.getEngineContext().getEngineConfig().getTra= nsportOut( + new QName(listenerTransport)); + if (transportOut !=3D null) { + msgctx.setTransportOut(transportOut); + } else { + throw new AxisFault("Unknown transport " + senderTransport= ); + } + } + } =20 } Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/clie= ntapi/Stub.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/clientapi/Stub.java?rev=3D171100&r1=3D171099&r2=3D1711= 00&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= Stub.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/clientapi/= Stub.java Fri May 20 04:11:07 2005 @@ -16,21 +16,16 @@ =20 package org.apache.axis.clientapi; =20 -import javax.xml.namespace.QName; - -import org.apache.axis.context.ConfigurationContextFactory; +import org.apache.axis.addressing.EndpointReference; import org.apache.axis.context.ConfigurationContext; -import org.apache.axis.context.ServiceContext; import org.apache.axis.context.MessageContext; +import org.apache.axis.context.ServiceContext; import org.apache.axis.deployment.DeploymentException; -import org.apache.axis.engine.AxisFault; import org.apache.axis.description.ServiceDescription; -import org.apache.axis.description.OperationDescription; -import org.apache.axis.addressing.EndpointReference; -import org.apache.axis.addressing.AddressingConstants; -import org.apache.axis.soap.SOAPEnvelope; +import org.apache.axis.engine.AxisFault; import org.apache.axis.om.OMAbstractFactory; import org.apache.axis.om.OMElement; +import org.apache.axis.soap.SOAPEnvelope; =20 /** * @author chathura@opensource.lk Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/TransportSender.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/TransportSender.java?rev=3D171100&r1=3D17109= 9&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= TransportSender.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= TransportSender.java Fri May 20 04:11:07 2005 @@ -15,10 +15,12 @@ */ package org.apache.axis.transport; =20 +import org.apache.axis.engine.AxisFault; import org.apache.axis.engine.Handler; =20 /** * Interface TransportSender */ public interface TransportSender extends Handler { + public void cleanUp() throws AxisFault; } Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/http/HTTPTransportReceiver.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/http/HTTPTransportReceiver.java?rev=3D171100= &r1=3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= http/HTTPTransportReceiver.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= http/HTTPTransportReceiver.java Fri May 20 04:11:07 2005 @@ -88,7 +88,9 @@ * @param msgContext * @throws AxisFault */ - public void invoke(MessageContext msgContext,ConfigurationContext engi= neContext) throws AxisFault{ + public SOAPEnvelope checkForResponse(MessageContext msgContext,Configu= rationContext engineContext) throws AxisFault{ + SOAPEnvelope soapEnvelope =3D null; + =20 Reader in =3D (Reader) msgContext.getProperty(MessageContext.TRANS= PORT_READER); if (in !=3D null) { boolean serverSide =3D msgContext.isServerSide(); @@ -112,20 +114,19 @@ msgContext.setProperty( MessageContext.TRANSPORT_SUCCEED, HTTPConstants.RESPONSE_ACK_CODE_VAL); - return; + return soapEnvelope; } =20 // TODO take care of other HTTP Headers } - AxisEngine axisEngine =3D new AxisEngine(engineContext); + try { XMLStreamReader xmlreader =3D XMLInputFactory.newInstance(= )=2EcreateXMLStreamReader(in); StAXBuilder builder =3D new StAXSOAPModelBuilder(xmlreader= ); - msgContext.setEnvelope((SOAPEnvelope) builder.getDocumentE= lement()); + return (SOAPEnvelope) builder.getDocumentElement(); } catch (Exception e) { throw new AxisFault(e.getMessage(), e); } - axisEngine.receive(msgContext); } else { throw new AxisFault("Input reader not found"); } Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/http/HTTPTransportSender.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/http/HTTPTransportSender.java?rev=3D171100&r= 1=3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= http/HTTPTransportSender.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= http/HTTPTransportSender.java Fri May 20 04:11:07 2005 @@ -37,28 +37,27 @@ */ private Socket socket; private ByteArrayOutputStream outputStream; -// /** -// * Method obtainOutputStream -// * -// * @param msgContext -// * @return -// * @throws AxisFault -// */ -// protected Writer obtainWriter(MessageContext msgContext) throws Axis= Fault { -// if (!msgContext.isServerSide()) { -// //create a new byte buffer output stream -// outputStream =3D new ByteArrayOutputStream(); -// out =3D new OutputStreamWriter(outputStream); -// } else { -// out =3D (Writer) msgContext.getProperty(MessageContext.TRANS= PORT_WRITER); -// } -// if (out =3D=3D null) { -// throw new AxisFault("can not find the suffient information t= o find endpoint"); -// } else { -// return out; -// } -// } - + // /** + // * Method obtainOutputStream + // * + // * @param msgContext + // * @return + // * @throws AxisFault + // */ + // protected Writer obtainWriter(MessageContext msgContext) throws = AxisFault { + // if (!msgContext.isServerSide()) { + // //create a new byte buffer output stream + // outputStream =3D new ByteArrayOutputStream(); + // out =3D new OutputStreamWriter(outputStream); + // } else { + // out =3D (Writer) msgContext.getProperty(MessageContext.T= RANSPORT_WRITER); + // } + // if (out =3D=3D null) { + // throw new AxisFault("can not find the suffient informati= on to find endpoint"); + // } else { + // return out; + // } + // } =20 /** * Method writeTransportHeaders @@ -95,42 +94,40 @@ =20 public void finalizeSendWithToAddress(MessageContext msgContext, Write= r writer) throws AxisFault { - EndpointReference toURL =3D msgContext.getTo(); - if (toURL !=3D null) { - try { - URL url =3D new URL(toURL.getAddress()); - SocketAddress add =3D - new InetSocketAddress( - url.getHost(), - url.getPort() =3D=3D -1 ? 80 : url.getPort()); - socket =3D new Socket(); - socket.connect(add); - OutputStream outS =3D socket.getOutputStream(); - byte[] bytes =3D outputStream.toByteArray(); - - Writer realOut =3D new OutputStreamWriter(outS); - //write header to the out put stream - writeTransportHeaders(realOut, url, msgContext, bytes.= length); - realOut.flush(); - //write the content to the real output stream - outS.write(bytes); - outS.flush(); - - msgContext.setProperty( - MessageContext.TRANSPORT_READER, - new InputStreamReader(socket.getInputStream())); - msgContext.setProperty(HTTPConstants.SOCKET, socket); - - socket.shutdownOutput(); - - } catch (MalformedURLException e) { - throw new AxisFault(e.getMessage(), e); - } catch (IOException e) { - throw new AxisFault(e.getMessage(), e); - } - } else { - throw new AxisFault("to EPR must be specified"); + EndpointReference toURL =3D msgContext.getTo(); + if (toURL !=3D null) { + try { + URL url =3D new URL(toURL.getAddress()); + SocketAddress add =3D + new InetSocketAddress(url.getHost(), url.getPort() =3D= =3D -1 ? 80 : url.getPort()); + socket =3D new Socket(); + socket.connect(add); + OutputStream outS =3D socket.getOutputStream(); + byte[] bytes =3D outputStream.toByteArray(); + + Writer realOut =3D new OutputStreamWriter(outS); + //write header to the out put stream + writeTransportHeaders(realOut, url, msgContext, bytes.leng= th); + realOut.flush(); + //write the content to the real output stream + outS.write(bytes); + outS.flush(); + + msgContext.setProperty( + MessageContext.TRANSPORT_READER, + new InputStreamReader(socket.getInputStream())); + msgContext.setProperty(HTTPConstants.SOCKET, socket); + + socket.shutdownOutput(); + + } catch (MalformedURLException e) { + throw new AxisFault(e.getMessage(), e); + } catch (IOException e) { + throw new AxisFault(e.getMessage(), e); } + } else { + throw new AxisFault("to EPR must be specified"); + } } =20 protected Writer openTheConnection(EndpointReference epr) { @@ -140,17 +137,33 @@ =20 public void startSendWithOutputStreamFromIncomingConnection( MessageContext msgContext, - Writer writer)throws AxisFault { - try { - writer.write(new String(HTTPConstants.HTTP).toCharArray())= ; - writer.write(new String(HTTPConstants.OK).toCharArray()); - writer.write("\n\n".toCharArray()); - } catch (IOException e) { - throw new AxisFault(e); - } + Writer writer) + throws AxisFault { + try { + writer.write(new String(HTTPConstants.HTTP).toCharArray()); + writer.write(new String(HTTPConstants.OK).toCharArray()); + writer.write("\n\n".toCharArray()); + } catch (IOException e) { + throw new AxisFault(e); + } } =20 public void startSendWithToAddress(MessageContext msgContext, Writer w= riter) { + } + + /* (non-Javadoc) + * @see org.apache.axis.transport.TransportSender#cleanUp() + */ + public void cleanUp() throws AxisFault { + try { + if (socket !=3D null) { + socket.close(); + socket =3D null; + } + + } catch (IOException e) { + } + } =20 } Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/http/SimpleHTTPServer.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/http/SimpleHTTPServer.java?rev=3D171100&r1= =3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 Fri May 20 04:11:07 2005 @@ -22,7 +22,9 @@ import org.apache.axis.context.ConfigurationContextFactory; import org.apache.axis.context.MessageContext; import org.apache.axis.description.TransportOutDescription; +import org.apache.axis.engine.AxisEngine; import org.apache.axis.engine.AxisFault; +import org.apache.axis.soap.SOAPEnvelope; import org.apache.axis.transport.TransportListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -146,7 +148,10 @@ msgContext.setProperty(MessageContext.TRANSPORT_WR= ITER, out); msgContext.setProperty(MessageContext.TRANSPORT_RE= ADER, in); HTTPTransportReceiver reciver =3D new HTTPTranspor= tReceiver(); - reciver.invoke(msgContext, configurationContext); + msgContext.setEnvelope(reciver.checkForResponse(ms= gContext, configurationContext)); + =20 + AxisEngine engine =3D new AxisEngine(configuration= Context); + engine.receive(msgContext); =20 if (msgContext.getReplyTo() !=3D null && !AddressingConstants.EPR_ANONYMOUS_URL.equa= ls( Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/mail/MailConstants.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/mail/MailConstants.java?rev=3D171100&r1=3D17= 1099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/MailConstants.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/MailConstants.java Fri May 20 04:11:07 2005 @@ -22,4 +22,13 @@ public final static String POP3_PASSWORD =3D "transport.mail.pop3.pass= word"; =20 public final static String HEADER_SOAP_ACTION =3D "transport.mail.soap= action"; + =20 + public final static String CONTENT_TYPE =3D "transport.mail.contenttyp= e"; + =20 + public final static String CONTENT_LOCAION =3D "transport.mail.content= location"; + =20 + =20 + public final static String HOST =3D "host"; + public final static String USER =3D "user"; + public final static String PASSWORD =3D "password"; } Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/mail/MailTransportSender.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/mail/MailTransportSender.java?rev=3D171100&r= 1=3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 Fri May 20 04:11:07 2005 @@ -16,108 +16,103 @@ =20 package org.apache.axis.transport.mail; =20 +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.io.Writer; +import java.util.Properties; + +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.PasswordAuthentication; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.MimeMessage; + import org.apache.axis.addressing.EndpointReference; import org.apache.axis.context.MessageContext; import org.apache.axis.engine.AxisFault; import org.apache.axis.transport.AbstractTransportSender; =20 -import java.io.Writer; -import java.net.Socket; - public class MailTransportSender extends AbstractTransportSender { - protected Writer out; + private String host; + private String user; + private String password; + private String smtpPort =3D "25"; =20 - private Socket socket; + private PipedInputStream in; =20 public MailTransportSender() { =20 } =20 -=20 - - protected Writer obtainOutputStream(MessageContext msgContext, - EndpointReference epr) throws AxisFault { + public void finalizeSendWithToAddress(MessageContext msgContext, Write= r writer) + throws AxisFault { throw new UnsupportedOperationException(); + } =20 - =20 - protected void startSending(MessageContext msgContext) throws AxisFaul= t { - try { - Writer writer =3D (Writer) msgContext - .getProperty(MessageContext.TRANSPORT_WRITER); - startSending(msgContext, writer); - } catch (Exception e) { - throw new AxisFault(e.getMessage()); - } + public void startSendWithToAddress(MessageContext msgContext, Writer w= riter) throws AxisFault { + throw new UnsupportedOperationException(); + } =20 - protected void startSending(MessageContext msgContext, Writer writer) = throws AxisFault { + protected Writer openTheConnection(EndpointReference epr) throws AxisF= ault { + try { - writer.write("Content-Type: text/plain; charset=3Dus-ascii\n"); - writer.write("Content-Transfer-Encoding: 7bit\n"); - writer - .write("Accept: application/soap+xml, application/dime= , multipart/related, text\n"); - //writer.write("MIME-Version: 1.0\n"); - writer.write("User-Agent: Axis2 M1\n"); - writer.write("Cache-Control: no-cache\n"); - writer.write("Pragma: no-cache\n"); - writer.write("Subject: Re:" - + msgContext.getProperty(MailConstants.SUBJECT) + "\n\= n"); - } catch (Exception e) { - throw new AxisFault(e.getMessage()); + + in =3D new PipedInputStream(); + PipedOutputStream out =3D new PipedOutputStream(in); + + return new OutputStreamWriter(out); + } catch (IOException e) { + throw new AxisFault(e); } - } - =20 - /* (non-Javadoc) - * @see org.apache.axis.transport.AbstractTransportSender#finalizeSend= WithOutputStreamFromIncomingConnection(org.apache.axis.context.MessageConte= xt, java.io.Writer) - */ - public void finalizeSendWithOutputStreamFromIncomingConnection( - MessageContext msgContext, - Writer writer) - throws AxisFault { - throw new UnsupportedOperationException(); =20 } =20 - /* (non-Javadoc) - * @see org.apache.axis.transport.AbstractTransportSender#finalizeSend= WithToAddress(org.apache.axis.context.MessageContext, org.apache.axis.addre= ssing.EndpointReference, java.io.Writer) - */ - public void finalizeSendWithToAddress( + //Output Stream based cases are not supported=20 + public void startSendWithOutputStreamFromIncomingConnection( MessageContext msgContext, Writer writer) throws AxisFault { - throw new UnsupportedOperationException(); - - } - - /* (non-Javadoc) - * @see org.apache.axis.transport.AbstractTransportSender#openTheConne= ction(org.apache.axis.addressing.EndpointReference) - */ - protected Writer openTheConnection(EndpointReference epr) throws AxisF= ault { throw new UnsupportedOperationException(); - } =20 - /* (non-Javadoc) - * @see org.apache.axis.transport.AbstractTransportSender#startSendWit= hOutputStreamFromIncomingConnection(org.apache.axis.context.MessageContext,= java.io.Writer) - */ - public void startSendWithOutputStreamFromIncomingConnection( + } + public void finalizeSendWithOutputStreamFromIncomingConnection( MessageContext msgContext, Writer writer) throws AxisFault { - throw new UnsupportedOperationException(); - + try { + PasswordAuthentication authentication =3D new PasswordAuthenti= cation(user, password); + Properties props =3D new Properties(); + props.put("mail.user", user); + props.put("mail.host", host); + props.put("mail.store.protocol", "pop3"); + props.put("mail.transport.protocol", "smtp"); + props.put("mail.smtp.port", smtpPort); + Session session =3D Session.getInstance(props); + + MimeMessage msg =3D new MimeMessage(session, in); + String action =3D msgContext.getWSAAction(); + if (action !=3D null) { + msg.setHeader("transport.mail.soapaction", action); + } + + msg.addRecipients(Message.RecipientType.TO, msgContext.getTo()= .getAddress()); + msg.setSubject(msgContext.getTo().getAddress()); + Transport.send(msg); + } catch (MessagingException e) { + throw new AxisFault(e); + } } - /* (non-Javadoc) - * @see org.apache.axis.transport.AbstractTransportSender#startSendWit= hToAddress(org.apache.axis.context.MessageContext, org.apache.axis.addressi= ng.EndpointReference, java.io.Writer) + * @see org.apache.axis.transport.TransportSender#cleanUp() */ - public void startSendWithToAddress( - MessageContext msgContext, - Writer writer) - throws AxisFault { - throw new UnsupportedOperationException(); + public void cleanUp() throws AxisFault { + // TODO Auto-generated method stub =20 } =20 } - Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/mail/MailWorker.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/mail/MailWorker.java?rev=3D171100&r1=3D17109= 9&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/MailWorker.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/MailWorker.java Fri May 20 04:11:07 2005 @@ -16,6 +16,17 @@ =20 package org.apache.axis.transport.mail; =20 +import java.io.ByteArrayInputStream; +import java.util.Properties; + +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + import org.apache.axis.Constants; import org.apache.axis.addressing.AddressingConstants; import org.apache.axis.addressing.EndpointReference; @@ -28,41 +39,17 @@ import org.apache.axis.soap.impl.llom.builder.StAXSOAPModelBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.net.smtp.SMTPClient; -import org.apache.commons.net.smtp.SMTPReply; - -import javax.mail.Message; -import javax.mail.Session; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; -import java.io.ByteArrayInputStream; -import java.io.Writer; -import java.util.Properties; =20 public class MailWorker implements Runnable { protected static Log log =3D LogFactory.getLog(MailWorker.class.getNam= e()); =20 private String contentType =3D "text/xml"; =20 - // Server - private SimpleMailListner server; - - private SMTPClient client =3D null; - private ConfigurationContext reg =3D null; =20 // Current message private MimeMessage mimeMessage; =20 - //Processed responce CT 08-Feb-2005 - private MimeMessage outputMimeMessage; - - // Axis specific constants - private static String transportName =3D "mail"; - private Properties prop =3D new Properties(); =20 private Session session =3D Session.getDefaultInstance(prop, null); @@ -73,9 +60,7 @@ * @param server * @param mimeMessage */ - public MailWorker(SimpleMailListner server, MimeMessage mimeMessage, - ConfigurationContext reg) { - this.server =3D server; + public MailWorker(MimeMessage mimeMessage, ConfigurationContext reg) { this.mimeMessage =3D mimeMessage; this.reg =3D reg; } @@ -85,83 +70,46 @@ */ public void run() { // create an Axis server - AxisEngine engine =3D SimpleMailListner.getAxisEngine(); + AxisEngine engine =3D new AxisEngine(reg); MessageContext msgContext =3D null; // create and initialize a message context try { - msgContext =3D new MessageContext(null, - reg.getEngineConfig().getTransportIn(new QName(Constan= ts.TRANSPORT_HTTP)), - reg.getEngineConfig().getTransportOut(new QName(Consta= nts.TRANSPORT_HTTP)),reg); + msgContext =3D + new MessageContext( + null, + reg.getEngineConfig().getTransportIn(new QName(Constan= ts.TRANSPORT_MAIL)), + reg.getEngineConfig().getTransportOut(new QName(Consta= nts.TRANSPORT_MAIL)), + reg); msgContext.setServerSide(true); - } catch (AxisFault af) { - log.error("Error occured while creating the message context", = af); - } =20 - Message requestMsg =3D null; + msgContext.setProperty(MailConstants.CONTENT_TYPE, mimeMessage= .getContentType()); + msgContext.setWSAAction(getMailHeader(MailConstants.HEADER_SOA= P_ACTION)); =20 - // buffers for the headers we care about - StringBuffer soapAction =3D new StringBuffer(); - StringBuffer fileName =3D new StringBuffer(); - StringBuffer contentType =3D new StringBuffer(); - StringBuffer contentLocation =3D new StringBuffer(); - - Message responseMsg =3D null; - - // prepare request (do as much as possible while waiting for the - // next connection). -=20 - //msgContext.setResponseMessage(null); - //msgContext.reset(); - // msgContext.setTransport(new AxisTransport(transportName)); Ther= e is - // no way to set the transport. CT 07-Feb-2005. + String to =3D mimeMessage.getSubject(); + if (to !=3D null) { + msgContext.setTo(new EndpointReference(AddressingConstants= .WSA_TO, to)); + } =20 - responseMsg =3D null; + String replyTo =3D ((InternetAddress) mimeMessage.getReplyTo()= [0]).getAddress(); + if (replyTo !=3D null) { + msgContext.setReplyTo( + new EndpointReference(AddressingConstants.WSA_REPLY_TO= , replyTo)); + } =20 - try { - // parse all headers into hashtable - parseHeaders(mimeMessage, contentType, contentLocation, - soapAction); - - String soapActionString =3D soapAction.toString(); - if (soapActionString !=3D null) { - //msgContext.setUseSOAPAction(true); Not present CT - // 07-Feb-2005 - msgContext.setWSAAction( - soapActionString); + String sendFrom =3D ((InternetAddress) mimeMessage.getAllRecip= ients()[0]).getAddress(); + if (sendFrom !=3D null) { + msgContext.setFrom(new EndpointReference(AddressingConstan= ts.WSA_FROM, sendFrom)); } =20 - System.out - .println("This is the data that is to be processed \n= " - + mimeMessage.getContent().toString() + "\n"); - - ByteArrayInputStream bais =3D new ByteArrayInputStream(mimeMes= sage.getContent().toString().getBytes()); - XMLStreamReader reader =3D XMLInputFactory.newInstance() - .createXMLStreamReader(bais); + // add the SOAPEnvelope + ByteArrayInputStream bais =3D + new ByteArrayInputStream(mimeMessage.getContent().toString= ().getBytes()); + XMLStreamReader reader =3D XMLInputFactory.newInstance().creat= eXMLStreamReader(bais); StAXBuilder builder =3D new StAXSOAPModelBuilder(reader); - - msgContext.setEnvelope((SOAPEnvelope) builder - .getDocumentElement()); - - //A writer is created and sent to the engine so that the engine - // can write straight to the writer - String replyTo =3D ((InternetAddress) mimeMessage.getReplyTo()= [0]) - .getAddress(); - String sendFrom =3D ((InternetAddress) mimeMessage - .getAllRecipients()[0]).getAddress(); - String subject =3D mimeMessage.getSubject(); - msgContext.setProperty(MailConstants.FROM_ADDRESS, sendFrom); - msgContext.setProperty(MailConstants.TO_ADDRESS, replyTo); - msgContext.setProperty(MailConstants.SUBJECT, subject); - Writer wr =3D getMailWriter(server.getHost(), msgContext); - - msgContext.setProperty(MessageContext.TRANSPORT_WRITER, wr); - msgContext.setTo(new EndpointReference(AddressingConstants.WSA= _TO, replyTo)); + msgContext.setEnvelope((SOAPEnvelope) builder.getDocumentEleme= nt()); =20 // invoke the Axis engine engine.receive(msgContext); - - sendMessage(wr); - } catch (Exception e) { e.printStackTrace(); AxisFault af; @@ -169,8 +117,7 @@ af =3D (AxisFault) e; //log.debug(Messages.getMessage("serverFault00"), af); // CT 07-Feb-2005 - log.debug("Error occured while trying to process the mail.= ", - af); + log.debug("Error occured while trying to process the mail.= ", af); } else { af =3D AxisFault.makeFault(e); } @@ -185,71 +132,18 @@ */ } =20 - private Writer getMailWriter(String smtpHost, MessageContext msgContex= t) - throws Exception { - client =3D new SMTPClient(); - client.connect(smtpHost); - - // After connection attempt, you should check the reply code to ve= rify - // success. - int reply =3D client.getReplyCode(); - if (!SMTPReply.isPositiveCompletion(reply)) { - client.disconnect(); - AxisFault fault =3D new AxisFault("SMTP" - + "( SMTP server refused connection )"); //Issue #2 CT - // 07-Feb-2005. - throw fault; - } - - client.login(smtpHost); - reply =3D client.getReplyCode(); - if (!SMTPReply.isPositiveCompletion(reply)) { - client.disconnect(); - AxisFault fault =3D new AxisFault("SMTP" - + "( SMTP server refused connection )"); - throw fault; + private String getMailHeader(String headerName) throws AxisFault { + try { + String values[] =3D mimeMessage.getHeader(headerName); + if (values !=3D null) { + return values[0]; + } else { + return null; + } + } catch (MessagingException e) { + throw new AxisFault(e); } - client.setSender((String) msgContext - .getProperty(MailConstants.FROM_ADDRESS)); - client.addRecipient((String) msgContext - .getProperty(MailConstants.TO_ADDRESS)); - Writer writer =3D client.sendMessageData(); =20 - return writer; } =20 - private void sendMessage(Writer writer) throws Exception { - writer.flush(); - writer.close(); - - System.out.print(client.getReplyString()); - if (!client.completePendingCommand()) { - System.out.print(client.getReplyString()); - AxisFault fault =3D new AxisFault("SMTP" + "( Failed to send e= mail )"); - throw fault; - } - client.logout(); - client.disconnect(); - } - - /** - * Read all mime headers, returning the value of Content-Length and - * SOAPAction. - * - * @param mimeMessage InputStream to read from - * @param contentType The content type. - * @param contentLocation The content location - * @param soapAction StringBuffer to return the soapAction into - */ - private void parseHeaders(MimeMessage mimeMessage, - StringBuffer contentType, StringBuffer conte= ntLocation, - StringBuffer soapAction) throws Exception { - contentType.append(mimeMessage.getContentType()); - contentLocation.append(mimeMessage.getContentID()); - String values[] =3D mimeMessage - .getHeader(MailConstants.HEADER_SOAP_ACTION); - if (values !=3D null) - soapAction.append(values[0]); - System.out.println("Calling soap action " + soapAction); - } } Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transpo= rt/mail/SimpleMailListener.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/mail/SimpleMailListener.java?rev=3D171100&vi= ew=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/SimpleMailListener.java (added) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= mail/SimpleMailListener.java Fri May 20 04:11:07 2005 @@ -0,0 +1,301 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * 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 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * 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.transport.mail; + +import java.util.Properties; + +import javax.mail.Flags; +import javax.mail.Folder; +import javax.mail.Message; +import javax.mail.PasswordAuthentication; +import javax.mail.Session; +import javax.mail.Store; +import javax.mail.internet.MimeMessage; + +import org.apache.axis.context.ConfigurationContext; +import org.apache.axis.context.ConfigurationContextFactory; +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 S= OAP + * requests via Apache's xml-axis. This is not intended for production use= . Its + * intended uses are for demos, debugging, and performance profiling. + *=20 + * @author Davanum Srinivas + * @author Rob Jellinghaus (robj@unrealities.com) + *=20 + * @author Chamil Thanthrimudalige Changes done to make= the + * Class work inside Axis 2. + */ + +/* + * TODO ISSUES -- 1. Message.getMessage -- All messages are hardcoded in t= he + * code till a replacement or a working verion of this is put into Axis 2.= When + * internationalization work is done this can be fixed. CT 15-Feb-2005 + * =20 + */ + +public class SimpleMailListener implements Runnable { + + protected static Log log =3D LogFactory.getLog(SimpleMailListener.clas= s=2EgetName()); + + private String host; + + private int port; + + private String userid; + + private String password; + + private ConfigurationContext er =3D null; + + public SimpleMailListener(String host, int port, String userid, String= password, String dir) { + this.host =3D host; + this.port =3D port; + this.userid =3D userid; + this.password =3D password; + try { + ConfigurationContextFactory builder =3D new ConfigurationConte= xtFactory(); + er =3D builder.buildEngineContext(dir); + } catch (Exception e) { + e.printStackTrace(); + } + try { + System.out.println("Sleeping for a bit to let the engine start= up."); + Thread.sleep(2000); + } catch (InterruptedException e1) { + log.debug(e1.getMessage(), e1); + } + } + + public SimpleMailListener( + String host, + int port, + String userid, + String password, + ConfigurationContext er) { + this.host =3D host; + this.port =3D port; + this.userid =3D userid; + this.password =3D password; + this.er =3D er; + } + + // Are we doing threads? + private static boolean doThreads =3D true; + + public void setDoThreads(boolean value) { + doThreads =3D value; + } + + public boolean getDoThreads() { + return doThreads; + } + + // are we stopped? + // latch to true if stop() is called + private boolean stopped =3D false; + + /** + * Accept requests from a given TCP port and send them through the Axis + * engine for processing. + */ + public void run() { + // log.info(Message.getMessage("start00", "SimpleMailListner", hos= t + ":" + + // port)); TODO Issue #1 CT 07-Feb-2005. + // Accept and process requests from the socket + if (!stopped) { + String logMessage =3D + "Mail listner is being setup to listen to the address " + + userid + + "@" + + host + + " On port " + + port; + System.out.println(logMessage); + log.info(logMessage); + } + while (!stopped) { + try { + PasswordAuthentication authentication =3D + new PasswordAuthentication(userid, password); + Properties props =3D new Properties(); + props.put("mail.user", userid); + props.put("mail.host", host); + props.put("mail.store.protocol", "pop3"); + props.put("mail.transport.protocol", "smtp"); + Session session =3D Session.getInstance(props); + Store store =3D session.getStore(); + store.connect(); + Folder root =3D store.getDefaultFolder(); + Folder inbox =3D root.getFolder("inbox"); + inbox.open(Folder.READ_WRITE); + Message[] msgs =3D inbox.getMessages(); + int numMessages =3D msgs.length; + if (msgs.length =3D=3D 0) { + System.out.println("No messages in inbox"); + } + for (int i =3D 0; i < msgs.length; i++) { + MimeMessage msg =3D (MimeMessage) msgs[i]; + if (msg !=3D null) { + MailWorker worker =3D new MailWorker(msg, er); + if (doThreads) { + Thread thread =3D new Thread(worker); + thread.setDaemon(true); + thread.start(); + } else { + worker.run(); + } + } + msg.setFlag(Flags.Flag.DELETED, true); + } + inbox.close(true); + store.close(); + } catch (Exception e) { + //log.debug(Messages.getMessage("exception00"), e); TODO I= ssue + // #1 CT 07-Feb-2005. + log.debug("An error occured when running the mail listner.= " + e.getMessage(), e); + System.out.println( + "An error occured when running the mail listner." + e.= getMessage()); + break; + } + try { + pop3.logout(); + pop3.disconnect(); + Thread.sleep(3000); + } catch (Exception e) { + //log.error(Messages.getMessage("exception00"), e); TODO I= ssue + // #1 CT 07-Feb-2005. + log.debug( + "An error occured when trying to disconnect from the S= erver." + e.getMessage(), + e); + System.out.println( + "An error occured when trying to disconnect from the S= erver." + e.getMessage()); + } + } + + log.info("Mail listner has been stoped."); + System.out.println("Mail listner has been stoped."); + //log.info(Messages.getMessage("quit00", "SimpleMailListner")); TO= DO Issue #1 + // CT 07-Feb-2005. + + } + + /** + * POP3 connection + */ + private POP3Client pop3; + + /** + * Obtain the serverSocket that that SimpleMailListner is listening on. + */ + public POP3Client getPOP3() { + return pop3; + } + + /** + * Set the serverSocket this server should listen on. (note : changing= this + * will not affect a running server, but if you stop() and then start(= ) the + * server, the new socket will be used). + */ + public void setPOP3(POP3Client pop3) { + this.pop3 =3D pop3; + } + + //CT 03-Feb-2005 I think it should be POP instead of HTTP + /** + * Start this server. + *=20 + * Spawns a worker thread to listen for HTTP requests. + *=20 + * @param daemon + * a boolean indicating if the thread should be a daemon. + */ + public void start(boolean daemon) throws Exception { + if (doThreads) { + Thread thread =3D new Thread(this); + thread.setDaemon(daemon); + thread.start(); + } else { + run(); + } + } + + /** + * Start this server as a NON-daemon. + */ + public void start() throws Exception { + start(false); + } + + /** + * Stop this server. + *=20 + * This will interrupt any pending accept(). + */ + public void stop() throws Exception { + /* + * Close the server socket cleanly, but avoid fresh accepts while = the + * socket is closing. + */ + stopped =3D true; + //log.info(Messages.getMessage("quit00", "SimpleMailListner")); TO= DO Issue #1 + // CT 07-Feb-2005. + log.info("Quiting the mail listner"); + } + + /** + * Server process. + */ + public static void main(String args[]) { + boolean optDoThreads =3D true; + String optHostName =3D "localhost"; + boolean optUseCustomPort =3D false; + int optCustomPortToUse =3D 0; + String optDir =3D "/home/chamil/temp"; + String optUserName =3D "server"; + String optPassword =3D "server"; + System.out.println("Starting the mail listner"); + // Options object is not used for now. Hard coded values will be u= sed. + // TODO have to meke this a bit more generic. CT 07-Feb-2005. + //Options opts =3D null; + + /* + * try { opts =3D new Options(args); } catch (MalformedURLExceptio= n e) { + * log.error(Messages.getMessage("malformedURLException00"), e); r= eturn; } + */ + try { + doThreads =3D optDoThreads; //(opts.isFlagSet('t') > 0); + String host =3D optHostName; //opts.getHost(); + int port =3D ((optUseCustomPort) ? optCustomPortToUse : 110); + POP3Client pop3 =3D new POP3Client(); + SimpleMailListener sas =3D + new SimpleMailListener(host, port, optUserName, optPasswor= d, optDir); + sas.setPOP3(pop3); + sas.start(); + } catch (Exception e) { + // log.error(Messages.getMessage("exception00"), e); TODO Issu= e #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; + } + + } +} \ No newline at end of file Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/tcp/TCPServer.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/tcp/TCPServer.java?rev=3D171100&r1=3D171099&= r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= tcp/TCPServer.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= tcp/TCPServer.java Fri May 20 04:11:07 2005 @@ -100,11 +100,12 @@ new MessageContext( null, configContext.getEngineConfig().getTransportIn( - new QName(Constants.TRANSPORT_HTTP)), + new QName(Constants.TRANSPORT_TCP)), transportOut, configContext); msgContext.setServerSide(true); - msgContext.setProperty(MessageContext.TRANSPORT_WRITER, ne= w OutputStreamWriter(socket.getOutputStream())); + msgContext.setProperty(MessageContext.TRANSPORT_WRITER, ou= t); + msgContext.setProperty(MessageContext.TRANSPORT_READER, in= ); =20 AxisEngine engine =3D new AxisEngine(configContext); try { @@ -117,12 +118,16 @@ engine.receive(msgContext); } catch (Throwable e) { log.error(e); + e.printStackTrace(); } finally{ try { - socket.close(); - if(!started){ - serversocket.close(); - } + if(socket !=3D null){ + socket.close(); =20 + if(!started){ + serversocket.close(); + } + } + } catch (IOException e1) { log.error(e1); } @@ -150,7 +155,12 @@ * @see org.apache.axis.transport.TransportListener#stop() */ public void stop() throws AxisFault { - started =3D false; + try { + this.serversocket.close(); =20 + started =3D false; + } catch (IOException e) { + throw new AxisFault(e); + } } =20 } Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/tran= sport/tcp/TCPTransportSender.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /src/org/apache/axis/transport/tcp/TCPTransportSender.java?rev=3D171100&r1= =3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= tcp/TCPTransportSender.java (original) +++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/= tcp/TCPTransportSender.java Fri May 20 04:11:07 2005 @@ -64,7 +64,8 @@ public void finalizeSendWithToAddress(MessageContext msgContext, Write= r writer) throws AxisFault { try { - socket.close(); + socket.shutdownOutput(); + msgContext.setProperty(MessageContext.TRANSPORT_READER, new In= putStreamReader(socket.getInputStream())); } catch (IOException e) { throw new AxisFault(e); } @@ -97,6 +98,18 @@ } =20 public void startSendWithToAddress(MessageContext msgContext, Writer w= riter) { + } + + public void cleanUp() throws AxisFault { + try { + if(socket !=3D null){ + socket.close(); + socket =3D null; + } + =20 + } catch (IOException e) { + } + } =20 } Modified: webservices/axis/trunk/java/modules/core/test/org/apache/axis/tra= nsport/SimpleMailListnerTest.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core= /test/org/apache/axis/transport/SimpleMailListnerTest.java?rev=3D171100&r1= =3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/core/test/org/apache/axis/transport= /SimpleMailListnerTest.java (original) +++ webservices/axis/trunk/java/modules/core/test/org/apache/axis/transport= /SimpleMailListnerTest.java Fri May 20 04:11:07 2005 @@ -15,10 +15,11 @@ */ package org.apache.axis.transport; import junit.framework.TestCase; -import org.apache.axis.transport.mail.SimpleMailListner; + +import org.apache.axis.transport.mail.SimpleMailListener; =20 public class SimpleMailListnerTest extends TestCase { - private SimpleMailListner sas; + private SimpleMailListener sas; public SimpleMailListnerTest(String testName) { super(testName); } Modified: webservices/axis/trunk/java/modules/samples/project.xml URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/project.xml?rev=3D171100&r1=3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/project.xml (original) +++ webservices/axis/trunk/java/modules/samples/project.xml Fri May 20 04:1= 1:07 2005 @@ -93,6 +93,22 @@ true + + commons-net + commons-net + 1.3.0 + + true + + + + geronimo-spec + geronimo-spec-javamail + 1.3.1-rc3 + + true + + =20 @@ -107,6 +123,7 @@ **/*Abstract*.java **/*Util*.java **/*InteropStubTest.java + **/*TCPEchoRawXMLTest.java **/*Test.java Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/= engine/EchoRawXMLOnTwoChannelsTest.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/test/org/apache/axis/engine/EchoRawXMLOnTwoChannelsTest.java?rev=3D1711= 00&r1=3D171099&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine= /EchoRawXMLOnTwoChannelsTest.java (original) +++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine= /EchoRawXMLOnTwoChannelsTest.java Fri May 20 04:11:07 2005 @@ -109,27 +109,27 @@ } =20 public void testEchoXMLCompleteASync() throws Exception { - DeploymentEngine deploymentEngine =3D new DeploymentEngine(); - File file =3D new File("target/test-resources/repository-client/mo= dules/addressing.mar"); - //File file =3D new File("modules/samples/target/test-resources/re= pository-client/modules/addressing.mar"); - - assertTrue(file.exists()); - ModuleDescription moduleDesc =3D deploymentEngine.buildModule(file= ); - - ConfigurationContextFactory efac =3D new ConfigurationContextFacto= ry(); - ConfigurationContext sysContext =3D efac.buildClientEngineContext(= null); - new ConfigurationContext(new AxisConfigurationImpl()); - sysContext.getEngineConfig().addMdoule(moduleDesc); - sysContext.getEngineConfig().engageModule(moduleDesc.getName()); +// DeploymentEngine deploymentEngine =3D new DeploymentEngine(); +// File file =3D new File(UtilServer.TESTING_REPOSITORY + "/address= ing.mar"); +// assertTrue(file.exists()); +// ModuleDescription moduleDesc =3D deploymentEngine.buildModule(fi= le); +// +// ConfigurationContextFactory efac =3D new ConfigurationContextFac= tory(); +// ConfigurationContext sysContext =3D efac.buildClientEngineContex= t(null); +// new ConfigurationContext(new AxisConfigurationImpl()); +// sysContext.getEngineConfig().addMdoule(moduleDesc); +// sysContext.getEngineConfig().engageModule(moduleDesc.getName()); ServiceDescription service =3D Utils.createSimpleService( serviceName, org.apache.axis.engine.Echo.class.getName(), operationName); - sysContext.getEngineConfig().addService(service); - Utils.resolvePhases(sysContext.getEngineConfig(), service); - ServiceContext serviceContext =3D sysContext.createServiceContext(= service.getName()); - +// sysContext.getEngineConfig().addService(service); +// Utils.resolvePhases(sysContext.getEngineConfig(), service); +// ServiceContext serviceContext =3D sysContext.createServiceContex= t(service.getName()); + ServiceContext serviceContext =3D UtilServer.createAdressedEnabled= ClientSide(service); + =20 + =20 OMFactory fac =3D OMAbstractFactory.getOMFactory(); =20 OMNamespace omNs =3D fac.createOMNamespace("http://localhost/my", = "my"); Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/eng= ine/TCPEchoRawXMLTest.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/test/org/apache/axis/engine/TCPEchoRawXMLTest.java?rev=3D171100&view=3D= auto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine= /TCPEchoRawXMLTest.java (added) +++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/engine= /TCPEchoRawXMLTest.java Fri May 20 04:11:07 2005 @@ -0,0 +1,154 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + *=20 + * 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 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * 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.engine; + + + +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.MessageContext; +import org.apache.axis.context.ServiceContext; +import org.apache.axis.description.ServiceDescription; +import org.apache.axis.integration.UtilServer; +import org.apache.axis.integration.UtilsTCPServer; +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.SOAPFactory; +import org.apache.axis.transport.http.SimpleHTTPServer; +import org.apache.axis.util.Utils; + +public class TCPEchoRawXMLTest extends TestCase { + private EndpointReference targetEPR =3D + new EndpointReference(AddressingConstants.WSA_TO, + "http://127.0.0.1:" + + (UtilServer.TESTING_PORT+1) + + "/axis/services/EchoXMLService/echoOMElement"); + private QName serviceName =3D new QName("EchoXMLService"); + private QName operationName =3D new QName("echoOMElement"); + private QName transportName =3D new QName("http://localhost/my", "Null= Transport"); + + private MessageContext mc; + private SimpleHTTPServer sas; + private ServiceDescription service; + private ServiceContext serviceContext; + =20 + private boolean finish =3D false; + + public TCPEchoRawXMLTest() { + super(TCPEchoRawXMLTest.class.getName()); + } + + public TCPEchoRawXMLTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + UtilsTCPServer.start(); + =20 + =20 + //create and deploy the service + service =3D + Utils.createSimpleService(serviceName, + org.apache.axis.engine.Echo.class.getName(), + operationName); + UtilsTCPServer.deployService(service); + =20 + ServiceDescription service =3D + Utils.createSimpleService( + serviceName, + org.apache.axis.engine.Echo.class.getName(), + operationName); + serviceContext =3D UtilServer.createAdressedEnabledClientSi= de(service); + } + + protected void tearDown() throws Exception { + UtilsTCPServer.stop(); + } + + private OMElement createEnvelope() { + OMFactory fac =3D OMAbstractFactory.getOMFactory(); + OMNamespace omNs =3D fac.createOMNamespace("http://localhost/my", = "my"); + OMElement method =3D fac.createOMElement("echoOMElement", omNs); + OMElement value =3D fac.createOMElement("myValue", omNs); + value.addChild(fac.createText(value, "Isaac Assimov, the foundatio= n Sega")); + method.addChild(value); + =20 + return method; + } + + public void testEchoXMLASync() throws Exception { + OMElement payload =3D createEnvelope(); + + org.apache.axis.clientapi.Call call =3D new org.apache.axis.client= api.Call(); + + call.setTo(targetEPR); + call.setTransportInfo(Constants.TRANSPORT_TCP, Constants.TRANSPORT= _TCP, false); + + Callback callback =3D new Callback() { + public void onComplete(AsyncResult result) { + try { + result.getResponseEnvelope().serializeWithCache(XMLOut= putFactory.newInstance().createXMLStreamWriter(System.out)); + } catch (XMLStreamException e) { + reportError(e); + } finally { + finish =3D true; + } + } + + public void reportError(Exception e) { + e.printStackTrace(); + finish =3D true; + } + }; + + call.invokeNonBlocking(operationName.getLocalPart(), payload, call= back); + int index =3D 0; + while (!finish) { + Thread.sleep(1000); + index++; + if(index > 10 ){ + throw new AxisFault("Server is shutdown as the Async respo= nse take too longs time"); + } + } + } + + public void testEchoXMLSync() throws Exception { + SOAPFactory fac =3D OMAbstractFactory.getSOAP11Factory(); + + OMElement payload =3D createEnvelope(); + + org.apache.axis.clientapi.Call call =3D new org.apache.axis.client= api.Call(); + + call.setTo(targetEPR); + call.setTransportInfo(Constants.TRANSPORT_TCP, Constants.TRANSPORT= _TCP, false); + + OMElement result =3D + (OMElement) call.invokeBlocking(operationName.getLocalPart= (), payload); + result.serializeWithCache(XMLOutputFactory.newInstance().createXML= StreamWriter(System.out)); + } +} Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/= integration/UtilServer.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/test/org/apache/axis/integration/UtilServer.java?rev=3D171100&r1=3D1710= 99&r2=3D171100&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/integr= ation/UtilServer.java (original) +++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/integr= ation/UtilServer.java Fri May 20 04:11:07 2005 @@ -13,48 +13,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -=20 + package org.apache.axis.integration; =20 +import java.io.File; +import java.net.ServerSocket; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + import org.apache.axis.context.ConfigurationContext; import org.apache.axis.context.ConfigurationContextFactory; import org.apache.axis.context.ServiceContext; +import org.apache.axis.deployment.DeploymentEngine; +import org.apache.axis.description.ModuleDescription; import org.apache.axis.description.ServiceDescription; -import org.apache.axis.engine.AxisConfiguration; +import org.apache.axis.engine.AxisConfigurationImpl; import org.apache.axis.engine.AxisFault; import org.apache.axis.transport.http.SimpleHTTPServer; import org.apache.axis.util.Utils; =20 -import javax.xml.namespace.QName; -import java.io.File; -import java.net.ServerSocket; - public class UtilServer { private static int count =3D 0; private static SimpleHTTPServer reciver; public static final int TESTING_PORT =3D 5555; public static final String FAILURE_MESSAGE =3D "Intentional Faliure"; + public static final String TESTING_REPOSITORY =3D "target/test-resourc= es/samples"; + //public static final String TESTING_REPOSITORY =3D "modules/samples/t= arget/test-resources/samples"; =20 - - - public static synchronized void deployService(ServiceDescription servi= ce) - throws AxisFault { - reciver.getSystemContext().getEngineConfig().addService(service); = =20 - Utils.resolvePhases(reciver.getSystemContext().getEngineConfig(),s= ervice); + public static synchronized void deployService(ServiceDescription servi= ce) throws AxisFault { + reciver.getSystemContext().getEngineConfig().addService(service); + Utils.resolvePhases(reciver.getSystemContext().getEngineConfig(), = service); } =20 - public static synchronized void unDeployService(QName service) - throws AxisFault { + public static synchronized void unDeployService(QName service) throws = AxisFault { reciver.getSystemContext().getEngineConfig().removeService(service= ); } =20 public static synchronized void start() throws Exception { if (count =3D=3D 0) { ConfigurationContextFactory erfac =3D new ConfigurationContext= Factory(); - =20 - //File file =3D new File("modules/samples/target/test-resource= s/samples"); - File file =3D new File("target/test-resources/samples"); - if(!file.exists()){ + File file =3D new File(TESTING_REPOSITORY); + if (!file.exists()) { throw new Exception("repository directory does not exists"= ); } ConfigurationContext er =3D erfac.buildEngineContext(file.getA= bsolutePath()); @@ -63,14 +64,10 @@ } catch (InterruptedException e1) { throw new AxisFault("Thread interuptted", e1); } - =20 - =20 - - =20 =20 ServerSocket serverSoc =3D null; serverSoc =3D new ServerSocket(Constants.TESTING_PORT); - reciver =3D new SimpleHTTPServer(er,serverSoc); + reciver =3D new SimpleHTTPServer(er, serverSoc); Thread thread =3D new Thread(reciver); thread.setDaemon(true); =20 @@ -93,8 +90,29 @@ count--; } } - =20 - public static ConfigurationContext getConfigurationContext(){ + + public static ConfigurationContext getConfigurationContext() { return reciver.getSystemContext(); } + + public static ServiceContext createAdressedEnabledClientSide(ServiceDe= scription service) + throws AxisFault { + DeploymentEngine deploymentEngine =3D new DeploymentEngine(); + File file =3D new File(UtilServer.TESTING_REPOSITORY + "/modules/a= ddressing.mar"); + TestCase.assertTrue(file.exists()); + ModuleDescription moduleDesc =3D deploymentEngine.buildModule(file= ); + + ConfigurationContextFactory efac =3D new ConfigurationContextFacto= ry(); + ConfigurationContext sysContext =3D efac.buildClientEngineContext(= null); + new ConfigurationContext(new AxisConfigurationImpl()); + sysContext.getEngineConfig().addMdoule(moduleDesc); + sysContext.getEngineConfig().engageModule(moduleDesc.getName()); + + sysContext.getEngineConfig().addService(service); + //Utils.resolvePhases(sysContext.getEngineConfig(), service); + ServiceContext serviceContext =3D sysContext.createServiceContext(= service.getName()); + return serviceContext; + + } + } Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/int= egration/UtilsTCPServer.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/test/org/apache/axis/integration/UtilsTCPServer.java?rev=3D171100&view= =3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/integr= ation/UtilsTCPServer.java (added) +++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/integr= ation/UtilsTCPServer.java Fri May 20 04:11:07 2005 @@ -0,0 +1,90 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + *=20 + * 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 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * 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.integration; + +import java.io.File; + +import javax.xml.namespace.QName; + +import org.apache.axis.context.ConfigurationContext; +import org.apache.axis.context.ConfigurationContextFactory; +import org.apache.axis.description.ServiceDescription; +import org.apache.axis.engine.AxisFault; +import org.apache.axis.transport.tcp.TCPServer; + +public class UtilsTCPServer { + private static int count =3D 0; + private static TCPServer reciver; + + private static ConfigurationContext configurationContext; + public static final int TESTING_PORT =3D 5555; + public static final String FAILURE_MESSAGE =3D "Intentional Faliure"; + public static final String TESTING_REPOSITORY =3D "target/test-resourc= es/samples"; + //public static final String TESTING_REPOSITORY =3D "modules/samples/t= arget/test-resources/samples"; + + public static synchronized void deployService(ServiceDescription servi= ce) throws AxisFault { + configurationContext.getEngineConfig().addService(service); + + } + + public static synchronized void unDeployService(QName service) throws = AxisFault { + configurationContext.getEngineConfig().removeService(service); + } + + public static synchronized void start() throws Exception { + if (count =3D=3D 0) { + + //start tcp server + + ConfigurationContextFactory erfac =3D new ConfigurationContext= Factory(); + File file =3D new File(TESTING_REPOSITORY); + if (!file.exists()) { + throw new Exception("repository directory does not exists"= ); + } + configurationContext =3D erfac.buildEngineContext(file.getAbso= lutePath()); + try { + Thread.sleep(2000); + } catch (InterruptedException e1) { + throw new AxisFault("Thread interuptted", e1); + } + + reciver =3D new TCPServer(UtilServer.TESTING_PORT, configurati= onContext); + reciver.start(); + + } + count++; + } + + public static synchronized void stop() { + try { + if (count =3D=3D 1) { + reciver.stop(); + count =3D 0; + System.out.print("Server stopped ....."); + } else { + count--; + } + } catch (AxisFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static ConfigurationContext getConfigurationContext() { + return configurationContext; + } +}