Search in sources :

Example 6 with SOAPMessageContext

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);
}
Also used : HashMap(java.util.HashMap) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) List(java.util.List)

Example 7 with SOAPMessageContext

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);
}
Also used : SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) Test(org.junit.Test)

Example 8 with SOAPMessageContext

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);
}
Also used : HashMap(java.util.HashMap) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) List(java.util.List)

Example 9 with SOAPMessageContext

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);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 10 with SOAPMessageContext

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;
}
Also used : ContentType(javax.mail.internet.ContentType) WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) SOAPEnvelope(javax.xml.soap.SOAPEnvelope)

Aggregations

SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)45 SOAPMessage (javax.xml.soap.SOAPMessage)33 WebServiceException (javax.xml.ws.WebServiceException)24 SOAPException (javax.xml.soap.SOAPException)22 SOAPElement (javax.xml.soap.SOAPElement)18 Test (org.junit.Test)13 SOAPBody (javax.xml.soap.SOAPBody)12 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)10 QName (javax.xml.namespace.QName)7 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)7 IOException (java.io.IOException)6 List (java.util.List)6 Set (java.util.Set)6 ContentType (javax.mail.internet.ContentType)6 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)6 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)6 Handler (javax.xml.ws.handler.Handler)6 MessageContext (javax.xml.ws.handler.MessageContext)6 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)6 ArrayList (java.util.ArrayList)5