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 gd...@apache.org on 2001/02/08 23:08:18 UTC
cvs commit: xml-axis/java/src/org/apache/axis/handlers BasicHandler.java HTTPActionHandler.java Router.java DebugHandler.java EchoHandler.java ErrorHandler.java
gdaniels 01/02/08 14:08:17
Modified: java/src/org/apache/axis/handlers DebugHandler.java
EchoHandler.java ErrorHandler.java
Added: java/src/org/apache/axis/handlers BasicHandler.java
HTTPActionHandler.java Router.java
Log:
Add several new Handlers:
The Router serves to simply find and invoke a service with the name
found in the MC_TARGET property of the MessageContext. This guy
will get used a lot in various contexts.
The HTTPActionHandler is a demonstration of transport-specific Handlers.
He just takes the value of the SOAPAction property and puts it into the
MC_TARGET property so that a Router can use it.
BasicHandler is an abstract class to make writing Handlers easier. It
encapsulates the property database, and stubs for every method
except invoke() (which must be implemented by subclasses).
Changed ErrorHandler + EchoHandler + DebugHandler to extend
BasicHandler. They're tiny now. :)
Revision Changes Path
1.2 +32 -70 xml-axis/java/src/org/apache/axis/handlers/DebugHandler.java
Index: DebugHandler.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/DebugHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DebugHandler.java 2001/02/05 22:32:28 1.1
+++ DebugHandler.java 2001/02/08 22:08:06 1.2
@@ -69,77 +69,39 @@
*
* @author Doug Davis (dug@us.ibm.com)
*/
-public class DebugHandler implements Handler {
- protected Hashtable options ;
-
- public void init() {
- }
-
- public void cleanup() {
- }
-
- public void invoke(MessageContext msgContext) throws AxisFault {
- Debug.Print( 1, "Enter: DebugHandler::invoke" );
- try {
- Message msg = msgContext.getIncomingMessage();
- SOAPEnvelope env = (SOAPEnvelope) msg.getAs( "SOAPEnvelope" );
- Vector headers = null ;
-
- headers = env.getHeadersByURI( Constants.URI_DEBUG );
-
- for ( int i = 0 ; headers != null && i < headers.size() ; i ++ ) {
- SOAPHeader header = (SOAPHeader) headers.get(i);
- Node node = header.getDataAtIndex( 0 );
- if ( node != null ) {
- String value = node.getNodeValue();
- int debugVal = Integer.parseInt( value );
- Debug.Print( 1, "Settng debug level to: " + debugVal );
- Debug.setDebugLevel( debugVal );
- header.setProcessed( true );
+public class DebugHandler extends BasicHandler {
+
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ Debug.Print( 1, "Enter: DebugHandler::invoke" );
+ try {
+ Message msg = msgContext.getIncomingMessage();
+ SOAPEnvelope env = (SOAPEnvelope) msg.getAs( "SOAPEnvelope" );
+ Vector headers = null ;
+
+ headers = env.getHeadersByURI( Constants.URI_DEBUG );
+
+ for ( int i = 0 ; headers != null && i < headers.size() ; i ++ ) {
+ SOAPHeader header = (SOAPHeader) headers.get(i);
+ Node node = header.getDataAtIndex( 0 );
+ if ( node != null ) {
+ String value = node.getNodeValue();
+ int debugVal = Integer.parseInt( value );
+ Debug.Print( 1, "Settng debug level to: " + debugVal );
+ Debug.setDebugLevel( debugVal );
+ header.setProcessed( true );
+ }
+ }
}
- }
- }
- catch( Exception e ) {
- Debug.Print( 1, e );
- throw new AxisFault( e );
+ catch( Exception e ) {
+ Debug.Print( 1, e );
+ throw new AxisFault( e );
+ }
+ Debug.Print( 1, "Exit: DebugHandler::invoke" );
}
- Debug.Print( 1, "Exit: DebugHandler::invoke" );
- }
-
- public void undo(MessageContext msgContext) {
- Debug.Print( 1, "Enter: DebugHandler::undo" );
- Debug.Print( 1, "Exit: DebugHandler::undo" );
- }
- public boolean canHandleBlock(QName qname) {
- return( false );
- }
-
- /**
- * Add the given option (name/value) to this handler's bag of options
- */
- public void addOption(String name, Object value) {
- if ( options == null ) options = new Hashtable();
- options.put( name, value );
- }
-
- /**
- * Returns the option corresponding to the 'name' given
- */
- public Object getOption(String name) {
- if ( options == null ) return( null );
- return( options.get(name) );
- }
-
- /**
- * Return the entire list of options
- */
- public Hashtable getOptions() {
- return( options );
- }
-
- public void setOptions(Hashtable opts) {
- options = opts ;
- }
-
+ public void undo(MessageContext msgContext) {
+ Debug.Print( 1, "Enter: DebugHandler::undo" );
+ Debug.Print( 1, "Exit: DebugHandler::undo" );
+ }
+
};
1.10 +17 -59 xml-axis/java/src/org/apache/axis/handlers/EchoHandler.java
Index: EchoHandler.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/EchoHandler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EchoHandler.java 2001/02/01 22:21:26 1.9
+++ EchoHandler.java 2001/02/08 22:08:07 1.10
@@ -57,10 +57,6 @@
package org.apache.axis.handlers ;
-import java.util.* ;
-import org.w3c.dom.* ;
-import org.xml.sax.InputSource ;
-
import org.apache.axis.* ;
import org.apache.axis.utils.* ;
import org.apache.axis.message.* ;
@@ -69,63 +65,25 @@
*
* @author Doug Davis (dug@us.ibm.com)
*/
-public class EchoHandler implements Handler {
- protected Hashtable options ;
-
- public void init() {
- }
-
- public void cleanup() {
- }
+public class EchoHandler extends BasicHandler {
- public void invoke(MessageContext msgContext) throws AxisFault {
- Debug.Print( 1, "Enter: EchoHandler::invoke" );
- try {
- Message msg = msgContext.getIncomingMessage();
- SOAPEnvelope env = (SOAPEnvelope) msg.getAs( "SOAPEnvelope" );
- msgContext.setOutgoingMessage( new Message( env, "SOAPEnvelope" ) );
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ Debug.Print( 1, "Enter: EchoHandler::invoke" );
+ try {
+ Message msg = msgContext.getIncomingMessage();
+ SOAPEnvelope env = (SOAPEnvelope) msg.getAs( "SOAPEnvelope" );
+ msgContext.setOutgoingMessage( new Message( env, "SOAPEnvelope" ) );
+ }
+ catch( Exception e ) {
+ Debug.Print( 1, e );
+ throw new AxisFault( e );
+ }
+ Debug.Print( 1, "Exit: EchoHandler::invoke" );
}
- catch( Exception e ) {
- Debug.Print( 1, e );
- throw new AxisFault( e );
- }
- Debug.Print( 1, "Exit: EchoHandler::invoke" );
- }
-
- public void undo(MessageContext msgContext) {
- Debug.Print( 1, "Enter: EchoHandler::undo" );
- Debug.Print( 1, "Exit: EchoHandler::undo" );
- }
- public boolean canHandleBlock(QName qname) {
- return( false );
- }
-
- /**
- * Add the given option (name/value) to this handler's bag of options
- */
- public void addOption(String name, Object value) {
- if ( options == null ) options = new Hashtable();
- options.put( name, value );
- }
-
- /**
- * Returns the option corresponding to the 'name' given
- */
- public Object getOption(String name) {
- if ( options == null ) return( null );
- return( options.get(name) );
- }
-
- /**
- * Return the entire list of options
- */
- public Hashtable getOptions() {
- return( options );
- }
-
- public void setOptions(Hashtable opts) {
- options = opts ;
- }
+ public void undo(MessageContext msgContext) {
+ Debug.Print( 1, "Enter: EchoHandler::undo" );
+ Debug.Print( 1, "Exit: EchoHandler::undo" );
+ }
};
1.8 +11 -49 xml-axis/java/src/org/apache/axis/handlers/ErrorHandler.java
Index: ErrorHandler.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/ErrorHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ErrorHandler.java 2001/02/01 22:21:26 1.7
+++ ErrorHandler.java 2001/02/08 22:08:08 1.8
@@ -57,62 +57,24 @@
package org.apache.axis.handlers ;
-import java.util.* ;
import org.apache.axis.* ;
import org.apache.axis.utils.* ;
/**
*
* @author Doug Davis (dug@us.ibm.com)
+ * @author Glen Daniels (gdaniels@allaire.com)
*/
-public class ErrorHandler implements Handler {
- protected Hashtable options ;
+public class ErrorHandler extends BasicHandler {
- public void init() {
- }
-
- public void cleanup() {
- }
-
- public void invoke(MessageContext msgContext) throws AxisFault {
- Debug.Print( 1, "Enter: ErrorHandler::invoke" );
- throw new AxisFault( "Server.Whatever", "ERROR", null, null );
- }
-
- public void undo(MessageContext msgContext) {
- Debug.Print( 1, "Enter: ErrorHandler::undo" );
- Debug.Print( 1, "Exit: ErrorHandler::undo" );
- }
-
- public boolean canHandleBlock(QName qname) {
- return( false );
- }
-
- /**
- * Add the given option (name/value) to this handler's bag of options
- */
- public void addOption(String name, Object value) {
- if ( options == null ) options = new Hashtable();
- options.put( name, value );
- }
-
- /**
- * Returns the option corresponding to the 'name' given
- */
- public Object getOption(String name) {
- if ( options == null ) return( null );
- return( options.get(name) );
- }
-
- /**
- * Return the entire list of options
- */
- public Hashtable getOptions() {
- return( options );
- }
-
- public void setOptions(Hashtable opts) {
- options = opts ;
- }
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ Debug.Print( 1, "Enter: ErrorHandler::invoke" );
+ throw new AxisFault( "Server.Whatever", "ERROR", null, null );
+ }
+
+ public void undo(MessageContext msgContext) {
+ Debug.Print( 1, "Enter: ErrorHandler::undo" );
+ Debug.Print( 1, "Exit: ErrorHandler::undo" );
+ }
};
1.1 xml-axis/java/src/org/apache/axis/handlers/BasicHandler.java
Index: BasicHandler.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.handlers;
import org.apache.axis.*;
import org.apache.axis.utils.QName;
import java.util.Hashtable;
/** <code>BasicHandler</code> is a utility class which implements simple
* property setting/getting behavior, and stubs out a lot of the Handler
* methods. Extend this class to make writing your Handlers easier, and
* then override what you need to.
*
* @author Glen Daniels (gdaniels@allaire.com)
*/
public abstract class BasicHandler implements Handler {
protected Hashtable options ;
/** Stubbed-out methods. Override in your child class to implement
* any real behavior.
*/
public void init()
{
}
public void cleanup()
{
}
public void undo(MessageContext msgContext)
{
}
public boolean canHandleBlock(QName qname)
{
return false;
}
/** Must implement this in subclasses.
*/
public abstract void invoke(MessageContext msgContext) throws AxisFault;
/**
* Add the given option (name/value) to this handler's bag of options
*/
public void addOption(String name, Object value) {
if ( options == null ) options = new Hashtable();
options.put( name, value );
}
/**
* Returns the option corresponding to the 'name' given
*/
public Object getOption(String name) {
if ( options == null ) return( null );
return( options.get(name) );
}
/**
* Return the entire list of options
*/
public Hashtable getOptions() {
return( options );
}
public void setOptions(Hashtable opts) {
options = opts ;
}
}
1.1 xml-axis/java/src/org/apache/axis/handlers/HTTPActionHandler.java
Index: HTTPActionHandler.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.handlers;
import org.apache.axis.*;
import org.apache.axis.registries.SimpleServiceRegistry;
import org.apache.axis.utils.Debug;
/** An <code>HTTPActionHandler</code> simply sets the context's TARGET
* property from the HTTPAction property. We expect there to be a
* Router on the chain after us, to dispatch to the service named in
* the SOAPAction.
*
* In the real world, this might do some more complex mapping of
* SOAPAction to a TARGET.
*
* @author Glen Daniels (gdaniels@allaire.com)
*/
public class HTTPActionHandler extends BasicHandler
{
public void invoke(MessageContext msgContext) throws AxisFault
{
Debug.Print( 1, "Enter: HTTPActionHandler::invoke" );
String action = (String)msgContext.getProperty(Constants.MC_HTTP_SOAPACTION);
if (action == null)
throw new AxisFault(new NullPointerException("HTTPActionHandler: No HTTPAction property in context!"));
msgContext.setProperty(Constants.MC_TARGET, action);
Debug.Print( 1, "Exit : HTTPActionHandler::invoke" );
}
}
1.1 xml-axis/java/src/org/apache/axis/handlers/Router.java
Index: Router.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.handlers;
import org.apache.axis.*;
import org.apache.axis.registries.SimpleServiceRegistry;
import org.apache.axis.utils.Debug;
/** A <code>Router</code> is a Handler which has only one purpose in life:
* to look up the TARGET property in the passed MessageContext, then look
* up a Handler under that name in the ServiceRegistry. Then it passes
* the MessageContext off to that Handler.
*
* @author Glen Daniels (gdaniels@allaire.com)
*/
public class Router extends BasicHandler
{
public void invoke(MessageContext msgContext) throws AxisFault
{
Debug.Print( 1, "Enter: Router::invoke" );
SimpleServiceRegistry registry = (SimpleServiceRegistry)msgContext.getProperty(Constants.SERVICE_REGISTRY);
if (registry == null)
throw new AxisFault(new NullPointerException("Router: No registry property in context!"));
String target = (String)msgContext.getProperty(Constants.MC_TARGET);
if (target == null)
throw new AxisFault(new NullPointerException("Router: No target property in context!"));
Handler h = registry.find( target );
if (h == null)
throw new AxisFault(new Exception("Router: Couldn't find service '" + target + "' in the registry!"));
// Make sure next dispatch, if any, is clean so we don't loop back.
msgContext.clearProperty(Constants.MC_TARGET);
h.invoke(msgContext);
Debug.Print( 1, "Exit : Router::invoke" );
}
}