use of javax.xml.ws.handler.LogicalMessageContext in project cxf by apache.
the class LogicalHandlerInterceptorTest method testInterceptSuccess.
@Test
public void testInterceptSuccess() {
List<LogicalHandler<?>> list = new ArrayList<LogicalHandler<?>>();
list.add(new LogicalHandler<LogicalMessageContext>() {
public void close(MessageContext arg0) {
}
public boolean handleFault(LogicalMessageContext arg0) {
return true;
}
public boolean handleMessage(LogicalMessageContext arg0) {
return true;
}
});
@SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
expect(binding.getHandlerChain()).andReturn(hList).anyTimes();
expect(invoker.getLogicalHandlers()).andReturn(list);
expect(message.getExchange()).andReturn(exchange).anyTimes();
expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
expect(message.keySet()).andReturn(new TreeSet<String>()).anyTimes();
expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
expect(exchange.getOutMessage()).andReturn(message);
expect(invoker.invokeLogicalHandlers(eq(true), isA(LogicalMessageContext.class))).andReturn(true);
control.replay();
LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding);
assertEquals("unexpected phase", "pre-protocol-frontend", li.getPhase());
li.handleMessage(message);
control.verify();
}
use of javax.xml.ws.handler.LogicalMessageContext in project jbossws-cxf by jbossws.
the class LogicalJAXBHandler method appendHandlerName.
@SuppressWarnings("unchecked")
private boolean appendHandlerName(MessageContext msgContext, String direction) {
try {
// Get the payload as Source
LogicalMessageContext logicalContext = (LogicalMessageContext) msgContext;
JAXBContext jaxb = JAXBContext.newInstance(Echo.class.getPackage().getName());
Object payload = logicalContext.getMessage().getPayload(jaxb);
JAXBElement<Object> jaxbElement = null;
if (payload instanceof JAXBElement) {
jaxbElement = (JAXBElement<Object>) payload;
payload = jaxbElement.getValue();
}
if (payload instanceof Echo) {
Echo echo = (Echo) payload;
String value = echo.getString1();
echo.setString1(value + ":" + direction + ":LogicalJAXBHandler");
} else if (payload instanceof EchoResponse) {
EchoResponse echo = (EchoResponse) payload;
String value = echo.getResult();
echo.setResult(value + ":" + direction + ":LogicalJAXBHandler");
} else {
throw new WebServiceException("Invalid payload type: " + payload);
}
if (jaxbElement != null) {
jaxbElement.setValue(payload);
payload = jaxbElement;
}
// Set the updated payload
logicalContext.getMessage().setPayload(payload, jaxb);
return true;
} catch (RuntimeException rte) {
throw rte;
} catch (Exception ex) {
throw new WebServiceException(ex);
}
}
use of javax.xml.ws.handler.LogicalMessageContext in project jbossws-cxf by jbossws.
the class LogicalSourceHandler method appendHandlerName.
private boolean appendHandlerName(MessageContext msgContext, String direction) {
try {
// Get the payload as Source
LogicalMessageContext logicalContext = (LogicalMessageContext) msgContext;
Source source = logicalContext.getMessage().getPayload();
TransformerFactory tf = TransformerFactory.newInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
tf.newTransformer().transform(source, new StreamResult(baos));
// Parse the payload and extract the value
Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()), getDocumentBuilder());
Element element = DOMUtils.getFirstChildElement(root);
String oldValue = DOMUtils.getTextContent(element);
String newValue = oldValue + ":" + direction + ":LogicalSourceHandler";
element.setTextContent(newValue);
log.debug("oldValue: " + oldValue);
log.debug("newValue: " + newValue);
// Set the updated payload
source = new DOMSource(root);
logicalContext.getMessage().setPayload(source);
return true;
} catch (RuntimeException rte) {
throw rte;
} catch (Exception ex) {
throw new WebServiceException(ex);
}
}
Aggregations