Package org.springframework.ws.context

Examples of org.springframework.ws.context.DefaultMessageContext


    @Test
    public void testResolveExceptionCustom() throws Exception {
        MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
        MessageContext context = new DefaultMessageContext(factory);

        boolean result = resolver.resolveException(context, null, new MyCustomException());
        Assert.assertTrue("resolveException returns false", result);
        Assert.assertTrue("Context has no response", context.hasResponse());
        SoapMessage response = (SoapMessage) context.getResponse();
        Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
        Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
        Assert.assertEquals("Invalid fault code on fault", new QName("http://springframework.org/spring-ws", "Fault"),
                fault.getFaultCode());
        Assert.assertEquals("Invalid fault string on fault", "MyCustomException thrown", fault.getFaultStringOrReason());
View Full Code Here


    @Test
    public void testResolveExceptionInheritance() throws Exception {
        MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
        MessageContext context = new DefaultMessageContext(factory);

        boolean result = resolver.resolveException(context, null, new MySubClientException());
        Assert.assertTrue("resolveException returns false", result);
        Assert.assertTrue("Context has no response", context.hasResponse());
        SoapMessage response = (SoapMessage) context.getResponse();
        Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
        Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
        Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
                fault.getFaultCode());
        Assert.assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason());
View Full Code Here

    @Test
    public void testResolveExceptionExceptionMessage() throws Exception {
        MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
        MessageContext context = new DefaultMessageContext(factory);

        boolean result = resolver.resolveException(context, null, new NoStringOrReasonException("Exception message"));
        Assert.assertTrue("resolveException returns false", result);
        Assert.assertTrue("Context has no response", context.hasResponse());
        SoapMessage response = (SoapMessage) context.getResponse();
        Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
        Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
        Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
                fault.getFaultCode());
        Assert.assertEquals("Invalid fault string on fault", "Exception message", fault.getFaultStringOrReason());
View Full Code Here

        verify(connectionMock, interceptorMock1, interceptorMock2, requestCallback, extractorMock);
    }

    @Test
    public void testInterceptorsIntercepted() throws Exception {
        MessageContext messageContext = new DefaultMessageContext(messageFactory);

        ClientInterceptor interceptorMock1 = createStrictMock("interceptor1", ClientInterceptor.class);
        ClientInterceptor interceptorMock2 = createStrictMock("interceptor2", ClientInterceptor.class);
        template.setInterceptors(new ClientInterceptor[]{interceptorMock1, interceptorMock2});
        expect(interceptorMock1.handleRequest(isA(MessageContext.class))).andReturn(false);
        expect(interceptorMock1.handleResponse(isA(MessageContext.class))).andReturn(true);
        interceptorMock1.afterCompletion(isA(MessageContext.class), (Exception)isNull());

        WebServiceMessageCallback requestCallback = createMock(WebServiceMessageCallback.class);
        requestCallback.doWithMessage(messageContext.getRequest());

        WebServiceMessageExtractor extractorMock = createMock(WebServiceMessageExtractor.class);
        Object extracted = new Object();
        expect(extractorMock.extractData(isA(WebServiceMessage.class))).andReturn(extracted);
View Full Code Here

        verify(connectionMock, interceptorMock1, interceptorMock2, requestCallback, extractorMock);
    }

    @Test
    public void testInterceptorsInterceptedCreateResponse() throws Exception {
        MessageContext messageContext = new DefaultMessageContext(messageFactory);
        // force creation of response
        messageContext.getResponse();

        ClientInterceptor interceptorMock1 = createStrictMock("interceptor1", ClientInterceptor.class);
        ClientInterceptor interceptorMock2 = createStrictMock("interceptor2", ClientInterceptor.class);
        template.setInterceptors(new ClientInterceptor[]{interceptorMock1, interceptorMock2});
        expect(interceptorMock1.handleRequest(isA(MessageContext.class))).andReturn(false);
        expect(interceptorMock1.handleResponse(isA(MessageContext.class))).andReturn(true);
        interceptorMock1.afterCompletion(isA(MessageContext.class), (Exception)isNull());

        WebServiceMessageCallback requestCallback = createMock(WebServiceMessageCallback.class);
        requestCallback.doWithMessage(messageContext.getRequest());

        WebServiceMessageExtractor extractorMock = createMock(WebServiceMessageExtractor.class);
        Object extracted = new Object();
        expect(extractorMock.extractData(messageContext.getResponse())).andReturn(extracted);

        expect(connectionMock.hasFault()).andReturn(false);

        replay(connectionMock, interceptorMock1, interceptorMock2, requestCallback, extractorMock);
View Full Code Here

        this.messageSource.setBasename("org.springframework.ws.soap.server.endpoint.messages");
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage request = messageFactory.createMessage();
        request.getSOAPBody().addBodyElement(new QName("http://www.springframework.org/spring-ws", "request"));
        messageContext =
                new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory));
    }
View Full Code Here

    @Test
    public void testHandleInvalidRequestSoap11() throws Exception {
        SoapMessage invalidMessage = soap11Factory.createWebServiceMessage();
        InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE);
        transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult());
        context = new DefaultMessageContext(invalidMessage, soap11Factory);

        boolean result = interceptor.handleRequest(context, null);
        Assert.assertFalse("Invalid response from interceptor", result);
        Assert.assertTrue("Context has no response", context.hasResponse());
        SoapMessage response = (SoapMessage) context.getResponse();
View Full Code Here

    @Test
    public void testHandleInvalidRequestSoap12() throws Exception {
        SoapMessage invalidMessage = soap12Factory.createWebServiceMessage();
        InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE);
        transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult());
        context = new DefaultMessageContext(invalidMessage, soap12Factory);

        boolean result = interceptor.handleRequest(context, null);
        Assert.assertFalse("Invalid response from interceptor", result);
        Assert.assertTrue("Context has no response", context.hasResponse());
        SoapMessage response = (SoapMessage) context.getResponse();
View Full Code Here

    private MessageContext context;

    @Before
    public void setUp() throws Exception {
        mapping = new SoapActionEndpointMapping();
        context = new DefaultMessageContext(new SaajSoapMessageFactory(MessageFactory.newInstance()));
    }
View Full Code Here

        interceptor.setAddValidationErrorDetail(false);

        SoapMessage invalidMessage = soap11Factory.createWebServiceMessage();
        InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE);
        transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult());
        context = new DefaultMessageContext(invalidMessage, soap11Factory);

        boolean result = interceptor.handleRequest(context, null);
        Assert.assertFalse("Invalid response from interceptor", result);
        Assert.assertTrue("Context has no response", context.hasResponse());
        SoapMessage response = (SoapMessage) context.getResponse();
View Full Code Here

TOP

Related Classes of org.springframework.ws.context.DefaultMessageContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.