[jboss-svn-commits] JBossWS SVN: r694 - in trunk: . src/main/java/org/jboss/ws/integration/jboss src/main/java/org/jboss/ws/jaxws src/main/java/org/jboss/ws/server src/test/java/org/jboss/test/ws/jaxws/context src/test/java/org/jboss/test/ws/samples/wsaddressing
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 4 12:27:31 EDT 2006
Author: thomas.diesler at jboss.com
Date: 2006-08-04 12:27:13 -0400 (Fri, 04 Aug 2006)
New Revision: 694
Added:
trunk/src/main/java/org/jboss/ws/jaxws/WebServiceContextImpl.java
trunk/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java
trunk/src/main/java/org/jboss/ws/server/MessageContextInjector.java
Removed:
trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerBase.java
Modified:
trunk/build-thirdparty.xml
trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB21.java
trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB3.java
trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerMDB.java
trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java
trunk/src/test/java/org/jboss/test/ws/jaxws/context/EndpointBean.java
trunk/src/test/java/org/jboss/test/ws/jaxws/context/WebServiceContextTestCase.java
trunk/src/test/java/org/jboss/test/ws/samples/wsaddressing/StatefulEndpointImpl.java
Log:
WebServiceContext injection
Modified: trunk/build-thirdparty.xml
===================================================================
--- trunk/build-thirdparty.xml 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/build-thirdparty.xml 2006-08-04 16:27:13 UTC (rev 694)
@@ -94,6 +94,7 @@
<pathelement location="${jboss.server.lib}/jboss-jaxrpc.jar"/>
<pathelement location="${jboss.server.lib}/jboss-saaj.jar"/>
<pathelement location="${jboss.server.deploy}/ejb3.deployer/jboss-annotations-ejb3.jar"/>
+ <pathelement location="${jboss.server.deploy}/ejb3.deployer/jboss-ejb3x.jar"/>
</path>
<!-- The classpath for the jboss integration -->
@@ -108,7 +109,6 @@
<pathelement location="${jboss.server.deploy}/jboss-aop-jdk50.deployer/jboss-aspect-library-jdk50.jar"/>
<pathelement location="${jboss.server.deploy}/ejb3.deployer/jboss-annotations-ejb3.jar"/>
<pathelement location="${jboss.server.deploy}/ejb3.deployer/jboss-ejb3.jar"/>
- <pathelement location="${jboss.server.deploy}/ejb3.deployer/jboss-ejb3x.jar"/>
</path>
</target>
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB21.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB21.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB21.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -50,7 +50,7 @@
import org.jboss.ws.metadata.j2ee.UnifiedHandlerMetaData.HandlerType;
import org.jboss.ws.server.ServiceEndpointInfo;
import org.jboss.ws.server.ServiceEndpointInvoker;
-import org.jboss.ws.server.ServiceEndpointInvokerBase;
+import org.jboss.ws.server.AbstractServiceEndpointInvoker;
import org.jboss.ws.soap.MessageContextAssociation;
import org.jboss.ws.utils.ObjectNameFactory;
@@ -60,7 +60,7 @@
* @author Thomas.Diesler at jboss.org
* @since 19-Jan-2005
*/
-public class ServiceEndpointInvokerEJB21 extends ServiceEndpointInvokerBase implements ServiceEndpointInvoker
+public class ServiceEndpointInvokerEJB21 extends AbstractServiceEndpointInvoker implements ServiceEndpointInvoker
{
// provide logging
private Logger log = Logger.getLogger(ServiceEndpointInvokerEJB21.class);
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB3.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB3.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerEJB3.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -38,7 +38,7 @@
import org.jboss.ws.deployment.UnifiedDeploymentInfo;
import org.jboss.ws.server.ServiceEndpointInfo;
import org.jboss.ws.server.ServiceEndpointInvoker;
-import org.jboss.ws.server.ServiceEndpointInvokerBase;
+import org.jboss.ws.server.AbstractServiceEndpointInvoker;
import org.jboss.ws.utils.ObjectNameFactory;
/**
@@ -47,7 +47,7 @@
* @author Thomas.Diesler at jboss.org
* @since 23-Jul-2005
*/
-public class ServiceEndpointInvokerEJB3 extends ServiceEndpointInvokerBase implements ServiceEndpointInvoker
+public class ServiceEndpointInvokerEJB3 extends AbstractServiceEndpointInvoker implements ServiceEndpointInvoker
{
// provide logging
private Logger log = Logger.getLogger(ServiceEndpointInvokerEJB3.class);
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerMDB.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerMDB.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/main/java/org/jboss/ws/integration/jboss/ServiceEndpointInvokerMDB.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -31,7 +31,7 @@
import org.jboss.ws.binding.EndpointInvocation;
import org.jboss.ws.server.ServiceEndpointInfo;
import org.jboss.ws.server.ServiceEndpointInvoker;
-import org.jboss.ws.server.ServiceEndpointInvokerBase;
+import org.jboss.ws.server.AbstractServiceEndpointInvoker;
import org.jboss.ws.utils.ThreadLocalAssociation;
/**
@@ -40,7 +40,7 @@
* @author Thomas.Diesler at jboss.org
* @since 21-Mar-2006
*/
-public class ServiceEndpointInvokerMDB extends ServiceEndpointInvokerBase implements ServiceEndpointInvoker
+public class ServiceEndpointInvokerMDB extends AbstractServiceEndpointInvoker implements ServiceEndpointInvoker
{
// provide logging
private Logger log = Logger.getLogger(ServiceEndpointInvokerMDB.class);
Added: trunk/src/main/java/org/jboss/ws/jaxws/WebServiceContextImpl.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/jaxws/WebServiceContextImpl.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/main/java/org/jboss/ws/jaxws/WebServiceContextImpl.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.jaxws;
+
+import java.security.Principal;
+
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.util.NotImplementedException;
+
+/**
+ * A WebServiceContext makes it possible for a web service endpoint implementation
+ * class to access message context and security information relative to a request
+ * being served. Typically a WebServiceContext is injected into an endpoint implementation
+ * class using the Resource annotation.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 03-May-2006
+ */
+public class WebServiceContextImpl implements WebServiceContext
+{
+ private MessageContext messageContext;
+
+
+ public WebServiceContextImpl(MessageContext messageContext)
+ {
+ this.messageContext = messageContext;
+ }
+
+ public MessageContext getMessageContext()
+ {
+ return messageContext;
+ }
+
+ public Principal getUserPrincipal()
+ {
+ throw new NotImplementedException();
+ }
+
+ public boolean isUserInRole(String role)
+ {
+ throw new NotImplementedException();
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/java/org/jboss/ws/jaxws/WebServiceContextImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java (from rev 691, trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerBase.java)
===================================================================
--- trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerBase.java 2006-08-04 14:30:52 UTC (rev 691)
+++ trunk/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -0,0 +1,301 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.server;
+
+// $Id$
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.management.MBeanException;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.soap.SOAPFaultException;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
+import org.jboss.ws.binding.BindingProvider;
+import org.jboss.ws.binding.BindingProviderRegistry;
+import org.jboss.ws.binding.EndpointInvocation;
+import org.jboss.ws.common.SOAPMessageContextBase;
+import org.jboss.ws.jaxrpc.HandlerDelegateJAXRPC;
+import org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper;
+import org.jboss.ws.jaxws.HandlerDelegateJAXWS;
+import org.jboss.ws.metadata.EndpointMetaData;
+import org.jboss.ws.metadata.OperationMetaData;
+import org.jboss.ws.metadata.EndpointMetaData.Type;
+import org.jboss.ws.metadata.j2ee.UnifiedHandlerMetaData.HandlerType;
+import org.jboss.ws.soap.MessageContextAssociation;
+import org.jboss.ws.soap.SOAPMessageImpl;
+import org.jboss.ws.utils.JavaUtils;
+
+/** An implementation handles invocations on the endpoint
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 19-Jan-2005
+ */
+public abstract class AbstractServiceEndpointInvoker implements ServiceEndpointInvoker, HandlerDelegate
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(AbstractServiceEndpointInvoker.class);
+
+ protected HandlerDelegate handlerDelegate;
+ private HandlerType handlerType;
+
+ /** Initialize the service endpoint */
+ public void initServiceEndpoint(ServiceEndpointInfo seInfo)
+ {
+ Type type = seInfo.getServerEndpointMetaData().getType();
+ if (type == EndpointMetaData.Type.JAXRPC)
+ {
+ handlerDelegate = new HandlerDelegateJAXRPC();
+ handlerType = HandlerType.JAXRPC;
+ }
+ else
+ {
+ handlerDelegate = new HandlerDelegateJAXWS();
+ handlerType = HandlerType.JAXWS;
+ }
+ }
+
+ /** Load the SEI implementation bean if necessary */
+ protected abstract Class loadServiceEndpoint(ServiceEndpointInfo seInfo) throws ClassNotFoundException;
+
+ /** Create the instance of the SEI implementation bean if necessary */
+ protected abstract Object createServiceEndpoint(ServiceEndpointInfo seInfo, Object context, Class seiImplClass) throws IllegalAccessException, InstantiationException;
+
+ /** Invoke the instance of the SEI implementation bean */
+ protected abstract void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl, EndpointInvocation epInv);
+
+ /** Destroy the instance of the SEI implementation bean if necessary */
+ protected abstract void destroyServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl);
+
+ public boolean callRequestHandlerChain(ServiceEndpointInfo seInfo, HandlerType type)
+ {
+ return handlerDelegate.callRequestHandlerChain(seInfo, type);
+ }
+
+ public boolean callResponseHandlerChain(ServiceEndpointInfo seInfo, HandlerType type)
+ {
+ return handlerDelegate.callResponseHandlerChain(seInfo, type);
+ }
+
+ public boolean callFaultHandlerChain(ServiceEndpointInfo seInfo, HandlerType type, Exception ex)
+ {
+ return handlerDelegate.callFaultHandlerChain(seInfo, type, ex);
+ }
+
+ /** Invoke the the service endpoint */
+ public SOAPMessage invoke(ServiceEndpointInfo seInfo, Object context) throws Exception
+ {
+ SOAPMessageContextBase msgContext = MessageContextAssociation.peekMessageContext();
+ EndpointMetaData epMetaData = msgContext.getEndpointMetaData();
+ SOAPMessageImpl reqMessage = (SOAPMessageImpl)msgContext.getMessage();
+
+ // Load the endpoint implementation bean
+ Class seImpl = loadServiceEndpoint(seInfo);
+
+ // Create an instance of the endpoint implementation bean
+ Object seInstance = createServiceEndpoint(seInfo, context, seImpl);
+
+ try
+ {
+ boolean oneway = false;
+
+ // call the handler chain
+ boolean handlersPass = callRequestHandlerChain(seInfo, HandlerType.PRE);
+ handlersPass = handlersPass && callRequestHandlerChain(seInfo, handlerType);
+ handlersPass = handlersPass && callRequestHandlerChain(seInfo, HandlerType.POST);
+
+ if (handlersPass)
+ {
+ // Get the binding provider for the given bindingURI
+ BindingProvider bindingProvider;
+ if (epMetaData.getServiceMode() == Mode.MESSAGE)
+ {
+ bindingProvider = BindingProviderRegistry.getProvider(BindingProvider.JAXWS_MESSAGE_BINDING);
+ }
+ else if (epMetaData.getServiceMode() == Mode.PAYLOAD)
+ {
+ bindingProvider = BindingProviderRegistry.getProvider(BindingProvider.JAXWS_PAYLOAD_BINDING);
+ }
+ else
+ {
+ bindingProvider = BindingProviderRegistry.getDefaultProvider();
+ }
+
+ // Get the operation meta data from the SOAP message
+ OperationMetaData opMetaData = getDispatchDestination(epMetaData, reqMessage);
+ msgContext.setOperationMetaData(opMetaData);
+ oneway = opMetaData.isOneWayOperation();
+
+ // Unbind the request message
+ EndpointInvocation epInv = bindingProvider.unbindRequestMessage(opMetaData, reqMessage);
+
+ // Invoke the service endpoint
+ invokeServiceEndpoint(seInfo, seInstance, epInv);
+
+ // Set the outbound property
+ if (epMetaData.getType() == EndpointMetaData.Type.JAXWS)
+ msgContext.setProperty(MessageContext.MESSAGE_OUTBOUND_PROPERTY, new Boolean(true));
+
+ // Bind the response message
+ SOAPMessage resMessage = bindingProvider.bindResponseMessage(opMetaData, epInv);
+ msgContext.setMessage(resMessage);
+ }
+
+ // call the handler chain
+ if (oneway == false)
+ {
+ handlersPass = callResponseHandlerChain(seInfo, HandlerType.POST);
+ handlersPass = handlersPass && callResponseHandlerChain(seInfo, handlerType);
+ handlersPass = handlersPass && callResponseHandlerChain(seInfo, HandlerType.PRE);
+ }
+
+ SOAPMessage resMessage = msgContext.getMessage();
+ return resMessage;
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ SOAPMessage faultMessage = SOAPFaultExceptionHelper.exceptionToFaultMessage(ex);
+ msgContext.setMessage(faultMessage);
+
+ // call the handler chain
+ boolean handlersPass = handlerDelegate.callFaultHandlerChain(seInfo, HandlerType.POST, ex);
+ handlersPass = handlersPass && handlerDelegate.callFaultHandlerChain(seInfo, handlerType, ex);
+ handlersPass = handlersPass && handlerDelegate.callFaultHandlerChain(seInfo, HandlerType.PRE, ex);
+ }
+ catch (Exception subEx)
+ {
+ log.warn("Cannot process handlerChain.handleFault, ignoring: ", subEx);
+ }
+ throw ex;
+ }
+ finally
+ {
+ destroyServiceEndpoint(seInfo, seInstance);
+ }
+ }
+
+ private OperationMetaData getDispatchDestination(EndpointMetaData epMetaData, SOAPMessageImpl reqMessage) throws SOAPException
+ {
+ OperationMetaData opMetaData = reqMessage.getOperationMetaData(epMetaData);
+ SOAPHeader soapHeader = reqMessage.getSOAPHeader();
+
+ // Report a MustUnderstand fault
+ if (opMetaData == null)
+ {
+ SOAPBody soapBody = reqMessage.getSOAPBody();
+ SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
+ Name soapName = soapBodyElement.getElementName();
+
+ // R2724 If an INSTANCE receives a message that is inconsistent with its WSDL description, it SHOULD generate a soap:Fault
+ // with a faultcode of "Client", unless a "MustUnderstand" or "VersionMismatch" fault is generated.
+ if (soapHeader != null && soapHeader.examineMustUnderstandHeaderElements(Constants.URI_SOAP11_NEXT_ACTOR).hasNext())
+ {
+ QName faultCode = Constants.SOAP11_FAULT_CODE_MUST_UNDERSTAND;
+ String faultString = "Endpoint " + epMetaData.getQName() + " does not contain operation meta data for: " + soapName;
+ throw new SOAPFaultException(faultCode, faultString, null, null);
+ }
+ else
+ {
+ QName faultCode = Constants.SOAP11_FAULT_CODE_CLIENT;
+ String faultString = "Endpoint " + epMetaData.getQName() + " does not contain operation meta data for: " + soapName;
+ throw new SOAPFaultException(faultCode, faultString, null, null);
+ }
+ }
+ return opMetaData;
+ }
+
+ protected Method getImplMethod(Class implClass, Method seiMethod) throws ClassNotFoundException, NoSuchMethodException
+ {
+ String methodName = seiMethod.getName();
+ Class[] paramTypes = seiMethod.getParameterTypes();
+ for (int i = 0; i < paramTypes.length; i++)
+ {
+ Class paramType = paramTypes[i];
+ if (JavaUtils.isPrimitive(paramType) == false)
+ {
+ String paramTypeName = paramType.getName();
+ paramType = JavaUtils.loadJavaType(paramTypeName);
+ paramTypes[i] = paramType;
+ }
+ }
+
+ Method implMethod = implClass.getMethod(methodName, paramTypes);
+ return implMethod;
+ }
+
+ /** handle invokation exceptions */
+ public void handleInvocationException(Throwable th) throws SOAPFaultException
+ {
+ if (th instanceof RuntimeException)
+ throw (RuntimeException)th;
+
+ if (th instanceof InvocationTargetException)
+ {
+ InvocationTargetException targetException = (InvocationTargetException)th;
+ Throwable targetEx = targetException.getTargetException();
+ if (targetEx instanceof SOAPFaultException)
+ {
+ throw (SOAPFaultException)targetEx;
+ }
+ else
+ {
+ String faultString = targetEx.toString();
+ SOAPFaultException soapFaultEx = new SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
+ soapFaultEx.initCause(targetEx);
+ throw soapFaultEx;
+ }
+ }
+
+ if (th instanceof MBeanException)
+ {
+ Exception targetEx = ((MBeanException)th).getTargetException();
+ if (targetEx instanceof SOAPFaultException)
+ {
+ throw (SOAPFaultException)targetEx;
+ }
+ else
+ {
+ String faultString = targetEx.toString();
+ SOAPFaultException soapFaultEx = new SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
+ soapFaultEx.initCause(targetEx);
+ throw soapFaultEx;
+ }
+ }
+
+ String faultString = th.toString();
+ SOAPFaultException soapFaultEx = new SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
+ soapFaultEx.initCause(th);
+ throw soapFaultEx;
+ }
+}
Added: trunk/src/main/java/org/jboss/ws/server/MessageContextInjector.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/server/MessageContextInjector.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/main/java/org/jboss/ws/server/MessageContextInjector.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.server;
+
+// $Id: $
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.annotation.Resource;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.jaxws.WebServiceContextImpl;
+
+/**
+ * Inject the JAXWS WebServiceContext
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 04-Jan-2006
+ */
+public class MessageContextInjector
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(MessageContextInjector.class);
+
+ public static void injectMessageContext(Object epImpl, MessageContext msgContext)
+ {
+ WebServiceContextImpl webServiceContext = new WebServiceContextImpl(msgContext);
+
+ try
+ {
+ // scan fields that are marked with @Resource
+ Field[] fields = epImpl.getClass().getFields();
+ for (Field field : fields)
+ {
+ Class type = field.getType();
+ if (type == WebServiceContext.class && field.isAnnotationPresent(Resource.class))
+ {
+ field.set(epImpl, webServiceContext);
+ }
+ }
+
+ // scan methods that are marked with @Resource
+ Method[] methods = epImpl.getClass().getMethods();
+ for (Method method : methods)
+ {
+ Class[] paramTypes = method.getParameterTypes();
+ if (paramTypes.length == 1 && paramTypes[0] == WebServiceContext.class && method.isAnnotationPresent(Resource.class))
+ {
+ method.invoke(epImpl, new Object[] { webServiceContext });
+
+ }
+ }
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ log.warn("Cannot inject WebServiceContext", ex);
+ }
+ }
+}
Property changes on: trunk/src/main/java/org/jboss/ws/server/MessageContextInjector.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerBase.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerBase.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerBase.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -1,293 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ws.server;
-
-// $Id$
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import javax.management.MBeanException;
-import javax.xml.namespace.QName;
-import javax.xml.rpc.soap.SOAPFaultException;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPBodyElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPHeader;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.ws.Service.Mode;
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.Constants;
-import org.jboss.ws.binding.BindingProvider;
-import org.jboss.ws.binding.BindingProviderRegistry;
-import org.jboss.ws.binding.EndpointInvocation;
-import org.jboss.ws.common.SOAPMessageContextBase;
-import org.jboss.ws.jaxrpc.HandlerDelegateJAXRPC;
-import org.jboss.ws.jaxrpc.SOAPFaultExceptionHelper;
-import org.jboss.ws.jaxws.HandlerDelegateJAXWS;
-import org.jboss.ws.metadata.EndpointMetaData;
-import org.jboss.ws.metadata.OperationMetaData;
-import org.jboss.ws.metadata.EndpointMetaData.Type;
-import org.jboss.ws.metadata.j2ee.UnifiedHandlerMetaData.HandlerType;
-import org.jboss.ws.soap.MessageContextAssociation;
-import org.jboss.ws.soap.SOAPMessageImpl;
-import org.jboss.ws.utils.JavaUtils;
-
-/** An implementation handles invocations on the endpoint
- *
- * @author Thomas.Diesler at jboss.org
- * @since 19-Jan-2005
- */
-public abstract class ServiceEndpointInvokerBase implements ServiceEndpointInvoker, HandlerDelegate
-{
- // provide logging
- private static Logger log = Logger.getLogger(ServiceEndpointInvokerBase.class);
-
- protected HandlerDelegate handlerDelegate;
-
- /** Initialize the service endpoint */
- public void initServiceEndpoint(ServiceEndpointInfo seInfo)
- {
- Type type = seInfo.getServerEndpointMetaData().getType();
- if (type == EndpointMetaData.Type.JAXRPC)
- {
- handlerDelegate = new HandlerDelegateJAXRPC();
- }
- else
- {
- handlerDelegate = new HandlerDelegateJAXWS();
- }
- }
-
- /** Load the SEI implementation bean if necessary */
- protected abstract Class loadServiceEndpoint(ServiceEndpointInfo seInfo) throws ClassNotFoundException;
-
- /** Create the instance of the SEI implementation bean if necessary */
- protected abstract Object createServiceEndpoint(ServiceEndpointInfo seInfo, Object context, Class seiImplClass) throws IllegalAccessException, InstantiationException;
-
- /** Invoke the instance of the SEI implementation bean */
- protected abstract void invokeServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl, EndpointInvocation epInv);
-
- /** Destroy the instance of the SEI implementation bean if necessary */
- protected abstract void destroyServiceEndpoint(ServiceEndpointInfo seInfo, Object seiImpl);
-
- public boolean callRequestHandlerChain(ServiceEndpointInfo seInfo, HandlerType type)
- {
- return handlerDelegate.callRequestHandlerChain(seInfo, type);
- }
-
- public boolean callResponseHandlerChain(ServiceEndpointInfo seInfo, HandlerType type)
- {
- return handlerDelegate.callResponseHandlerChain(seInfo, type);
- }
-
- public boolean callFaultHandlerChain(ServiceEndpointInfo seInfo, HandlerType type, Exception ex)
- {
- return handlerDelegate.callFaultHandlerChain(seInfo, type, ex);
- }
-
- /** Invoke the the service endpoint */
- public SOAPMessage invoke(ServiceEndpointInfo seInfo, Object context) throws Exception
- {
- SOAPMessageContextBase msgContext = MessageContextAssociation.peekMessageContext();
- EndpointMetaData epMetaData = msgContext.getEndpointMetaData();
- SOAPMessageImpl reqMessage = (SOAPMessageImpl)msgContext.getMessage();
-
- // Load the endpoint implementation bean
- Class seImpl = loadServiceEndpoint(seInfo);
-
- // Create an instance of the endpoint implementation bean
- Object seInstance = createServiceEndpoint(seInfo, context, seImpl);
-
- try
- {
- boolean oneway = false;
-
- // call the handler chain
- boolean handlersPass = callRequestHandlerChain(seInfo, HandlerType.PRE);
- handlersPass = handlersPass && callRequestHandlerChain(seInfo, HandlerType.JAXRPC);
- handlersPass = handlersPass && callRequestHandlerChain(seInfo, HandlerType.POST);
-
- if (handlersPass)
- {
- // Get the binding provider for the given bindingURI
- BindingProvider bindingProvider;
- if (epMetaData.getServiceMode() == Mode.MESSAGE)
- {
- bindingProvider = BindingProviderRegistry.getProvider(BindingProvider.JAXWS_MESSAGE_BINDING);
- }
- else if (epMetaData.getServiceMode() == Mode.PAYLOAD)
- {
- bindingProvider = BindingProviderRegistry.getProvider(BindingProvider.JAXWS_PAYLOAD_BINDING);
- }
- else
- {
- bindingProvider = BindingProviderRegistry.getDefaultProvider();
- }
-
- // Get the operation meta data from the SOAP message
- OperationMetaData opMetaData = getDispatchDestination(epMetaData, reqMessage);
- msgContext.setOperationMetaData(opMetaData);
- oneway = opMetaData.isOneWayOperation();
-
- // Unbind the request message
- EndpointInvocation epInv = bindingProvider.unbindRequestMessage(opMetaData, reqMessage);
-
- // Invoke the service endpoint
- invokeServiceEndpoint(seInfo, seInstance, epInv);
-
- // Bind the response message
- SOAPMessage resMessage = bindingProvider.bindResponseMessage(opMetaData, epInv);
- msgContext.setMessage(resMessage);
- }
-
- // call the handler chain
- if (oneway == false)
- {
- handlersPass = callResponseHandlerChain(seInfo, HandlerType.POST);
- handlersPass = handlersPass && callResponseHandlerChain(seInfo, HandlerType.JAXRPC);
- handlersPass = handlersPass && callResponseHandlerChain(seInfo, HandlerType.PRE);
- }
-
- SOAPMessage resMessage = msgContext.getMessage();
- return resMessage;
- }
- catch (Exception ex)
- {
- try
- {
- SOAPMessage faultMessage = SOAPFaultExceptionHelper.exceptionToFaultMessage(ex);
- msgContext.setMessage(faultMessage);
-
- // call the handler chain
- boolean handlersPass = handlerDelegate.callFaultHandlerChain(seInfo, HandlerType.POST, ex);
- handlersPass = handlersPass && handlerDelegate.callFaultHandlerChain(seInfo, HandlerType.JAXRPC, ex);
- handlersPass = handlersPass && handlerDelegate.callFaultHandlerChain(seInfo, HandlerType.PRE, ex);
- }
- catch (Exception subEx)
- {
- log.warn("Cannot process handlerChain.handleFault, ignoring: ", subEx);
- }
- throw ex;
- }
- finally
- {
- destroyServiceEndpoint(seInfo, seInstance);
- }
- }
-
- private OperationMetaData getDispatchDestination(EndpointMetaData epMetaData, SOAPMessageImpl reqMessage) throws SOAPException
- {
- OperationMetaData opMetaData = reqMessage.getOperationMetaData(epMetaData);
- SOAPHeader soapHeader = reqMessage.getSOAPHeader();
-
- // Report a MustUnderstand fault
- if (opMetaData == null)
- {
- SOAPBody soapBody = reqMessage.getSOAPBody();
- SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
- Name soapName = soapBodyElement.getElementName();
-
- // R2724 If an INSTANCE receives a message that is inconsistent with its WSDL description, it SHOULD generate a soap:Fault
- // with a faultcode of "Client", unless a "MustUnderstand" or "VersionMismatch" fault is generated.
- if (soapHeader != null && soapHeader.examineMustUnderstandHeaderElements(Constants.URI_SOAP11_NEXT_ACTOR).hasNext())
- {
- QName faultCode = Constants.SOAP11_FAULT_CODE_MUST_UNDERSTAND;
- String faultString = "Endpoint " + epMetaData.getQName() + " does not contain operation meta data for: " + soapName;
- throw new SOAPFaultException(faultCode, faultString, null, null);
- }
- else
- {
- QName faultCode = Constants.SOAP11_FAULT_CODE_CLIENT;
- String faultString = "Endpoint " + epMetaData.getQName() + " does not contain operation meta data for: " + soapName;
- throw new SOAPFaultException(faultCode, faultString, null, null);
- }
- }
- return opMetaData;
- }
-
- protected Method getImplMethod(Class implClass, Method seiMethod) throws ClassNotFoundException, NoSuchMethodException
- {
- String methodName = seiMethod.getName();
- Class[] paramTypes = seiMethod.getParameterTypes();
- for (int i = 0; i < paramTypes.length; i++)
- {
- Class paramType = paramTypes[i];
- if (JavaUtils.isPrimitive(paramType) == false)
- {
- String paramTypeName = paramType.getName();
- paramType = JavaUtils.loadJavaType(paramTypeName);
- paramTypes[i] = paramType;
- }
- }
-
- Method implMethod = implClass.getMethod(methodName, paramTypes);
- return implMethod;
- }
-
- /** handle invokation exceptions */
- public void handleInvocationException(Throwable th) throws SOAPFaultException
- {
- if (th instanceof RuntimeException)
- throw (RuntimeException)th;
-
- if (th instanceof InvocationTargetException)
- {
- InvocationTargetException targetException = (InvocationTargetException)th;
- Throwable targetEx = targetException.getTargetException();
- if (targetEx instanceof SOAPFaultException)
- {
- throw (SOAPFaultException)targetEx;
- }
- else
- {
- String faultString = targetEx.toString();
- SOAPFaultException soapFaultEx = new SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
- soapFaultEx.initCause(targetEx);
- throw soapFaultEx;
- }
- }
-
- if (th instanceof MBeanException)
- {
- Exception targetEx = ((MBeanException)th).getTargetException();
- if (targetEx instanceof SOAPFaultException)
- {
- throw (SOAPFaultException)targetEx;
- }
- else
- {
- String faultString = targetEx.toString();
- SOAPFaultException soapFaultEx = new SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
- soapFaultEx.initCause(targetEx);
- throw soapFaultEx;
- }
- }
-
- String faultString = th.toString();
- SOAPFaultException soapFaultEx = new SOAPFaultException(Constants.SOAP11_FAULT_CODE_CLIENT, faultString, null, null);
- soapFaultEx.initCause(th);
- throw soapFaultEx;
- }
-}
Modified: trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/main/java/org/jboss/ws/server/ServiceEndpointInvokerJSE.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -21,7 +21,7 @@
*/
package org.jboss.ws.server;
-// $Id$
+// $Id: $
import java.lang.reflect.Method;
@@ -33,8 +33,11 @@
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
import org.jboss.ws.binding.EndpointInvocation;
+import org.jboss.ws.common.SOAPMessageContextBase;
import org.jboss.ws.jaxrpc.ServletEndpointContextImpl;
+import org.jboss.ws.jaxws.handler.SOAPMessageContextJAXWS;
import org.jboss.ws.metadata.ServerEndpointMetaData;
+import org.jboss.ws.soap.MessageContextAssociation;
/**
* Handles invocations on JSE endpoints.
@@ -42,7 +45,7 @@
* @author Thomas.Diesler at jboss.org
* @since 19-Jan-2005
*/
-public class ServiceEndpointInvokerJSE extends ServiceEndpointInvokerBase implements ServiceEndpointInvoker
+public class ServiceEndpointInvokerJSE extends AbstractServiceEndpointInvoker implements ServiceEndpointInvoker
{
// provide logging
private Logger log = Logger.getLogger(ServiceEndpointInvokerJSE.class);
@@ -83,6 +86,10 @@
log.debug("invokeServiceEndpoint: " + epInv.getJavaMethod().getName());
try
{
+ SOAPMessageContextBase msgContext = MessageContextAssociation.peekMessageContext();
+ if (msgContext instanceof SOAPMessageContextJAXWS)
+ MessageContextInjector.injectMessageContext(seiImpl, (SOAPMessageContextJAXWS)msgContext);
+
Class implClass = seiImpl.getClass();
Method seiMethod = epInv.getJavaMethod();
Method implMethod = getImplMethod(implClass, seiMethod);
Modified: trunk/src/test/java/org/jboss/test/ws/jaxws/context/EndpointBean.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/jaxws/context/EndpointBean.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/test/java/org/jboss/test/ws/jaxws/context/EndpointBean.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -1,32 +1,37 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.test.ws.jaxws.context;
+// $Id: $
+
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.soap.SOAPMessageContext;
@WebService(name = "EndpointInterface", targetNamespace = "http://org.jboss.ws/jaxws/context", serviceName = "TestService")
@@ -34,14 +39,22 @@
public class EndpointBean
{
@Resource
- private WebServiceContext context;
-
+ public WebServiceContext context;
+
@WebMethod
public String echo(String input)
{
- SOAPMessageContext msgContext = (SOAPMessageContext)context.getMessageContext();
- SOAPMessage soapMessage = msgContext.getMessage();
-
- return input;
+ try
+ {
+ SOAPMessageContext msgContext = (SOAPMessageContext)context.getMessageContext();
+ SOAPMessage soapMessage = msgContext.getMessage();
+ SOAPElement soapElement = (SOAPElement)soapMessage.getSOAPBody().getChildElements().next();
+ soapElement = (SOAPElement)soapElement.getChildElements().next();
+ return soapElement.getValue();
+ }
+ catch (SOAPException ex)
+ {
+ throw new WebServiceException(ex);
+ }
}
}
Modified: trunk/src/test/java/org/jboss/test/ws/jaxws/context/WebServiceContextTestCase.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/jaxws/context/WebServiceContextTestCase.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/test/java/org/jboss/test/ws/jaxws/context/WebServiceContextTestCase.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -66,8 +66,6 @@
Service service = Service.create(wsdlURL, qname);
EndpointInterface port = (EndpointInterface)service.getPort(EndpointInterface.class);
- //System.out.println("FIXME: JBWS-1022");
-
String helloWorld = "Hello world!";
Object retObj = port.echo(helloWorld);
assertEquals(helloWorld, retObj);
Modified: trunk/src/test/java/org/jboss/test/ws/samples/wsaddressing/StatefulEndpointImpl.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/samples/wsaddressing/StatefulEndpointImpl.java 2006-08-04 14:49:57 UTC (rev 693)
+++ trunk/src/test/java/org/jboss/test/ws/samples/wsaddressing/StatefulEndpointImpl.java 2006-08-04 16:27:13 UTC (rev 694)
@@ -58,12 +58,17 @@
// The state map for all clients
private static Map<String, List<String>> clientStateMap = new HashMap<String, List<String>>();
- @Resource
- private WebServiceContext context;
-
private String clientid;
private static List<String> items;
+ private WebServiceContext context;
+ @Resource
+ public void setContext(WebServiceContext context)
+ {
+ log.info("injecting: " + context);
+ this.context = context;
+ }
+
@WebMethod
public void addItem(String item)
{
More information about the jboss-svn-commits
mailing list