Search in sources :

Example 1 with MessageContext

use of jakarta.xml.ws.handler.MessageContext in project metro-jax-ws by eclipse-ee4j.

the class EchoImpl method echoString.

public String echoString(String str) throws Exception1, Fault1, WSDLBarException {
    MessageContext ctxt = wsc.getMessageContext();
    Map<String, List<String>> hdrs = (Map<String, List<String>>) ctxt.get(MessageContext.HTTP_REQUEST_HEADERS);
    if (str == null) {
        return null;
    } else if (str.equals("Exception1")) {
        throw new Exception1("my exception1");
    } else if (str.equals("Fault1")) {
        FooException fooException = new FooException();
        fooException.setVarString("foo");
        fooException.setVarInt(33);
        fooException.setVarFloat(44F);
        throw new Fault1("fault1", fooException);
    } else if (str.equals("WSDLBarException")) {
        throw new WSDLBarException("my barException", new Bar(33));
    } else {
        List<String> ctList = hdrs.get("Content-Type");
        if (ctList == null || ctList.size() != 1) {
            throw new WebServiceException("Invalid Content-Type header=" + ctList);
        }
        String ct = ctList.get(0).toLowerCase();
        if (!(ct.contains(str.toLowerCase()))) {
            throw new WebServiceException("Invalid Encoding for request. Expected=" + str + " Got Content-Type header=" + ctList);
        }
    }
    return str;
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) List(java.util.List) MessageContext(jakarta.xml.ws.handler.MessageContext) Map(java.util.Map)

Example 2 with MessageContext

use of jakarta.xml.ws.handler.MessageContext in project metro-jax-ws by eclipse-ee4j.

the class EchoImpl method echoString.

public String echoString(String str) throws Exception1, Fault1, WSDLBarException {
    MessageContext ctxt = wsc.getMessageContext();
    Map<String, List<String>> hdrs = (Map<String, List<String>>) ctxt.get(MessageContext.HTTP_REQUEST_HEADERS);
    if (str == null) {
        return null;
    } else if (str.equals("Exception1")) {
        throw new Exception1("my exception1");
    } else if (str.equals("Fault1")) {
        FooException fooException = new FooException();
        fooException.setVarString("foo");
        fooException.setVarInt(33);
        fooException.setVarFloat(44F);
        throw new Fault1("fault1", fooException);
    } else if (str.equals("WSDLBarException")) {
        throw new WSDLBarException("my barException", new Bar(33));
    } else {
        List<String> ctList = hdrs.get("Content-Type");
        if (ctList == null || ctList.size() != 1) {
            throw new WebServiceException("Invalid Content-Type header=" + ctList);
        }
        String ct = ctList.get(0).toLowerCase();
        if (!(ct.contains(str.toLowerCase()))) {
            throw new WebServiceException("Invalid Encoding for request. Expected=" + str + " Got Content-Type header=" + ctList);
        }
    }
    return str;
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) List(java.util.List) MessageContext(jakarta.xml.ws.handler.MessageContext) Map(java.util.Map)

Example 3 with MessageContext

use of jakarta.xml.ws.handler.MessageContext in project metro-jax-ws by eclipse-ee4j.

the class HelloServiceImpl method introduce.

@WebMethod
public void introduce() {
    Map<String, List<String>> hdrs = new HashMap<String, List<String>>();
    hdrs.put("Set-Cookie", Collections.singletonList("a=b"));
    MessageContext mc = wsc.getMessageContext();
    mc.put(MessageContext.HTTP_RESPONSE_HEADERS, hdrs);
}
Also used : MessageContext(jakarta.xml.ws.handler.MessageContext) WebMethod(jakarta.jws.WebMethod)

Example 4 with MessageContext

use of jakarta.xml.ws.handler.MessageContext in project metro-jax-ws by eclipse-ee4j.

the class HelloServiceImpl method rememberMe.

@WebMethod
public boolean rememberMe() {
    MessageContext mc = wsc.getMessageContext();
    Map<String, List<String>> hdrs = (Map<String, List<String>>) mc.get(MessageContext.HTTP_REQUEST_HEADERS);
    List<String> cookieList = hdrs.get("Cookie");
    if (cookieList == null || cookieList.get(0) == null || !cookieList.get(0).equals("a=b")) {
        return false;
    }
    return true;
}
Also used : MessageContext(jakarta.xml.ws.handler.MessageContext) WebMethod(jakarta.jws.WebMethod)

Example 5 with MessageContext

use of jakarta.xml.ws.handler.MessageContext in project metro-jax-ws by eclipse-ee4j.

the class HelloServiceImpl method rememberMe.

@WebMethod
public void rememberMe() {
    MessageContext mc = wsc.getMessageContext();
    Map<String, List<String>> hdrs = (Map<String, List<String>>) mc.get(MessageContext.HTTP_REQUEST_HEADERS);
    List<String> cookieList = hdrs.get("Cookie");
    if (cookieList == null || cookieList.size() != 2) {
        throw new WebServiceException("Expecting two cookies, Got=" + cookieList);
    }
    String cookie1 = cookieList.get(0);
    String cookie2 = cookieList.get(1);
    if (!((cookie1.equals("a=b") && cookie2.equals("c=d")) || (cookie1.equals("c=d") && cookie2.equals("a=b")))) {
        throw new WebServiceException("Cookies are not matiching, Got=" + cookieList);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) List(java.util.List) ArrayList(java.util.ArrayList) MessageContext(jakarta.xml.ws.handler.MessageContext) Map(java.util.Map) HashMap(java.util.HashMap) WebMethod(jakarta.jws.WebMethod)

Aggregations

MessageContext (jakarta.xml.ws.handler.MessageContext)46 WebServiceException (jakarta.xml.ws.WebServiceException)17 WebMethod (jakarta.jws.WebMethod)13 List (java.util.List)12 Map (java.util.Map)12 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 Cookie (jakarta.servlet.http.Cookie)3 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)3 HTTPException (jakarta.xml.ws.http.HTTPException)3 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 QName (javax.xml.namespace.QName)2 HaInfo (com.sun.xml.ws.api.ha.HaInfo)1 Packet (com.sun.xml.ws.api.message.Packet)1 SOAPMessageContextImpl (com.sun.xml.ws.handler.SOAPMessageContextImpl)1 DataHandler (jakarta.activation.DataHandler)1 WebServiceContext (jakarta.xml.ws.WebServiceContext)1 StringReader (java.io.StringReader)1 SAXSource (javax.xml.transform.sax.SAXSource)1 StreamSource (javax.xml.transform.stream.StreamSource)1