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;
}
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;
}
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 + ">";
}
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();
}
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;
}
Aggregations