Search in sources :

Example 16 with MessageContext

use of javax.xml.ws.handler.MessageContext in project cxf by apache.

the class GreeterSessionImpl method greetMeOneWay.

public void greetMeOneWay(String me) {
    LOG.info("Executing operation greetMeOneWay");
    LOG.info("Message received: " + me);
    MessageContext mc = context.getMessageContext();
    HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
    HttpSession session = req.getSession();
    if (session == null) {
        throw new WebServiceException("No session in WebServiceContext");
    }
    String name = (String) session.getAttribute("name");
    if (name == null) {
        name = me;
        LOG.info("Starting the Session");
    }
    session.setAttribute("name", me);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebServiceException(javax.xml.ws.WebServiceException) HttpSession(javax.servlet.http.HttpSession) MessageContext(javax.xml.ws.handler.MessageContext)

Example 17 with MessageContext

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

the class EjbWsContext method getMessageContext.

@Override
public MessageContext 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 : ThreadContext(org.apache.openejb.core.ThreadContext) MessageContext(javax.xml.ws.handler.MessageContext)

Example 18 with MessageContext

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

the class EjbWsContext method getMessageContext.

public MessageContext 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 : ThreadContext(org.apache.openejb.core.ThreadContext) MessageContext(javax.xml.ws.handler.MessageContext)

Example 19 with MessageContext

use of javax.xml.ws.handler.MessageContext 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 20 with MessageContext

use of javax.xml.ws.handler.MessageContext in project cxf by apache.

the class OOBHdrServiceImpl method checkContext.

private boolean checkContext() {
    boolean success = false;
    MessageContext ctx = context == null ? null : context.getMessageContext();
    if (ctx.containsKey(Header.HEADER_LIST)) {
        List<?> oobHdr = (List<?>) ctx.get(Header.HEADER_LIST);
        Iterator<?> iter = oobHdr.iterator();
        while (iter.hasNext()) {
            Object hdr = iter.next();
            if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
                Header hdr1 = (Header) hdr;
                // System.out.println("Node conains : " + hdr1.getObject().toString());
                try {
                    JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
                    OutofBandHeader ob = (OutofBandHeader) job.getValue();
                    if ("testOobHeader".equals(ob.getName()) && "testOobHeaderValue".equals(ob.getValue())) {
                        if ("testHdrAttribute".equals(ob.getHdrAttribute())) {
                            success = true;
                            // mark it processed
                            iter.remove();
                        } else if ("dontProcess".equals(ob.getHdrAttribute())) {
                            // we won't remove it so we won't let the runtime know
                            // it's processed.   It SHOULD throw an exception
                            // saying the mustunderstand wasn't processed
                            success = true;
                        }
                    } else {
                        throw new RuntimeException("test failed");
                    }
                } catch (JAXBException ex) {
                    // 
                    ex.printStackTrace();
                }
            }
        }
    } else {
        throw new RuntimeException("MessageContext is null or doesnot contain OOBHeaders");
    }
    return success;
}
Also used : Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) ObjectFactory(org.apache.cxf.outofband.header.ObjectFactory) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) List(java.util.List) MessageContext(javax.xml.ws.handler.MessageContext)

Aggregations

MessageContext (javax.xml.ws.handler.MessageContext)46 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 QName (javax.xml.namespace.QName)10 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)9 Exchange (org.apache.cxf.message.Exchange)9 MessageImpl (org.apache.cxf.message.MessageImpl)9 HandlerChainInvoker (org.apache.cxf.jaxws.handler.HandlerChainInvoker)8 List (java.util.List)7 Header (org.apache.cxf.headers.Header)7 IOException (java.io.IOException)6 Handler (javax.xml.ws.handler.Handler)6 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpSession (javax.servlet.http.HttpSession)5 JAXBException (javax.xml.bind.JAXBException)5 SOAPMessage (javax.xml.soap.SOAPMessage)5 Binding (javax.xml.ws.Binding)5