Search in sources :

Example 26 with MessageContext

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

the class OOBHdrServiceImpl method sendReturnOOBHeader.

private void sendReturnOOBHeader() {
    if (context != null) {
        MessageContext ctx = context.getMessageContext();
        if (ctx != null) {
            try {
                // Create out-of-band header object.
                OutofBandHeader ob = new OutofBandHeader();
                ob.setName("testOobReturnHeaderName");
                ob.setValue("testOobReturnHeaderValue");
                ob.setHdrAttribute("testReturnHdrAttribute");
                // Add Out-of-band header object to HeaderHolder.
                JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(new QName(OOBHeaderTest.TEST_HDR_NS, OOBHeaderTest.TEST_HDR_RESPONSE_ELEM), OutofBandHeader.class, null, ob);
                Header hdr = new Header(new QName(OOBHeaderTest.TEST_HDR_NS, OOBHeaderTest.TEST_HDR_RESPONSE_ELEM), job, new JAXBDataBinding(ob.getClass()));
                List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
                hdrList.add(hdr);
            // Add headerHolder to requestContext.
            // ctx.put(Header.HEADER_LIST, hdrList);
            // System.out.println("Completed adding list to context");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) MessageContext(javax.xml.ws.handler.MessageContext) JAXBElement(javax.xml.bind.JAXBElement) JAXBException(javax.xml.bind.JAXBException)

Example 27 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 28 with MessageContext

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

the class RestSourcePayloadProvider method invoke.

public DOMSource invoke(DOMSource request) {
    MessageContext mc = wsContext.getMessageContext();
    String path = (String) mc.get(Message.PATH_INFO);
    String query = (String) mc.get(Message.QUERY_STRING);
    String httpMethod = (String) mc.get(Message.HTTP_REQUEST_METHOD);
    System.out.println("--path--- " + path);
    System.out.println("--query--- " + query);
    System.out.println("--httpMethod--- " + httpMethod);
    if (httpMethod.equalsIgnoreCase("POST")) {
        // TBD: parse query info from DOMSource
        System.out.println("---Invoking updateCustomer---");
        return updateCustomer(request);
    } else if (httpMethod.equalsIgnoreCase("GET")) {
        if (path.equals("/customerservice/customer") && query == null) {
            System.out.println("---Invoking getAllCustomers---");
            return getAllCustomers();
        } else if (path.equals("/customerservice/customer") && query != null) {
            System.out.println("---Invoking getCustomer---");
            return getCustomer(query);
        }
    }
    return null;
}
Also used : MessageContext(javax.xml.ws.handler.MessageContext)

Example 29 with MessageContext

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

the class JAXWSMethodInvoker method invoke.

@Override
protected Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object> params) {
    // set up the webservice request context
    WrappedMessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION);
    Map<String, Object> handlerScopedStuff = removeHandlerProperties(ctx);
    final MessageContext oldCtx = WebServiceContextImpl.setMessageContext(ctx);
    List<Object> res = null;
    try {
        if ((params == null || params.isEmpty()) && serviceObject instanceof Provider) {
            params = Collections.singletonList(null);
        }
        res = CastUtils.cast((List<?>) super.invoke(exchange, serviceObject, m, params));
        if ((serviceObject instanceof Provider) && MessageUtils.getContextualBoolean(exchange.getInMessage(), "jaxws.provider.interpretNullAsOneway", true) && (res != null && !res.isEmpty() && res.get(0) == null) && exchange.getInMessage().getInterceptorChain().getState() == InterceptorChain.State.EXECUTING) {
            // treat the non-oneway call as oneway when a provider returns null
            // and the chain is not suspended due to a continuation suspend
            res = null;
            changeToOneway(exchange);
        }
        // update the webservice response context
        updateWebServiceContext(exchange, ctx);
    } catch (Fault f) {
        // get chance to copy over customer's header
        if (MessageUtils.getContextualBoolean(exchange.getInMessage(), COPY_SOAP_HEADERS_BY_FAULT, true)) {
            updateHeader(exchange, ctx);
        }
        throw f;
    } finally {
        // restore the WebServiceContextImpl's ThreadLocal variable to the previous value
        if (oldCtx == null) {
            WebServiceContextImpl.clear();
        } else {
            WebServiceContextImpl.setMessageContext(oldCtx);
        }
        addHandlerProperties(ctx, handlerScopedStuff);
    }
    return res;
}
Also used : WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) List(java.util.List) Fault(org.apache.cxf.interceptor.Fault) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) Provider(javax.xml.ws.Provider)

Example 30 with MessageContext

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

the class AbstractProtocolHandlerInterceptor method handleMessage.

public void handleMessage(T message) {
    if (binding.getHandlerChain().isEmpty()) {
        return;
    }
    MessageContext context = createProtocolMessageContext(message);
    HandlerChainInvoker invoker = getInvoker(message);
    invoker.setProtocolMessageContext(context);
    invoker.invokeProtocolHandlers(isRequestor(message), context);
    onCompletion(message);
}
Also used : WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) 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