Search in sources :

Example 1 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRpcProvider method processMessage.

/**
 * @param msgContext msgContext
 * @param reqEnv reqEnv
 * @param resEnv resEnv
 * @param obj obj
 * @throws Exception
 */
@Override
public void processMessage(MessageContext msgContext, SOAPEnvelope reqEnv, SOAPEnvelope resEnv, Object obj) throws Exception {
    RPCElement body = getBody(reqEnv, msgContext);
    OperationDesc operation = getOperationDesc(msgContext, body);
    AxisRpcInterceptor interceptor = new AxisRpcInterceptor(operation, msgContext);
    SOAPMessage message = msgContext.getMessage();
    try {
        message.getSOAPPart().getEnvelope();
        msgContext.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION, Boolean.FALSE);
        RpcContainer container = (RpcContainer) ejbDeployment.getContainer();
        Object[] arguments = { msgContext, interceptor };
        Class callInterface = ejbDeployment.getServiceEndpointInterface();
        Object result = container.invoke(ejbDeployment.getDeploymentID(), InterfaceType.SERVICE_ENDPOINT, callInterface, operation.getMethod(), arguments, null);
        interceptor.createResult(result);
    } catch (ApplicationException e) {
        interceptor.createExceptionResult(e.getCause());
    } catch (Throwable throwable) {
        throw new AxisFault("Web Service EJB Invocation failed: method " + operation.getMethod(), throwable);
    }
}
Also used : AxisFault(org.apache.axis.AxisFault) RpcContainer(org.apache.openejb.RpcContainer) ApplicationException(org.apache.openejb.ApplicationException) RPCElement(org.apache.axis.message.RPCElement) OperationDesc(org.apache.axis.description.OperationDesc) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 2 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class JaxWsInvocationTest method testWsInvocations.

public void testWsInvocations() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class, "PseudoSecurityService", null, "PseudoSecurityService", null));
    assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
    final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
    assembler.createApplication(ejbJar);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("EchoBean");
    assertNotNull(beanContext);
    assertEquals("ServiceEndpointInterface", EchoServiceEndpoint.class, beanContext.getServiceEndpointInterface());
    // OK, Now let's fake a web serivce invocation coming from any random
    // web service provider.  The web serivce provider needs supply
    // the MessageContext and an interceptor to do the marshalling as
    // the arguments of the standard container.invoke signature.
    // So let's create a fake message context.
    final MessageContext messageContext = new FakeMessageContext();
    // Now let's create a fake interceptor as would be supplied by the
    // web service provider.  Instead of writing "fake" marshalling
    // code that would pull the arguments from the soap message, we'll
    // just give it the argument values directly.
    final Object wsProviderInterceptor = new FakeWsProviderInterceptor("Hello world");
    // Ok, now we have the two arguments expected on a JAX-RPC Web Service
    // invocation as per the OpenEJB-specific agreement between OpenEJB
    // and the Web Service Provider
    final Object[] args = new Object[] { messageContext, wsProviderInterceptor };
    // Let's grab the container as the Web Service Provider would do and
    // perform an invocation
    final RpcContainer container = (RpcContainer) beanContext.getContainer();
    final Method echoMethod = EchoServiceEndpoint.class.getMethod("echo", String.class);
    final String value = (String) container.invoke("EchoBean", InterfaceType.SERVICE_ENDPOINT, echoMethod.getDeclaringClass(), echoMethod, args, null);
    assertCalls(Call.values());
    calls.clear();
    assertEquals("Hello world", value);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Method(java.lang.reflect.Method) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) BeanContext(org.apache.openejb.BeanContext) RpcContainer(org.apache.openejb.RpcContainer) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) MessageContext(javax.xml.ws.handler.MessageContext) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 3 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbMethodInvoker method preEjbInvoke.

private Object preEjbInvoke(Exchange exchange, Method method, List<Object> params) {
    EjbMessageContext ctx = new EjbMessageContext(exchange.getInMessage(), Scope.APPLICATION);
    WebServiceContextImpl.setMessageContext(ctx);
    Map<String, Object> handlerProperties = removeHandlerProperties(ctx);
    exchange.put(HANDLER_PROPERTIES, handlerProperties);
    try {
        EjbInterceptor interceptor = new EjbInterceptor(params, method, this.bus, exchange);
        Object[] arguments = { ctx, interceptor };
        RpcContainer container = (RpcContainer) this.beanContext.getContainer();
        Class callInterface = this.beanContext.getServiceEndpointInterface();
        method = getMostSpecificMethod(beanContext, method, callInterface);
        Object res = container.invoke(this.beanContext.getDeploymentID(), InterfaceType.SERVICE_ENDPOINT, callInterface, method, arguments, null);
        if (exchange.isOneWay()) {
            return null;
        }
        return new MessageContentsList(res);
    } catch (ApplicationException e) {
        // when no handler is defined, EjbInterceptor will directly delegate
        // to #directEjbInvoke. So if an application exception is thrown by
        // the end user, when must consider the ApplicationException as a
        // web fault if it contains the @WebFault exception
        Throwable t = e.getCause();
        if (t != null) {
            if (RuntimeException.class.isAssignableFrom(t.getClass()) && t.getClass().isAnnotationPresent(javax.ejb.ApplicationException.class)) {
                // it's not a checked exception so it can not be a WebFault
                throw (RuntimeException) t;
            } else if (!t.getClass().isAnnotationPresent(WebFault.class)) {
                // not a web fault even if it's an EJB ApplicationException
                exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
                throw createFault(t, method, params, false);
            }
        } else {
            // may not occurs ...
            t = e;
        }
        // TODO may be we can change to FaultMode.CHECKED_APPLICATION_FAULT
        exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
        throw createFault(t, method, params, false);
    } catch (Exception e) {
        exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
        throw createFault(e, method, params, false);
    } finally {
        WebServiceContextImpl.clear();
    }
}
Also used : MessageContentsList(org.apache.cxf.message.MessageContentsList) ApplicationException(org.apache.openejb.ApplicationException) WebFault(javax.xml.ws.WebFault) FaultMode(org.apache.cxf.message.FaultMode) RpcContainer(org.apache.openejb.RpcContainer) ApplicationException(org.apache.openejb.ApplicationException)

Example 4 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRequestHandler method doEjbHome_REMOVE_BY_PKEY.

protected void doEjbHome_REMOVE_BY_PKEY(final EJBRequest req, final EJBResponse res) throws Exception {
    final CallContext call = CallContext.getCallContext();
    final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer();
    c.invoke(req.getDeploymentId(), InterfaceType.EJB_HOME, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
    res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, null);
}
Also used : RpcContainer(org.apache.openejb.RpcContainer)

Example 5 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRequestHandler method doEjbHome_CREATE.

protected void doEjbHome_CREATE(final EJBRequest req, final EJBResponse res) throws Exception {
    final CallContext call = CallContext.getCallContext();
    final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer();
    Object result = c.invoke(req.getDeploymentId(), InterfaceType.EJB_HOME, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
    if (result instanceof ProxyInfo) {
        final ProxyInfo info = (ProxyInfo) result;
        res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, info.getPrimaryKey());
    } else {
        result = new RemoteException("The bean is not EJB compliant.  The bean should be created or and exception should be thrown.");
        LOGGER.error(req + "The bean is not EJB compliant.  The bean should be created or and exception should be thrown.");
        res.setResponse(req.getVersion(), ResponseCodes.EJB_SYS_EXCEPTION, new ThrowableArtifact((Throwable) result));
    }
}
Also used : ProxyInfo(org.apache.openejb.ProxyInfo) RpcContainer(org.apache.openejb.RpcContainer) ThrowableArtifact(org.apache.openejb.client.ThrowableArtifact) RemoteException(java.rmi.RemoteException)

Aggregations

RpcContainer (org.apache.openejb.RpcContainer)12 Method (java.lang.reflect.Method)3 ApplicationException (org.apache.openejb.ApplicationException)3 BeanContext (org.apache.openejb.BeanContext)3 RemoteException (java.rmi.RemoteException)2 ProxyInfo (org.apache.openejb.ProxyInfo)2 Assembler (org.apache.openejb.assembler.classic.Assembler)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)2 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)2 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)2 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)2 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)2 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)2 ContainerSystem (org.apache.openejb.spi.ContainerSystem)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EJBException (javax.ejb.EJBException)1