Author: ips
Date: Thu May 19 17:02:37 2005
New Revision: 171023
URL: http://svn.apache.org/viewcvs?rev=171023&view=rev
Log:
improved error handling and request validation in Handler; misc
Modified:
incubator/apollo/trunk/maven.xml
incubator/apollo/trunk/src/java/org/apache/ws/resource/NamespaceConstants.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/GenericAxisHandler.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProvider.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProviderFactory.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/WsrfAxisServlet.java
incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java
Modified: incubator/apollo/trunk/maven.xml
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/maven.xml?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
--- incubator/apollo/trunk/maven.xml (original)
+++ incubator/apollo/trunk/maven.xml Thu May 19 17:02:37 2005
@@ -75,6 +75,7 @@
<goal name="website"
description="generates project website / docs using Forrest">
+ <delete dir="${maven.src.dir}/site/content/tutorial/generated" />
<echo>FORREST_HOME=${env.FORREST_HOME}</echo>
<property name="forrest.home" location="${env.FORREST_HOME}" />
<property name="forrest.install.dir" location="${forrest.home}/../.." />
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/NamespaceConstants.java
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/NamespaceConstants.java?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
---
incubator/apollo/trunk/src/java/org/apache/ws/resource/NamespaceConstants.java
(original)
+++
incubator/apollo/trunk/src/java/org/apache/ws/resource/NamespaceConstants.java
Thu May 19 17:02:37 2005
@@ -23,14 +23,14 @@
{
/**
- * DOCUMENT_ME
+ * TODO: Use http://ws.apache.org/namespaces/wsrf/... instead.
*/
String NSURI_APACHE_WS_RESOURCE = "http://ws.apache.org/resource";
/**
* DOCUMENT_ME
*/
- String NSPREFIX_APACHE_WS_RESOURCE = "wsrf";
+ String NSPREFIX_APACHE_WS_RESOURCE = "asf-wsrf";
/**
* DOCUMENT_ME
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
---
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
(original)
+++
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
Thu May 19 17:02:37 2005
@@ -29,6 +29,7 @@
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl;
import javax.xml.namespace.QName;
import javax.xml.rpc.JAXRPCException;
@@ -48,13 +49,14 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* LOG-DONE Base class for platform-specific providers; also is a JAX-RPC
Handler for more flexibility.
*
- * @author Ian P. Springer
+ * @author Ian Springer
* @author Sal Campana
*/
public abstract class ResourceHandler
@@ -93,13 +95,14 @@
public void init( HandlerInfo handlerInfo )
{
- m_handlerOptions = handlerInfo.getHandlerConfig();
+ Map handlerConfig = handlerInfo.getHandlerConfig();
+ m_handlerOptions = handlerConfig != null ? handlerConfig : new
HashMap();
}
/**
- * DOCUMENT_ME
+ * This handler acts as the pivot and does not process any SOAP header
elements.
*
- * @return DOCUMENT_ME
+ * @return the names of the SOAP header elements that this handler
processes
*/
public QName[] getHeaders()
{
@@ -107,11 +110,9 @@
}
/**
- * DOCUMENT_ME
- *
- * @param msgContext DOCUMENT_ME
- *
- * @return DOCUMENT_ME
+ * Deserializes the incoming SOAP request to an XMLBean and dispatches it
to the appropriate service. It is required
+ * that the request meet the following criteria: <ol> <li>SOAP Header
contains the header elements required by
+ * WS-Addressing (either 2003/03 or 2004/08)</li> <li>SOAP Body contains
no more than one body element</li> </ol>
*/
public boolean handleRequest( MessageContext msgContext )
{
@@ -140,13 +141,13 @@
if ( childElems.length > 1 )
{
throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
- "SOAP Body contains more than one request element -
this service requires that the SOAP Body contain at most one request element."
);
+ "SOAP request Body contains more than one body element
- this service requires that all SOAP requests contain at most one body
element." );
}
if ( childElems.length == 0 ) // empty Body
{
if ( methodNameFromAction != null )
{
- //try to find a method based on the action
+ // try to find a method based on the wsa:Action...
serviceMethod = getServiceMethod( service,
methodNameFromAction );
LOG.debug( MSG.getMessage( Keys.INVOKE_RESOURCE_METHOD,
serviceMethod.getName() ) );
@@ -159,7 +160,7 @@
else // empty Body and unmapped wsa:Action
{
throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
- "No SOAP Body elements were defined, and the
WS-Addressing Action was not recognized. Unable to process request." );
+ "No SOAP Body elements were defined, and the value
of the WS-Addressing Action header was not recognized - unable to dispatch
request." );
}
}
else // childElems.length == 1
@@ -319,25 +320,30 @@
private void validateRequestXml( XmlObject requestXBean )
{
- boolean validateRequestXml = Boolean.valueOf( getHandlerOption(
HANDLER_OPT_VALIDATE_REQUEST_XML, "true" ) ).booleanValue();
- if ( validateRequestXml )
+ boolean validateRequestXml = Boolean.valueOf( getHandlerOption(
HANDLER_OPT_VALIDATE_REQUEST_XML, "true" ) )
+ .booleanValue();
+ if ( validateRequestXml && ! ( requestXBean instanceof XmlAnyTypeImpl
) )
{
XmlOptions validateOptions = new XmlOptions();
List errorList = new ArrayList();
- validateOptions.setErrorListener(errorList);
- boolean isValid = requestXBean.validate(validateOptions);
- if (!isValid)
- {
- StringBuffer strBuf = new StringBuffer( "Request body element
" );
- strBuf.append( XmlBeanUtils.getName( requestXBean ) );
- strBuf.append( " is not valid as per its schema: \n" );
- for (int i = 0; i < errorList.size(); i++)
- {
- strBuf.append( " o " );
- strBuf.append( errorList.get(i) );
- strBuf.append( "\n" );
- }
- throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
strBuf.toString() );
+ validateOptions.setErrorListener( errorList );
+ boolean isValid = requestXBean.validate( validateOptions );
+ if ( !isValid )
+ {
+ QName bodyElemName = XmlBeanUtils.getName( requestXBean );
+ StringBuffer strBuf = new StringBuffer( "Request body element
" );
+ strBuf.append( toString( bodyElemName ) );
+ strBuf.append( " is not valid as per its schema: \n\n" );
+ for ( int i = 0; i < errorList.size(); i++ )
+ {
+ strBuf.append( "\t\t" );
+ strBuf.append( i + 1 );
+ strBuf.append( ") " );
+ strBuf.append( errorList.get( i ) );
+ strBuf.append( "\n" );
+ }
+ strBuf.append( "\n" );
+ throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
strBuf.toString() );
}
}
}
@@ -440,7 +446,7 @@
if ( serviceMethod == null )
{
- throw new JAXRPCException( MSG.getMessage(
Keys.UNABLE_TO_FIND_METHOD_IN_SERVICE,
+ throw new JAXRPCException( MSG.getMessage(
Keys.BAD_REQUEST_BODY_ELEMENT,
methodNameFromAction,
service.getClass().getName() ) );
}
@@ -513,69 +519,63 @@
private Method getServiceMethod( WsrfService service,
XmlObject requestXBean )
{
+ QName bodyElemName = XmlBeanUtils.getName( requestXBean );
if ( LOG.isDebugEnabled() )
{
- LOG.debug( MSG.getMessage( Keys.DERIVE_SERVICE_NAME_FROM_REQ,
- requestXBean.toString() ) );
+ LOG.debug( MSG.getMessage( Keys.DERIVE_SERVICE_NAME_FROM_REQ,
toString( bodyElemName ) ) );
}
-
- Method serviceMethod = null;
- String serviceMethodName =
- service.getMethodNameMap().getMethodName(
XmlBeanUtils.getName( requestXBean ) );
- serviceMethod = getServiceMethod( service, serviceMethodName,
requestXBean );
-
- return serviceMethod;
+ String serviceMethodName = service.getMethodNameMap().getMethodName(
bodyElemName );
+ return getServiceMethod( service, serviceMethodName, requestXBean );
}
/**
* Method used to locate a Method object in a Service based on the method
name and param
*
* @param service
- * @param serviceMethodName
- * @param requestXBean
+ * @param methodName
+ * @param param
*
* @return
*/
- private Method getServiceMethod( WsrfService service, String
serviceMethodName, XmlObject requestXBean )
+ private Method getServiceMethod( WsrfService service, String methodName,
XmlObject param )
{
Method serviceMethod = null;
- LOG.debug( "Based on the request, looking for method named: " +
serviceMethodName + " in service " +
+ LOG.debug( "Based on the request, looking for method named: " +
methodName + " in service " +
service.getClass().getName() +
" with " +
1 +
" param type called: " +
- requestXBean ==
+ param ==
null ?
- "null" : requestXBean.getClass().getName() );
+ "null" : param.getClass().getName() );
Method[] methods = service.getClass().getMethods();
for ( int i = 0; i < methods.length; i++ )
{
Method method = methods[i];
- if ( method.getName().equals( serviceMethodName ) )
+ if ( method.getName().equals( methodName ) )
{
if ( method.getParameterTypes().length == 1 )
{
- if ( method.getParameterTypes()[0].isInstance(
requestXBean ) ) //todo check if handles null
+ if ( method.getParameterTypes()[0].isInstance( param ) )
//todo check if handles null
{
-
serviceMethod = method;
break;
}
else
{
- LOG.warn( "Found method named: " + serviceMethodName +
" in service " +
+ LOG.warn( "Found method named: " + methodName + " in
service " +
service.getClass().getName() +
" with " +
1 +
" param of type: " +
method.getParameterTypes()[0].getName() +
" , however the request param was: " +
- requestXBean.getClass().getName() );
+ param.getClass().getName() );
}
}
else
{
- LOG.warn( "Found method named: " + serviceMethodName + "
in service " +
+ LOG.warn( "Found method named: " + methodName + " in
service " +
service.getClass().getName() +
" with " +
method.getParameterTypes().length +
@@ -583,19 +583,27 @@
}
}
}
-
- if ( serviceMethod == null )
+ if ( serviceMethod == null ) // method not found
{
- throw new JAXRPCException( MSG.getMessage(
Keys.UNABLE_TO_FIND_METHOD_IN_SERVICE,
- serviceMethodName,
- service.getClass().getName() ) );
+ QName bodyElemName = XmlBeanUtils.getName( param );
+ throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
MSG.getMessage( Keys.BAD_REQUEST_BODY_ELEMENT, toString( bodyElemName ) ) );
}
-
- LOG.debug( MSG.getMessage( Keys.FOUND_SERVICE_METHOD,
- serviceMethod.getName() ) );
+ LOG.debug( MSG.getMessage( Keys.FOUND_SERVICE_METHOD,
serviceMethod.getName() ) );
return serviceMethod;
}
+ private static String toString( QName name )
+ {
+ StringBuffer strBuf = new StringBuffer();
+ strBuf.append( name.getLocalPart() );
+ if ( name.getNamespaceURI() != null )
+ {
+ strBuf.append( "@" );
+ strBuf.append( name.getNamespaceURI() );
+ }
+ return strBuf.toString();
+ }
+
private SOAPMessage createSOAPMessage()
{
try
@@ -629,7 +637,7 @@
private String getHandlerOption( String optionName, String defaultValue )
{
- Object value = m_handlerOptions.get( optionName );
+ Object value = m_handlerOptions != null ? m_handlerOptions.get(
optionName ) : null;
return value != null ? value.toString() : defaultValue;
}
}
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/GenericAxisHandler.java
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/GenericAxisHandler.java?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
---
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/GenericAxisHandler.java
(original)
+++
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/GenericAxisHandler.java
Thu May 19 17:02:37 2005
@@ -19,51 +19,64 @@
import org.apache.axis.handlers.BasicHandler;
import javax.xml.rpc.handler.Handler;
+import javax.xml.rpc.handler.HandlerInfo;
+import javax.xml.namespace.QName;
/**
- * LOG-DONE
+ * TODO
+ *
* @author Ian Springer
*/
public class GenericAxisHandler
- extends BasicHandler
+ extends BasicHandler
{
- private Handler jaxRpcHandler;
+ private Handler jaxRpcHandler;
- /**
- * Creates a new [EMAIL PROTECTED] GenericAxisHandler} object.
- *
- * @param handler DOCUMENT_ME
- */
- public GenericAxisHandler( Handler handler )
- {
- jaxRpcHandler = handler;
- }
+ /**
+ * Creates a new [EMAIL PROTECTED] GenericAxisHandler} object.
+ *
+ * @param handler DOCUMENT_ME
+ */
+ public GenericAxisHandler( Handler handler )
+ {
+ jaxRpcHandler = handler;
+ }
- /**
- * Impl of [EMAIL PROTECTED]
org.apache.axis.Handler#invoke(org.apache.axis.MessageContext)} that delegates
to either JAX-RPC
- * [EMAIL PROTECTED]
Handler#handleRequest(javax.xml.rpc.handler.MessageContext)} or JAX-RPC [EMAIL
PROTECTED]
- * Handler#handleResponse(javax.xml.rpc.handler.MessageContext)}, depending
upon whether the handler chain pivot has
- * been passed yet or not.
- */
- public void invoke( org.apache.axis.MessageContext msgContext )
- throws AxisFault
- {
- if ( !msgContext.getPastPivot( ) )
- {
- jaxRpcHandler.handleRequest( msgContext );
- }
- else
- {
- jaxRpcHandler.handleResponse( msgContext );
- }
- }
+ /**
+ * Impl of [EMAIL PROTECTED] org.apache.axis.Handler#init()} that
delegates to JAX-RPC
+ * [EMAIL PROTECTED] Handler#init(javax.xml.rpc.handler.HandlerInfo)}.
+ */
+ public void init()
+ {
+ HandlerInfo handlerInfo = new HandlerInfo( jaxRpcHandler.getClass(),
getOptions(), new QName[0] );
+ jaxRpcHandler.init( handlerInfo );
+ }
- /**
- * Impl of [EMAIL PROTECTED]
org.apache.axis.Handler#onFault(org.apache.axis.MessageContext)} that delegates
to JAX-RPC [EMAIL PROTECTED]
- * Handler#handleFault(javax.xml.rpc.handler.MessageContext)}.
- */
- public void onFault( org.apache.axis.MessageContext msgContext )
- {
- jaxRpcHandler.handleFault( msgContext );
- }
+ /**
+ * Impl of [EMAIL PROTECTED]
org.apache.axis.Handler#invoke(org.apache.axis.MessageContext)} that delegates
to either JAX-RPC
+ * [EMAIL PROTECTED]
Handler#handleRequest(javax.xml.rpc.handler.MessageContext)} or JAX-RPC [EMAIL
PROTECTED]
+ * Handler#handleResponse(javax.xml.rpc.handler.MessageContext)},
depending upon whether the handler chain pivot has
+ * been passed yet or not.
+ */
+ public void invoke( org.apache.axis.MessageContext msgContext )
+ throws AxisFault
+ {
+ if ( !msgContext.getPastPivot() )
+ {
+ jaxRpcHandler.handleRequest( msgContext );
+ }
+ else
+ {
+ jaxRpcHandler.handleResponse( msgContext );
+ }
+ }
+
+ /**
+ * Impl of [EMAIL PROTECTED]
org.apache.axis.Handler#onFault(org.apache.axis.MessageContext)} that delegates
to JAX-RPC [EMAIL PROTECTED]
+ * Handler#handleFault(javax.xml.rpc.handler.MessageContext)}.
+ */
+ public void onFault( org.apache.axis.MessageContext msgContext )
+ {
+ jaxRpcHandler.handleFault( msgContext );
+ }
}
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProvider.java
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProvider.java?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
---
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProvider.java
(original)
+++
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProvider.java
Thu May 19 17:02:37 2005
@@ -37,6 +37,7 @@
import javax.xml.namespace.QName;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
+import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.soap.SOAPFaultException;
import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
@@ -50,7 +51,7 @@
/**
* LOG-DONE Axis provider that dispatches requests to WS-Resources.
*
- * @author Ian P. Springer, Sal Campana
+ * @author Ian Springer, Sal Campana
*/
public class ResourceProvider
extends ResourceHandler
@@ -60,6 +61,12 @@
public static final Messages MSG = MessagesImpl.getInstance();
private GenericAxisHandler m_axisHelperHandler = new GenericAxisHandler(
this );
+ public void init()
+ {
+ m_axisHelperHandler.setOptions( getOptions() );
+ m_axisHelperHandler.init();
+ }
+
/**
* DOCUMENT_ME
*
@@ -179,14 +186,6 @@
SOAPService service = msgContext.getService();
LOG.debug( MSG.getMessage( Keys.RECEIVED_WSDL_REQUEST,
service.getName() ) );
service.generateWSDL( msgContext );
- }
-
- /**
- * DOCUMENT_ME
- */
- public void init()
- {
- m_axisHelperHandler.init();
}
/**
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProviderFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProviderFactory.java?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
---
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProviderFactory.java
(original)
+++
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/ResourceProviderFactory.java
Thu May 19 17:02:37 2005
@@ -21,26 +21,26 @@
import org.apache.axis.deployment.wsdd.WSDDService;
/**
- * LOG-DONE
- * A WSRF Wsdd Provider Factory for use in Axis.
- * [EMAIL PROTECTED] WSDDProvider}
+ * An Axis [EMAIL PROTECTED] WSDDProvider} that acts as a factory for [EMAIL
PROTECTED] ResourceProvider}
+ * instances.
*
- * @author Sal Campana
+ * @author Sal Campana, Ian Springer
*/
public class ResourceProviderFactory
extends WSDDProvider
{
+
/**
- * Provider Name for use in the servier-config.wsdd file (i.e.
provider="java:WSRF")
+ * Provider Name for use in the server-config.wsdd file (e.g.
provider="java:WSRF").
*/
- public static final String PROVIDER_WSRF = "WSRF";
+ public static final String PROVIDER_NAME = "WSRF";
/**
* @see WSDDProvider#getName()
*/
public String getName( )
{
- return PROVIDER_WSRF;
+ return PROVIDER_NAME;
}
/**
@@ -50,6 +50,10 @@
EngineConfiguration registry )
throws Exception
{
- return new ResourceProvider( );
+ ResourceProvider resourceProvider = new ResourceProvider();
+ resourceProvider.setOptions( System.getProperties() );
+ resourceProvider.init();
+ return resourceProvider;
}
+
}
Modified:
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/WsrfAxisServlet.java
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/WsrfAxisServlet.java?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
---
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/WsrfAxisServlet.java
(original)
+++
incubator/apollo/trunk/src/java/org/apache/ws/resource/handler/axis/WsrfAxisServlet.java
Thu May 19 17:02:37 2005
@@ -28,9 +28,10 @@
/**
* LOG-DONE
* Extension to Axis servlet used to initialize and destroy the registration
manager, which manages WS-Resources.
+ * TODO: Make this a separate servlet, so it's platform-independent - no
reason to extend AxisServlet.
*
* @author Sal Campana
- * @author Ian P. Springer
+ * @author Ian Springer
*/
public class WsrfAxisServlet
extends AxisServlet
Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java
URL:
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java?rev=171023&r1=171022&r2=171023&view=diff
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java
(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/i18n/Keys.java Thu
May 19 17:02:37 2005
@@ -187,19 +187,19 @@
String RETRIEVED_SERVICE_CLASSNAME = "RETRIEVED_SERVICE_CLASSNAME";
/**
- * @msg {0} :service param not defined in resource home.
+ * @msg {0}: service param not defined in resource home.
*/
String SERVICE_OPT_UNDEFINED_IN_HOME = "SERVICE_OPT_UNDEFINED_IN_HOME";
/**
- * @msg Deriving the service method name from the request: {0}
+ * @msg Deriving the service method name from the request body element
name ({0})...
*/
String DERIVE_SERVICE_NAME_FROM_REQ = "DERIVE_SERVICE_NAME_FROM_REQ";
/**
- * @msg Unable to find method {0} with valid signature in service class
{1}.
+ * @msg Unrecognized request body element: {0}
*/
- String UNABLE_TO_FIND_METHOD_IN_SERVICE =
"UNABLE_TO_FIND_METHOD_IN_SERVICE";
+ String BAD_REQUEST_BODY_ELEMENT = "BAD_REQUEST_BODY_ELEMENT";
/**
* @msg Found service method: {0}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]