Search in sources :

Example 21 with MessageContext

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

the class GreeterSessionImpl method greetMe.

// greetMe will use session to return last called name
public String greetMe(String me) {
    LOG.info("Executing operation greetMe");
    LOG.info("Message received: " + me);
    MessageContext mc = context.getMessageContext();
    HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
    Cookie[] cookies = req.getCookies();
    String val = "";
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            val += ";" + cookie.getName() + "=" + cookie.getValue();
        }
    }
    HttpSession session = req.getSession();
    // Get a session property "counter" from context
    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);
    return "Hello " + name + val;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) WebServiceException(javax.xml.ws.WebServiceException) HttpSession(javax.servlet.http.HttpSession) MessageContext(javax.xml.ws.handler.MessageContext)

Example 22 with MessageContext

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

the class HeaderTesterImpl method validateOutOfBandHander.

protected boolean validateOutOfBandHander() {
    MessageContext ctx = context == null ? null : context.getMessageContext();
    if (!relayHeaders) {
        if (ctx != null && !ctx.containsKey(Header.HEADER_LIST) || (ctx.containsKey(Header.HEADER_LIST) && ((List<?>) ctx.get(Header.HEADER_LIST)).size() == 0)) {
            return true;
        }
        return false;
    }
    boolean success = false;
    if (ctx != null && 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;
                try {
                    JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.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) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) List(java.util.List) MessageContext(javax.xml.ws.handler.MessageContext)

Example 23 with MessageContext

use of javax.xml.ws.handler.MessageContext in project ats-framework by Axway.

the class AgentWsImpl method getCaller.

/**
     * @return a token which contains a random Unique ID per caller and the caller IP as well
     */
private String getCaller() {
    MessageContext msgx = wsContext.getMessageContext();
    HttpServletRequest request = ((HttpServletRequest) msgx.get(MessageContext.SERVLET_REQUEST));
    String uid = "";
    try {
        Map<String, List<String>> headers = (Map<String, List<String>>) msgx.get(MessageContext.HTTP_REQUEST_HEADERS);
        uid = headers.get(ApplicationContext.ATS_UID_SESSION_TOKEN).get(0);
    } catch (Exception e) {
        if (!alreadyLoggedErrorAboutSessionUid) {
            log.warn("Could not get ATS UID for call from " + request.getRemoteAddr() + ". This error will not be logged again before Agent restart.", e);
            alreadyLoggedErrorAboutSessionUid = true;
        }
    }
    return "<Caller: " + request.getRemoteAddr() + "; ATS UID: " + uid + ">";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) List(java.util.List) MessageContext(javax.xml.ws.handler.MessageContext) Map(java.util.Map) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException)

Example 24 with MessageContext

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

the class WebServiceRUs method noteService.

private void noteService() {
    MessageContext ctx = injectedContext.getMessageContext();
    WrappedMessageContext wmc = (WrappedMessageContext) ctx;
    org.apache.cxf.message.Message msg = wmc.getWrappedMessage();
    service = msg.getExchange().getService();
}
Also used : WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) MessageContext(javax.xml.ws.handler.MessageContext)

Example 25 with MessageContext

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

the class AbstractProvider method invoke.

public T invoke(T req) {
    MessageContext mc = wsContext.getMessageContext();
    String method = (String) mc.get(MessageContext.HTTP_REQUEST_METHOD);
    LOG.info("method: " + method);
    T ret = null;
    if ("GET".equalsIgnoreCase(method)) {
        ret = get(req);
    } else if ("POST".equalsIgnoreCase(method)) {
        ret = post(req);
    }
    return ret;
}
Also used : 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