Search in sources :

Example 1 with MessageContext

use of javax.xml.rpc.handler.MessageContext in project wildfly by wildfly.

the class SessionContextImpl method getMessageContext.

public MessageContext getMessageContext() throws IllegalStateException {
    final InterceptorContext invocation = CurrentInvocationContext.get();
    final MessageContext context = invocation.getPrivateData(MessageContext.class);
    if (context == null) {
        throw EjbLogger.ROOT_LOGGER.cannotCall("getMessageContext()", "MessageContext");
    }
    return context;
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) MessageContext(javax.xml.rpc.handler.MessageContext)

Example 2 with MessageContext

use of javax.xml.rpc.handler.MessageContext in project tomee by apache.

the class JaxRpcInvocationTest method testWebServiceInvocations.

public void testWebServiceInvocations() 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.rpc.handler.MessageContext) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 3 with MessageContext

use of javax.xml.rpc.handler.MessageContext in project tomee by apache.

the class BaseSessionContext method getMessageContext.

public MessageContext getMessageContext() throws IllegalStateException {
    doCheck(Call.getMessageContext);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final MessageContext messageContext = threadContext.get(MessageContext.class);
    if (messageContext == null) {
        throw new IllegalStateException("Only calls on the service-endpoint have a MessageContext.");
    }
    return messageContext;
}
Also used : MessageContext(javax.xml.rpc.handler.MessageContext)

Aggregations

MessageContext (javax.xml.rpc.handler.MessageContext)3 Method (java.lang.reflect.Method)1 BeanContext (org.apache.openejb.BeanContext)1 RpcContainer (org.apache.openejb.RpcContainer)1 Assembler (org.apache.openejb.assembler.classic.Assembler)1 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)1 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)1 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)1 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)1 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)1 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)1 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1 InterceptorContext (org.jboss.invocation.InterceptorContext)1