1 7 8 package org.jboss.webservice.server; 10 11 13 import org.jboss.axis.AxisFault; 14 import org.jboss.axis.MessageContext; 15 import org.jboss.axis.handlers.soap.SOAPService; 16 import org.jboss.invocation.Invocation; 17 import org.jboss.invocation.InvocationKey; 18 import org.jboss.invocation.InvocationType; 19 import org.jboss.logging.Logger; 20 import org.jboss.metadata.ApplicationMetaData; 21 import org.jboss.metadata.BeanMetaData; 22 import org.jboss.security.SecurityAssociation; 23 import org.jboss.webservice.Constants; 24 25 import javax.management.MBeanException ; 26 import javax.management.MalformedObjectNameException ; 27 import javax.management.ObjectName ; 28 import java.lang.reflect.Method ; 29 import java.security.Principal ; 30 31 37 public class InvokerProviderEJB extends InvokerProvider 38 { 39 40 static final long serialVersionUID = 7848928202043133442L; 41 private Logger log = Logger.getLogger(InvokerProviderEJB.class); 43 44 private String jndiName; 45 private ObjectName containerName; 46 47 50 public void initServiceDesc(SOAPService service, MessageContext msgContext) throws AxisFault 51 { 52 super.initServiceDesc(service, msgContext); 53 54 String ejbLink = portComponentInfo.getPortComponentMetaData().getEjbLink(); 55 if (ejbLink == null) 56 throw new ServiceException("Cannot obtain ejb-link from port component"); 57 58 ApplicationMetaData applMetaData = (ApplicationMetaData)portComponentInfo.getDeploymentInfo().metaData; 59 BeanMetaData beanMetaData = (BeanMetaData)applMetaData.getBeanByEjbName(ejbLink); 60 if (beanMetaData == null) 61 throw new ServiceException("Cannot obtain ejb meta data for: " + ejbLink); 62 63 String sei = portComponentInfo.getPortComponentMetaData().getServiceEndpointInterface(); 65 String serviceEndpoint = beanMetaData.getServiceEndpoint(); 66 if (sei.equals(serviceEndpoint) == false) 67 throw new ServiceException("The <" + sei + "> does not correspond to <" + serviceEndpoint + "> in ejb-jar.xml"); 68 69 jndiName = beanMetaData.getContainerObjectNameJndiName(); 71 if (jndiName == null) 72 throw new ServiceException("Cannot obtain JNDI name for: " + ejbLink); 73 74 try 75 { 76 containerName = new ObjectName ("jboss.j2ee:jndiName=" + jndiName + ",service=EJB"); 77 } 78 catch (MalformedObjectNameException e) 79 { 80 throw new ServiceException(e.toString()); 81 } 82 } 83 84 87 protected ClassLoader getContextClassLoader() 88 { 89 return portComponentInfo.getDeploymentInfo().ucl; 90 } 91 92 95 protected Object makeNewServiceObject(MessageContext msgContext, String className) throws Exception 96 { 97 log.debug("makeNewServiceObject: class=" + className); 98 return null; 99 } 100 101 109 protected Object invokeServiceEndpoint(MessageContext msgContext, 110 Method method, Object obj, Object [] argValues) 111 throws Exception 112 { 113 log.debug("Invoke EJB: " + method); 114 115 Principal principal = SecurityAssociation.getPrincipal(); 117 Object credential = SecurityAssociation.getCredential(); 118 119 msgContext.setProperty(Constants.HANDLER_CHAIN, handlerChain); 121 122 Invocation inv = new Invocation(null, method, argValues, null, principal, credential); 124 inv.setValue(InvocationKey.SOAP_MESSAGE_CONTEXT, msgContext); 125 inv.setValue(InvocationKey.SOAP_MESSAGE, msgContext.getMessage()); 126 inv.setType(InvocationType.SERVICE_ENDPOINT); 127 128 Object [] invArgs = {inv}; 130 String [] sig = {Invocation.class.getName()}; 131 Object ret = server.invoke(containerName, "invoke", invArgs, sig); 132 return ret; 133 } 134 135 137 protected void processException(Exception ex) throws AxisFault 138 { 139 Exception cause = ex; 140 141 if (ex instanceof MBeanException && ex.getCause() instanceof Exception ) 143 cause = (Exception )ex.getCause(); 144 145 super.processException(cause); 146 } 147 } 148 | Popular Tags |