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);
}
}
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);
}
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();
}
}
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);
}
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));
}
}
Aggregations