You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by du...@apache.org on 2006/02/21 14:34:20 UTC
svn commit: r379450 - in /webservices/axis/trunk/java:
src/org/apache/axis/server/AxisServer.java
src/org/apache/axis/transport/http/SimpleAxisServer.java
test/functional/FunctionalTests.java test/functional/TestWSA.java
test/functional/auto-deploy.wsdd
Author: dug
Date: Tue Feb 21 05:34:19 2006
New Revision: 379450
URL: http://svn.apache.org/viewcvs?rev=379450&view=rev
Log:
Complete the WSA stuff by adding in the server-side processing.
Also includes a couple of minor tests. Next I need to add some
more docs and samples.
With this commit all tests (all-tests and TCKs) run ok.
Added:
webservices/axis/trunk/java/test/functional/TestWSA.java
Modified:
webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java
webservices/axis/trunk/java/src/org/apache/axis/transport/http/SimpleAxisServer.java
webservices/axis/trunk/java/test/functional/FunctionalTests.java
webservices/axis/trunk/java/test/functional/auto-deploy.wsdd
Modified: webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java?rev=379450&r1=379449&r2=379450&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/server/AxisServer.java Tue Feb 21 05:34:19 2006
@@ -1,12 +1,12 @@
/*
* Copyright 2001-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,19 +25,26 @@
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.SimpleTargetedChain;
-import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.soap.SOAPConstants;
import org.apache.axis.client.AxisClient;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
+import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.utils.ClassUtils;
import org.apache.axis.utils.Messages;
import org.apache.commons.logging.Log;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.message.SOAPBodyElement;
+import org.apache.axis.message.SOAPHeaderElement;
+import org.apache.axis.wsa.MIHeader;
+import org.apache.axis.wsa.WSAConstants;
+import org.apache.axis.wsa.WSAHandler;
import java.util.Map;
+import java.lang.reflect.Method ;
+
/**
*
- * @author Doug Davis (dug@us.ibm.com)
* @author Glen Daniels (gdaniels@allaire.com)
*/
public class AxisServer extends AxisEngine
@@ -48,7 +55,8 @@
LogFactory.getLog("org.apache.axis.TIME");
private static AxisServerFactory factory = null;
-
+ private long t0=0, t1=0, t2=0, t3=0, t4=0, t5=0;
+
public static AxisServer getServer(Map environment) throws AxisFault
{
if (factory == null) {
@@ -124,13 +132,149 @@
return clientEngine;
}
+ public void invokeInboundTransport(MessageContext msgContext)
+ throws Exception
+ {
+ /* Process the Transport Specific Request Chain */
+ /**********************************************/
+ String hName = msgContext.getTransportName();
+ Handler h = null ;
+ SimpleTargetedChain transportChain = null ;
+
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage("transport01","AxisServer.invoke",hName));
+ t1=System.currentTimeMillis();
+ }
+
+ if ( hName != null && (h = getTransport( hName )) != null ) {
+ if (h instanceof SimpleTargetedChain) {
+ transportChain = (SimpleTargetedChain)h;
+ h = transportChain.getRequestHandler();
+ if (h != null)
+ h.invoke(msgContext);
+ }
+ }
+ }
+
+ public void invokeOutboundTransport(MessageContext msgContext)
+ throws Exception
+ {
+ String hName = msgContext.getTransportName();
+ Handler h = null ;
+ SimpleTargetedChain transportChain = null ;
+
+ /* Process the Transport Specific Response Chain */
+ /***********************************************/
+ if ( hName != null && (h = getTransport( hName )) != null ) {
+ if (h instanceof SimpleTargetedChain) {
+ transportChain = (SimpleTargetedChain)h;
+ h = transportChain.getResponseHandler();
+ if (h != null) {
+ h.invoke(msgContext);
+ }
+ }
+ }
+ }
+
+ public void invokeService(MessageContext msgContext) throws Exception {
+ Handler h = null ;
+
+ if ( tlog.isDebugEnabled() )
+ t2=System.currentTimeMillis();
+
+ try {
+ // Run WSA logic
+ WSAHandler.invoke( msgContext );
+
+ MIHeader mih = MIHeader.fromCurrentMessage();
+
+ if ( mih != null ) {
+ // See if it needs to be rerouted
+ // Dug - not yet // (new WSXHandler()).invoke( msgContext );
+ }
+
+ /* Process the Global Request Chain */
+ /************************************/
+ if ((h = getGlobalRequest()) != null ) {
+ h.invoke(msgContext);
+ }
+
+ /**
+ * At this point, the service should have been set by someone
+ * (either the originator of the MessageContext, or one of the
+ * transport or global Handlers). If it hasn't been set, we
+ * fault.
+ */
+ h = msgContext.getService();
+ if (h == null) {
+ // It's possible that we haven't yet parsed the
+ // message at this point. This is a kludge to
+ // make sure we have. There probably wants to be
+ // some kind of declarative "parse point" on the handler
+ // chain instead....
+ Message rm = msgContext.getRequestMessage();
+ rm.getSOAPEnvelope().getFirstBody();
+
+ h = msgContext.getService();
+ if (h == null)
+ throw new AxisFault("Server.NoService",
+ Messages.getMessage("noService05",
+ "" + msgContext.getTargetService()),
+ null, null );
+ }
+ if ( tlog.isDebugEnabled() )
+ t3=System.currentTimeMillis();
+
+ SOAPEnvelope env = msgContext.getRequestMessage().getSOAPEnvelope();
+
+ // Only invoke the service is there's a body - sort of a hack
+ if ( env.getFirstBody() != null ) {
+ initSOAPConstants(msgContext);
+ try {
+ h.invoke(msgContext);
+ }
+ catch(AxisFault af) {
+ if ( (h= getGlobalRequest()) != null )
+ h.onFault(msgContext);
+ throw af ;
+ }
+ finally {
+ msgContext.setPastPivot( true );
+ }
+ }
+
+ if ( tlog.isDebugEnabled() )
+ t4=System.currentTimeMillis();
+ }
+ catch(Exception exp) {
+ // If WSA isn't turned on then just rethrow it
+ // Dug - fix this, it should not do this we need to make this
+ // work even when WSA is turned on
+ if ( msgContext.getProperty(WSAConstants.REQ_MIH) == null ) throw exp ;
+ if ( !(exp instanceof AxisFault) )
+ exp = AxisFault.makeFault( exp );
+
+ msgContext.setPastPivot( true );
+ msgContext.setResponseMessage( new Message(exp) );
+
+ // WSA stuff
+ WSAHandler.fixAction( msgContext );
+ }
+ // WSA logic is run first
+ WSAHandler.invoke( msgContext );
+
+ /* Process the Global Response Chain */
+ /***********************************/
+ if ((h = getGlobalResponse()) != null)
+ h.invoke(msgContext);
+ }
+
/**
* Main routine of the AXIS server. In short we locate the appropriate
* handler for the desired service and invoke() it.
*/
public void invoke(MessageContext msgContext) throws AxisFault {
- long t0=0, t1=0, t2=0, t3=0, t4=0, t5=0;
- if( tlog.isDebugEnabled() ) {
+ if ( tlog.isDebugEnabled() ) {
t0=System.currentTimeMillis();
}
@@ -167,16 +311,23 @@
h = null ;
}
}
- if( tlog.isDebugEnabled() ) {
+ if ( tlog.isDebugEnabled() ) {
t1=System.currentTimeMillis();
}
- if ( h != null )
+ if ( h != null ) {
+ try {
h.invoke(msgContext);
+ }
+ catch(Exception exp ) {
+ exp.printStackTrace();
+ throw exp ;
+ }
+ }
else
throw new AxisFault( "Server.error",
Messages.getMessage("noHandler00", hName),
null, null );
- if( tlog.isDebugEnabled() ) {
+ if ( tlog.isDebugEnabled() ) {
t2=System.currentTimeMillis();
tlog.debug( "AxisServer.invoke " + hName + " invoke=" +
( t2-t1 ) + " pre=" + (t1-t0 ));
@@ -220,90 +371,22 @@
*/
- /* Process the Transport Specific Request Chain */
- /**********************************************/
- hName = msgContext.getTransportName();
- SimpleTargetedChain transportChain = null;
+ invokeInboundTransport(msgContext);
+ invokeService(msgContext);
- if (log.isDebugEnabled())
- log.debug(Messages.getMessage("transport01", "AxisServer.invoke", hName));
-
- if( tlog.isDebugEnabled() ) {
- t1=System.currentTimeMillis();
- }
- if ( hName != null && (h = getTransport( hName )) != null ) {
- if (h instanceof SimpleTargetedChain) {
- transportChain = (SimpleTargetedChain)h;
- h = transportChain.getRequestHandler();
- if (h != null)
- h.invoke(msgContext);
- }
- }
-
- if( tlog.isDebugEnabled() ) {
- t2=System.currentTimeMillis();
- }
- /* Process the Global Request Chain */
- /**********************************/
- if ((h = getGlobalRequest()) != null ) {
- h.invoke(msgContext);
- }
-
- /**
- * At this point, the service should have been set by someone
- * (either the originator of the MessageContext, or one of the
- * transport or global Handlers). If it hasn't been set, we
- * fault.
- */
- h = msgContext.getService();
- if (h == null) {
- // It's possible that we haven't yet parsed the
- // message at this point. This is a kludge to
- // make sure we have. There probably wants to be
- // some kind of declarative "parse point" on the handler
- // chain instead....
- Message rm = msgContext.getRequestMessage();
- rm.getSOAPEnvelope().getFirstBody();
-
- h = msgContext.getService();
- if (h == null)
- throw new AxisFault("Server.NoService",
- Messages.getMessage("noService05",
- "" + msgContext.getTargetService()),
- null, null );
- }
- if( tlog.isDebugEnabled() ) {
- t3=System.currentTimeMillis();
- }
+ msgContext.setPastPivot( true );
- initSOAPConstants(msgContext);
- try {
- h.invoke(msgContext);
- } catch (AxisFault ae) {
- if ((h = getGlobalRequest()) != null ) {
- h.onFault(msgContext);
- }
- throw ae;
- }
+ /*
+ if ( msgContext.getIsOneWay() )
+ msgContext.setResponseMessage( null );
+ */
- if( tlog.isDebugEnabled() ) {
- t4=System.currentTimeMillis();
- }
+ // Send async response if needed
+ WSAHandler.sendResponse( msgContext );
- /* Process the Global Response Chain */
- /***********************************/
- if ((h = getGlobalResponse()) != null)
- h.invoke(msgContext);
+ invokeOutboundTransport(msgContext);
- /* Process the Transport Specific Response Chain */
- /***********************************************/
- if (transportChain != null) {
- h = transportChain.getResponseHandler();
- if (h != null)
- h.invoke(msgContext);
- }
-
- if( tlog.isDebugEnabled() ) {
+ if ( tlog.isDebugEnabled() ) {
t5=System.currentTimeMillis();
tlog.debug( "AxisServer.invoke2 " +
" preTr=" +
@@ -337,7 +420,7 @@
* Extract ans store soap constants info from the envelope
* @param msgContext
* @throws AxisFault
- */
+ */
private void initSOAPConstants(MessageContext msgContext) throws AxisFault {
Message msg = msgContext.getRequestMessage();
if (msg == null)
@@ -466,9 +549,9 @@
// make sure we have. There probably wants to be
// some kind of declarative "parse point" on the handler
// chain instead....
- Message rm = msgContext.getRequestMessage();
- if (rm != null) {
- rm.getSOAPEnvelope().getFirstBody();
+ Message msg = msgContext.getRequestMessage();
+ if (msg != null) {
+ msg.getSOAPEnvelope().getFirstBody();
h = msgContext.getService();
}
if (h == null) {
Modified: webservices/axis/trunk/java/src/org/apache/axis/transport/http/SimpleAxisServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/transport/http/SimpleAxisServer.java?rev=379450&r1=379449&r2=379450&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/transport/http/SimpleAxisServer.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/transport/http/SimpleAxisServer.java Tue Feb 21 05:34:19 2006
@@ -337,6 +337,12 @@
pool.shutdown();
}
+ public void startListening(int port) throws Exception {
+ ServerSocket ss = new ServerSocket(port);
+ setServerSocket(ss);
+ start( true );
+ }
+
/**
* Server process.
*/
Modified: webservices/axis/trunk/java/test/functional/FunctionalTests.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/test/functional/FunctionalTests.java?rev=379450&r1=379449&r2=379450&view=diff
==============================================================================
--- webservices/axis/trunk/java/test/functional/FunctionalTests.java (original)
+++ webservices/axis/trunk/java/test/functional/FunctionalTests.java Tue Feb 21 05:34:19 2006
@@ -80,6 +80,8 @@
//suite.addTestSuite(TestMimeHeaders.class);
suite.addTestSuite(TestAutoTypes.class);
+
+ suite.addTestSuite(TestWSA.class);
return suite;
}
Added: webservices/axis/trunk/java/test/functional/TestWSA.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/test/functional/TestWSA.java?rev=379450&view=auto
==============================================================================
--- webservices/axis/trunk/java/test/functional/TestWSA.java (added)
+++ webservices/axis/trunk/java/test/functional/TestWSA.java Tue Feb 21 05:34:19 2006
@@ -0,0 +1,69 @@
+package test.functional;
+
+import junit.framework.TestCase;
+import org.apache.axis.client.AdminClient;
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service ;
+import org.apache.axis.encoding.XMLType;
+import org.apache.axis.utils.Options;
+import javax.xml.rpc.ParameterMode;
+import javax.xml.namespace.QName;
+import org.apache.axis.transport.http.SimpleAxisServer ;
+
+/**
+ * Test WSAddressing
+ */
+public class TestWSA extends TestCase {
+ public Call call = null ;
+
+ public TestWSA(String s) {
+ super(s);
+ }
+
+ /**
+ * Sets up the WSA Async listener
+ */
+ protected void setUp() throws Exception {
+ (new SimpleAxisServer()).startListening(88);
+ AdminClient.main( new String[] { "samples/wsa/deploy.wsdd" } );
+ }
+
+ public void testWSA() throws Exception {
+ Service service = new Service();
+ Call call = (Call) service.createCall();
+ Object rc = null ;
+ String rcStr = null ;
+
+ call.setTargetEndpointAddress( "http://localhost:8080/axis/services/wsaService");
+ call.addParameter( "text", XMLType.XSD_STRING, ParameterMode.IN );
+ call.setReturnType( XMLType.XSD_STRING );
+ call.setEncodingStyle("");
+
+ System.out.println( "Running non-WSA echo" );
+ rc = call.invoke( "echo", new Object[] { "hi1" } );
+ System.out.println( "rc: " + rc );
+ assertEquals( rc, "hi1" );
+
+ System.out.println( "Turning WSA on, and redoing echo" );
+ call.setProperty( "useWSA", "true" );
+ rc = call.invoke( "echo", new Object[] { "hi2" } );
+ System.out.println( "rc: " + rc );
+ assertEquals( rc, "hi2" );
+ assertEquals( null, call.getProperty("ASYNCRESPONSE") );
+
+ System.out.println( "Setting wsa:ReplyTo to async" );
+ call.setReplyTo( "http://localhost:88/axis/services/asyncService" );
+ rc = call.invoke( "echo", new Object[] { "hi3" } );
+ System.out.println( "rc: " + rc );
+ assertEquals( rc, "hi3" );
+ assertEquals( "true", call.getMessageContext().getProperty("ASYNCRESPONSE") );
+
+ /*
+ System.out.println( "Calling ping (one way)" );
+ call.invokeOneWay( "ping", new Object[] { "hi" } );
+
+ Thread.sleep(1000);
+ */
+ }
+
+}
Modified: webservices/axis/trunk/java/test/functional/auto-deploy.wsdd
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/test/functional/auto-deploy.wsdd?rev=379450&r1=379449&r2=379450&view=diff
==============================================================================
--- webservices/axis/trunk/java/test/functional/auto-deploy.wsdd (original)
+++ webservices/axis/trunk/java/test/functional/auto-deploy.wsdd Tue Feb 21 05:34:19 2006
@@ -15,5 +15,17 @@
</handler>
</requestFlow>
</globalConfiguration>
+
+ <transport name="SimpleHTTP">
+ <requestFlow>
+ <handler type="java:org.apache.axis.handlers.JWSHandler">
+ <parameter name="scope" value="session"/>
+ </handler>
+ <handler type="java:org.apache.axis.handlers.JWSHandler">
+ <parameter name="scope" value="request"/>
+ <parameter name="extension" value=".jwr"/>
+ </handler>
+ </requestFlow>
+ </transport>
</deployment>