Author: richard.opalka(a)jboss.com
Date: 2009-08-11 10:01:52 -0400 (Tue, 11 Aug 2009)
New Revision: 10519
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/security/SecurityAdapterImpl.java
Log:
[JBWS-2332] refactoring + javadoc
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java 2009-08-11
13:58:25 UTC (rev 10518)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java 2009-08-11
14:01:52 UTC (rev 10519)
@@ -38,8 +38,8 @@
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.spec.ServletMetaData;
import org.jboss.virtual.VirtualFile;
-import org.jboss.webservices.integration.invocation.InvocationHandlerEJB3;
import org.jboss.webservices.integration.util.ASHelper;
+import org.jboss.wsf.common.integration.WSConstants;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.deployment.ArchiveDeployment;
@@ -161,7 +161,7 @@
final String ejbClass = container.getComponentClassName();
final Endpoint ep = this.createEndpoint(ejbClass, ejbName, dep);
- ep.setProperty(InvocationHandlerEJB3.CONTAINER_NAME,
container.getContainerName());
+ ep.setProperty(WSConstants.CONTAINER_NAME, container.getContainerName());
}
dep.addAttachment(DeploymentUnit.class, unit);
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java 2009-08-11
13:58:25 UTC (rev 10518)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java 2009-08-11
14:01:52 UTC (rev 10519)
@@ -38,9 +38,6 @@
import org.jboss.invocation.PayloadKey;
import org.jboss.logging.Logger;
import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.security.SecurityContext;
-import org.jboss.security.SecurityContextAssociation;
-import org.jboss.webservices.integration.invocation.ServiceEndpointInterceptorEJB21;
import org.jboss.wsf.common.ObjectNameFactory;
import org.jboss.wsf.common.integration.WSHelper;
import org.jboss.wsf.spi.SPIProvider;
@@ -60,133 +57,190 @@
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerEJB21 extends AbstractInvocationHandler
+final class InvocationHandlerEJB21 extends AbstractInvocationHandler
{
- // provide logging
- private static final Logger log = Logger.getLogger(InvocationHandlerEJB21.class);
+ /** Logger. */
+ private static final Logger LOG = Logger.getLogger(InvocationHandlerEJB21.class);
+
+ /** EJB21 JNDI name. */
private String jndiName;
+
+ /** MBean server. */
private MBeanServer server;
- private ObjectName objectName;
+ /** Object name. */
+ private ObjectName ejb21ContainerName;
+
+ /**
+ * Consctructor.
+ */
InvocationHandlerEJB21()
{
+ super();
+
+ this.server = MBeanServerLocator.locateJBoss();
}
- public void init(Endpoint ep)
+ /**
+ * Initializes EJB 21 endpoint.
+ *
+ * @param endpoint web service endpoint
+ */
+ public void init(final Endpoint endpoint)
{
- String ejbName = ep.getShortName();
- Deployment dep = ep.getService().getDeployment();
- EJBArchiveMetaData apMetaData = WSHelper.getRequiredAttachment(dep,
EJBArchiveMetaData.class);
- EJBMetaData beanMetaData = (EJBMetaData)apMetaData.getBeanByEjbName(ejbName);
- if (beanMetaData == null)
+ final String ejbName = endpoint.getShortName();
+ final Deployment dep = endpoint.getService().getDeployment();
+ final EJBArchiveMetaData ejbArchiveMD = WSHelper.getRequiredAttachment(dep,
EJBArchiveMetaData.class);
+ final EJBMetaData ejbMD = (EJBMetaData)ejbArchiveMD.getBeanByEjbName(ejbName);
+
+ if (ejbMD == null)
+ {
throw new WebServiceException("Cannot obtain ejb meta data for: " +
ejbName);
+ }
- // get the MBeanServer
- server = MBeanServerLocator.locateJBoss();
+ // get the bean's JNDI name
+ this.jndiName = ejbMD.getContainerObjectNameJndiName();
- // get the bean's JNDI name
- jndiName = beanMetaData.getContainerObjectNameJndiName();
- if (jndiName == null)
+ if (this.jndiName == null)
+ {
throw new WebServiceException("Cannot obtain JNDI name for: " +
ejbName);
+ }
}
- public void invoke(Endpoint ep, Invocation inv) throws Exception
+ /**
+ * Gets EJB 21 container name lazily.
+ *
+ * @param endpoint webservice endpoint
+ * @return EJB21 container name
+ */
+ private synchronized ObjectName getEjb21ContainerName(final Endpoint endpoint)
{
- log.debug("Invoke: " + inv.getJavaMethod().getName());
+ final boolean ejb21ContainerNotInitialized = this.ejb21ContainerName == null;
- if (objectName == null)
+ if (ejb21ContainerNotInitialized)
{
- objectName = ObjectNameFactory.create("jboss.j2ee:jndiName=" +
jndiName + ",service=EJB");
- if (server.isRegistered(objectName) == false)
- throw new WebServiceException("Cannot find service endpoint target:
" + objectName);
+ this.ejb21ContainerName =
ObjectNameFactory.create("jboss.j2ee:jndiName=" + this.jndiName +
",service=EJB");
+ final boolean ejb21NotRegistered =
!this.server.isRegistered(this.ejb21ContainerName);
+ if (ejb21NotRegistered)
+ {
+ throw new IllegalArgumentException("Cannot find service endpoint target:
" + this.ejb21ContainerName);
+ }
// Inject the Service endpoint interceptor
- injectServiceEndpointInterceptor(objectName, ep.getShortName());
+ this.insertEJB21ServiceEndpointInterceptor(this.ejb21ContainerName,
endpoint.getShortName());
}
- // invoke on the container
+ return this.ejb21ContainerName;
+ }
+
+ /**
+ * Invokes EJB 21 endpoint.
+ *
+ * @param endpoint EJB 21 endpoint
+ * @param wsInvocation web service invocation
+ * @throws Exception if any error occurs
+ */
+ public void invoke(final Endpoint endpoint, final Invocation wsInvocation) throws
Exception
+ {
+ final ObjectName ejb21Name = this.getEjb21ContainerName(endpoint);
+
try
{
- // setup the invocation
- org.jboss.invocation.Invocation jbInv = getMBeanInvocation(inv);
+ // prepare for invocation
+ final org.jboss.invocation.Invocation jbossInvocation =
this.getMBeanInvocation(wsInvocation);
+ final String[] signature = {org.jboss.invocation.Invocation.class.getName()};
+ final Object[] args = new Object[] {jbossInvocation};
- String[] sig = { org.jboss.invocation.Invocation.class.getName() };
- Object retObj = server.invoke(objectName, "invoke", new Object[] {
jbInv }, sig);
- inv.setReturnValue(retObj);
+ // invoke method
+ final Object retObj = this.server.invoke(ejb21Name, "invoke", args,
signature);
+ wsInvocation.setReturnValue(retObj);
}
catch (Exception e)
{
- handleInvocationException(e);
+ this.handleInvocationException(e);
}
}
- private org.jboss.invocation.Invocation getMBeanInvocation(Invocation inv)
+ /**
+ * Returns configured EJB 21 JBoss MBean invocation.
+ *
+ * @param wsInvocation webservice invocation
+ * @return configured JBoss invocation
+ */
+ private org.jboss.invocation.Invocation getMBeanInvocation(final Invocation
wsInvocation)
{
- // EJB2.1 endpoints will only get an JAXRPC context
- MessageContext msgContext =
inv.getInvocationContext().getAttachment(MessageContext.class);
+ // ensure preconditions
+ final MessageContext msgContext =
wsInvocation.getInvocationContext().getAttachment(MessageContext.class);
if (msgContext == null)
+ {
throw new IllegalStateException("Cannot obtain MessageContext");
+ }
- SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
- SecurityAdaptor securityAdaptor =
spiProvider.getSPI(SecurityAdaptorFactory.class).newSecurityAdapter();
- SecurityContext sc = SecurityContextAssociation.getSecurityContext();
- Principal principal = securityAdaptor.getPrincipal();
- Object credential = securityAdaptor.getCredential();
+ final HandlerCallback callback =
wsInvocation.getInvocationContext().getAttachment(HandlerCallback.class);
+ if (callback == null)
+ {
+ throw new IllegalStateException("Cannot obtain HandlerCallback");
+ }
- if (principal == null && sc != null)
- principal = sc.getUtil().getUserPrincipal();
+ // prepare security data
+ final SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ final SecurityAdaptor securityAdaptor =
spiProvider.getSPI(SecurityAdaptorFactory.class).newSecurityAdapter();
+ final Principal principal = securityAdaptor.getPrincipal();
+ final Object credential = securityAdaptor.getCredential();
- if (credential == null && sc != null)
- credential = sc.getUtil().getCredential();
+ // prepare invocation data
+ final Method method = wsInvocation.getJavaMethod();
+ final Object[] args = wsInvocation.getArgs();
+ final org.jboss.invocation.Invocation jbossInvocation = new
org.jboss.invocation.Invocation(null, method, args, null, principal, credential);
- Method method = inv.getJavaMethod();
- Object[] args = inv.getArgs();
- org.jboss.invocation.Invocation jbInv = new org.jboss.invocation.Invocation(null,
method, args, null, principal, credential);
+ // propagate values to JBoss invocation
+ jbossInvocation.setValue(InvocationKey.SOAP_MESSAGE_CONTEXT, msgContext);
+ jbossInvocation.setValue(InvocationKey.SOAP_MESSAGE,
((SOAPMessageContext)msgContext).getMessage());
+ jbossInvocation.setType(InvocationType.SERVICE_ENDPOINT);
+ jbossInvocation.setValue(HandlerCallback.class.getName(), callback,
PayloadKey.TRANSIENT);
+ jbossInvocation.setValue(Invocation.class.getName(), wsInvocation,
PayloadKey.TRANSIENT);
- HandlerCallback callback =
inv.getInvocationContext().getAttachment(HandlerCallback.class);
- if (callback == null)
- throw new IllegalStateException("Cannot obtain HandlerCallback");
-
- jbInv.setValue(InvocationKey.SOAP_MESSAGE_CONTEXT, msgContext);
- jbInv.setValue(InvocationKey.SOAP_MESSAGE,
((SOAPMessageContext)msgContext).getMessage());
- jbInv.setType(InvocationType.SERVICE_ENDPOINT);
- jbInv.setValue(HandlerCallback.class.getName(), callback, PayloadKey.TRANSIENT);
- jbInv.setValue(Invocation.class.getName(), inv, PayloadKey.TRANSIENT);
-
- return jbInv;
+ return jbossInvocation;
}
- private void injectServiceEndpointInterceptor(ObjectName objectName, String ejbName)
+ /**
+ * This method dynamically inserts EJB 21 webservice endpoint interceptor
+ * to the last but one position in EJB 21 processing chain. See [JBWS-756] for more
info.
+ *
+ * @param objectName EJB 21 object name
+ * @param ejbName EJB 21 short name
+ */
+ private void insertEJB21ServiceEndpointInterceptor(final ObjectName objectName, final
String ejbName)
{
- // Dynamically add the service endpoint interceptor
- //
http://jira.jboss.org/jira/browse/JBWS-758
try
{
- EjbModule ejbModule = (EjbModule)server.getAttribute(objectName,
"EjbModule");
- StatelessSessionContainer container =
(StatelessSessionContainer)ejbModule.getContainer(ejbName);
+ final EjbModule ejbModule = (EjbModule)this.server.getAttribute(objectName,
"EjbModule");
+ final StatelessSessionContainer container =
(StatelessSessionContainer)ejbModule.getContainer(ejbName);
- boolean injectionPointFound = false;
- Interceptor prev = container.getInterceptor();
- while (prev != null && prev.getNext() != null)
+ Interceptor currentInterceptor = container.getInterceptor();
+ while (currentInterceptor != null && currentInterceptor.getNext() !=
null)
{
- Interceptor next = prev.getNext();
- if (next.getNext() == null)
+ final Interceptor nextInterceptor = currentInterceptor.getNext();
+
+ if (nextInterceptor.getNext() == null)
{
- log.debug("Inject service endpoint interceptor after: " +
prev.getClass().getName());
- ServiceEndpointInterceptorEJB21 sepInterceptor = new
ServiceEndpointInterceptorEJB21();
- prev.setNext(sepInterceptor);
- sepInterceptor.setNext(next);
- injectionPointFound = true;
+ final ServiceEndpointInterceptorEJB21 sepInterceptor = new
ServiceEndpointInterceptorEJB21();
+ currentInterceptor.setNext(sepInterceptor);
+ sepInterceptor.setNext(nextInterceptor);
+ InvocationHandlerEJB21.LOG.debug("Injecting EJB 21 service endpoint
interceptor after: " + currentInterceptor.getClass().getName());
+
+ return;
}
- prev = next;
+ currentInterceptor = nextInterceptor;
}
- if (injectionPointFound == false)
- log.warn("Cannot service endpoint interceptor injection point");
+
+ InvocationHandlerEJB21.LOG.warn("Cannot find EJB 21 service endpoint
interceptor insert point");
}
catch (Exception ex)
{
- log.warn("Cannot add service endpoint interceptor", ex);
+ InvocationHandlerEJB21.LOG.warn("Cannot register EJB 21 service endpoint
interceptor: ", ex);
}
}
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java 2009-08-11
13:58:25 UTC (rev 10518)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB3.java 2009-08-11
14:01:52 UTC (rev 10519)
@@ -21,91 +21,145 @@
*/
package org.jboss.webservices.integration.invocation;
+import java.lang.reflect.Method;
+
+import javax.xml.ws.WebServiceException;
+
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.wsf.common.integration.WSConstants;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.Invocation;
import org.jboss.wsf.spi.invocation.integration.InvocationContextCallback;
import org.jboss.wsf.spi.invocation.integration.ServiceEndpointContainer;
import org.jboss.wsf.spi.util.KernelLocator;
-import javax.xml.ws.WebServiceException;
-import java.lang.reflect.Method;
-
/**
* Handles invocations on EJB3 endpoints.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
*/
-public class InvocationHandlerEJB3 extends AbstractInvocationHandler
+final class InvocationHandlerEJB3 extends AbstractInvocationHandler
{
- public static final String CONTAINER_NAME =
"org.jboss.wsf.spi.invocation.ContainerName";
+ /** MC kernel controller. */
+ private final KernelController controller;
+ /** EJB3 container name. */
private String containerName;
- private KernelController houston;
+
+ /** EJB3 container. */
private ServiceEndpointContainer serviceEndpointContainer;
+ /**
+ * Constructor.
+ */
InvocationHandlerEJB3()
{
- houston = KernelLocator.getKernel().getController();
+ super();
+
+ this.controller = KernelLocator.getKernel().getController();
}
- public void init(Endpoint ep)
+ /**
+ * Initializes EJB3 container name.
+ *
+ * @param endpoint web service endpoint
+ */
+ public void init(final Endpoint endpoint)
{
- containerName = (String)ep.getProperty(InvocationHandlerEJB3.CONTAINER_NAME);
- assert containerName != null : "Target container name not set";
+ this.containerName = (String)endpoint.getProperty(WSConstants.CONTAINER_NAME);
+
+ if (this.containerName == null)
+ {
+ throw new IllegalArgumentException("Container name cannot be null");
+ }
}
- private ServiceEndpointContainer lazyInitializeInvocationTarget()
+ /**
+ * Gets EJB 3 container lazily.
+ *
+ * @return EJB3 container
+ */
+ private synchronized ServiceEndpointContainer getEjb3Container()
{
- if (null == this.serviceEndpointContainer)
+ final boolean ejb3ContainerNotInitialized = this.serviceEndpointContainer == null;
+
+ if (ejb3ContainerNotInitialized)
{
- ControllerContext context = houston.getInstalledContext(containerName);
+ final ControllerContext context =
this.controller.getInstalledContext(this.containerName);
if (context == null)
- throw new WebServiceException("Cannot find service endpoint target:
" + containerName);
+ {
+ throw new WebServiceException("Cannot find service endpoint target:
" + this.containerName);
+ }
- assert (context.getTarget() instanceof ServiceEndpointContainer) :
"Invocation target mismatch";
this.serviceEndpointContainer = (ServiceEndpointContainer)context.getTarget();
}
return this.serviceEndpointContainer;
}
- public void invoke(Endpoint ep, Invocation wsInv) throws Exception
+ /**
+ * Invokes EJB 3 endpoint.
+ *
+ * @param endpoint EJB 3 endpoint
+ * @param wsInvocation web service invocation
+ * @throws Exception if any error occurs
+ */
+ public void invoke(final Endpoint endpoint, final Invocation wsInvocation) throws
Exception
{
try
{
- ServiceEndpointContainer invocationTarget = lazyInitializeInvocationTarget();
+ // prepare for invocation
+ final ServiceEndpointContainer ejbContainer = this.getEjb3Container();
+ final InvocationContextCallback invocationCallback = new
EJB3InvocationContextCallback(wsInvocation);
+ final Class<?> implClass = ejbContainer.getServiceImplementationClass();
+ final Method seiMethod = wsInvocation.getJavaMethod();
+ final Method implMethod = this.getImplMethod(implClass, seiMethod);
+ final Object[] args = wsInvocation.getArgs();
- Class beanClass = invocationTarget.getServiceImplementationClass();
- Method method = getImplMethod(beanClass, wsInv.getJavaMethod());
- Object[] args = wsInv.getArgs();
- InvocationContextCallback invProps = new EJB3InvocationContextCallback(wsInv);
-
- Object retObj = invocationTarget.invokeEndpoint(method, args, invProps);
-
- wsInv.setReturnValue(retObj);
+ // invoke method
+ final Object retObj = ejbContainer.invokeEndpoint(implMethod, args,
invocationCallback);
+ wsInvocation.setReturnValue(retObj);
}
catch (Throwable th)
{
- handleInvocationException(th);
+ this.handleInvocationException(th);
}
}
- static class EJB3InvocationContextCallback implements InvocationContextCallback
+ /**
+ * EJB3 invocation callback allowing EJB 3 beans to access Web Service invocation
properties.
+ */
+ private static final class EJB3InvocationContextCallback implements
InvocationContextCallback
{
- private Invocation wsInv;
- public EJB3InvocationContextCallback(Invocation wsInv)
+ /** WebService invocation. */
+ private Invocation wsInvocation;
+
+ /**
+ * Constructor.
+ *
+ * @param wsInvocation delegee
+ */
+ public EJB3InvocationContextCallback(final Invocation wsInvocation)
{
- this.wsInv = wsInv;
+ this.wsInvocation = wsInvocation;
}
- public <T> T get(Class<T> propertyType)
+ /**
+ * Retrieves attachment type from Web Service invocation context attachments.
+ *
+ * @param <T> attachment type
+ * @param attachmentType attachment class
+ * @return attachment value
+ */
+ public <T> T get(final Class<T> attachmentType)
{
- return wsInv.getInvocationContext().getAttachment(propertyType);
+ return this.wsInvocation.getInvocationContext().getAttachment(attachmentType);
}
+
}
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/security/SecurityAdapterImpl.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/security/SecurityAdapterImpl.java 2009-08-11
13:58:25 UTC (rev 10518)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/security/SecurityAdapterImpl.java 2009-08-11
14:01:52 UTC (rev 10519)
@@ -56,7 +56,16 @@
*/
public Principal getPrincipal()
{
- return SecurityAssociation.getPrincipal();
+ final Principal principal = SecurityAssociation.getPrincipal();
+
+ if (principal != null)
+ {
+ return principal;
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrincipalPrivilegedAction());
+ }
}
/**
@@ -76,7 +85,16 @@
*/
public Object getCredential()
{
- return SecurityAssociation.getCredential();
+ final Object credential = SecurityAssociation.getCredential();
+
+ if (credential != null)
+ {
+ return credential;
+ }
+ else
+ {
+ return AccessController.doPrivileged(new CredentialPrivilegedAction());
+ }
}
/**
@@ -115,4 +133,70 @@
});
}
+ /**
+ * Returns user principal from security context if available.
+ */
+ private static final class PrincipalPrivilegedAction implements
PrivilegedAction<Principal>
+ {
+
+ /**
+ * Constructor.
+ */
+ private PrincipalPrivilegedAction()
+ {
+ super();
+ }
+
+ /**
+ * Execute this action.
+ *
+ * @return user principal if available or null.
+ */
+ public Principal run()
+ {
+ final SecurityContext securityContext =
SecurityContextAssociation.getSecurityContext();
+
+ if (securityContext != null)
+ {
+ return securityContext.getUtil().getUserPrincipal();
+ }
+
+ return null;
+ }
+
+ }
+
+ /**
+ * Returns user credential from security context if available.
+ */
+ private static final class CredentialPrivilegedAction implements
PrivilegedAction<Object>
+ {
+
+ /**
+ * Constructor.
+ */
+ private CredentialPrivilegedAction()
+ {
+ super();
+ }
+
+ /**
+ * Execute this action.
+ *
+ * @return user credential if available or null.
+ */
+ public Object run()
+ {
+ final SecurityContext securityContext =
SecurityContextAssociation.getSecurityContext();
+
+ if (securityContext != null)
+ {
+ return securityContext.getUtil().getCredential();
+ }
+
+ return null;
+ }
+
+ }
+
}