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