use of javax.xml.ws.handler.soap.SOAPMessageContext in project scout.rt by eclipse.
the class WsConsumerCorrelationIdHandlerTest method assertHandleOutboundMessage.
protected void assertHandleOutboundMessage(String expectedCid) {
// mock request context
Map<String, Object> headers = new HashMap<>();
// mock message context
SOAPMessageContext ctx = mock(SOAPMessageContext.class);
when(ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).thenReturn(Boolean.TRUE);
when(ctx.get(MessageContext.HTTP_REQUEST_HEADERS)).thenReturn(headers);
// handle inbound message
WsConsumerCorrelationIdHandler handler = new WsConsumerCorrelationIdHandler();
handler.handleMessage(ctx);
// verify invocation
verify(ctx, times(1)).get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (expectedCid != null) {
verify(ctx, times(1)).get(MessageContext.HTTP_REQUEST_HEADERS);
verify(ctx, times(1)).put(MessageContext.HTTP_REQUEST_HEADERS, headers);
// verify cid
assertEquals(1, headers.size());
assertTrue(headers.containsKey(CorrelationId.HTTP_HEADER_NAME));
Object cids = headers.get(CorrelationId.HTTP_HEADER_NAME);
assertNotNull(cids);
assertTrue(cids instanceof List<?>);
List<?> cidList = (List<?>) cids;
assertEquals(1, cidList.size());
assertEquals(expectedCid, cidList.get(0));
}
verifyNoMoreInteractions(ctx);
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project scout.rt by eclipse.
the class WsProviderCorrelationIdHandlerTest method testHandleOutboundMessage.
@Test
public void testHandleOutboundMessage() {
// mock message context
SOAPMessageContext ctx = mock(SOAPMessageContext.class);
when(ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).thenReturn(Boolean.TRUE);
// handle outbound message
WsProviderCorrelationIdHandler handler = new WsProviderCorrelationIdHandler();
handler.handleMessage(ctx);
// verify invocation
verify(ctx, times(1)).get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
verifyNoMoreInteractions(ctx);
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project scout.rt by eclipse.
the class WsProviderCorrelationIdHandlerTest method assertHandleInboundMessage.
protected void assertHandleInboundMessage(String expectedCid, String cidHeaderValue) {
// create HTTP headers
Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
if (cidHeaderValue != null) {
httpHeaders.put(CorrelationId.HTTP_HEADER_NAME, Collections.singletonList(cidHeaderValue));
}
// mock message context
SOAPMessageContext ctx = mock(SOAPMessageContext.class);
when(ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).thenReturn(Boolean.FALSE);
when(ctx.get(MessageContext.HTTP_REQUEST_HEADERS)).thenReturn(httpHeaders);
// handle inbound message
WsProviderCorrelationIdHandler handler = new WsProviderCorrelationIdHandler();
handler.handleMessage(ctx);
// verify invocation
verify(ctx, times(1)).get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
verify(ctx, times(1)).get(MessageContext.HTTP_REQUEST_HEADERS);
verify(ctx, times(1)).put(MessageContexts.PROP_CORRELATION_ID, expectedCid);
verify(ctx, times(1)).setScope(MessageContexts.PROP_CORRELATION_ID, Scope.APPLICATION);
verifyNoMoreInteractions(ctx);
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project jbossws-cxf by jbossws.
the class TestHandler method ensureInjectionsAndInitialization.
private boolean ensureInjectionsAndInitialization(MessageContext msgContext, String direction) {
if (!this.correctState) {
throw new WebServiceException("Unfunctional injections");
}
try {
SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
soapElement = (SOAPElement) soapElement.getChildElements().next();
String oldValue = soapElement.getValue();
String newValue = oldValue + ":" + direction + ":TestHandler";
soapElement.setValue(newValue);
log.debug("oldValue: " + oldValue);
log.debug("newValue: " + newValue);
return true;
} catch (SOAPException ex) {
throw new WebServiceException(ex);
}
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project jbossws-cxf by jbossws.
the class SOAP11ServerHandler method handleInbound.
@Override
public boolean handleInbound(SOAPMessageContext msgContext) {
log.info("handleInbound");
ContentType contentType = getContentType(msgContext);
if (contentType != null) {
log.info("contentType=" + contentType);
String startInfo = contentType.getParameter("start-info");
if (!startInfo.equals(SOAPConstants.SOAP_1_1_CONTENT_TYPE)) {
return false;
}
} else {
return false;
}
try {
SOAPEnvelope soapEnvelope = ((SOAPMessageContext) msgContext).getMessage().getSOAPPart().getEnvelope();
String nsURI = soapEnvelope.getNamespaceURI();
log.info("nsURI=" + nsURI);
if (!SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(nsURI)) {
return false;
}
} catch (SOAPException se) {
throw new WebServiceException(se);
}
return true;
}
Aggregations