Package com.consol.citrus.http.message

Examples of com.consol.citrus.http.message.HttpMessage


        return (HttpEndpointConfiguration) super.getEndpointConfiguration();
    }

    @Override
    public void send(Message message, TestContext context) {
        HttpMessage httpMessage;
        if (message instanceof HttpMessage) {
            httpMessage = (HttpMessage) message;
        } else {
            httpMessage = new HttpMessage(message);
        }

        String correlationKey = getEndpointConfiguration().getCorrelator().getCorrelationKey(httpMessage);
        context.saveCorrelationKey(correlationKey, this);

        String endpointUri;
        if (getEndpointConfiguration().getEndpointUriResolver() != null) {
            endpointUri = getEndpointConfiguration().getEndpointUriResolver().resolveEndpointUri(httpMessage, getEndpointConfiguration().getRequestUrl());
        } else {
            endpointUri = getEndpointConfiguration().getRequestUrl();
        }

        log.info("Sending HTTP message to: '" + endpointUri + "'");

        if (log.isDebugEnabled()) {
            log.debug("Message to be sent:\n" + httpMessage.getPayload().toString());
        }

        HttpMethod method = getEndpointConfiguration().getRequestMethod();
        if (httpMessage.getRequestMethod() != null) {
            method = httpMessage.getRequestMethod();
        }

        HttpEntity<?> requestEntity = getEndpointConfiguration().getMessageConverter().convertOutbound(httpMessage, getEndpointConfiguration());

        getEndpointConfiguration().getRestTemplate().setErrorHandler(new InternalResponseErrorHandler(correlationKey));
View Full Code Here


     * @param method
     * @param requestEntity
     * @return
     */
    private ResponseEntity<String> handleRequestInternal(HttpMethod method, HttpEntity<String> requestEntity) {
        HttpMessage request = endpointConfiguration.getMessageConverter().convertInbound(requestEntity, endpointConfiguration);

        HttpServletRequest servletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        UrlPathHelper pathHelper = new UrlPathHelper();

        request.setRequestUri(pathHelper.getRequestUri(servletRequest));
        request.setContextPath(pathHelper.getContextPath(servletRequest));

        String queryParams = pathHelper.getOriginatingQueryString(servletRequest);
        request.setQueryParams(queryParams != null ? queryParams : "");

        request.setRequestMethod(method);

        Message response = endpointAdapter.handleMessage(request);
        if (response == null) {
            responseCache = new ResponseEntity(HttpStatus.OK);
        } else {
            HttpMessage httpResponse;
            if (response instanceof HttpMessage) {
                httpResponse = (HttpMessage) response;
            } else {
                httpResponse = new HttpMessage(response);
            }

            if (httpResponse.getStatusCode() == null) {
                httpResponse.setStatusCode(HttpStatus.OK);
            }

            responseCache = (ResponseEntity) endpointConfiguration.getMessageConverter().convertOutbound(httpResponse, endpointConfiguration);
        }

View Full Code Here

        replay(restTemplate);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive(context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate);
    }
View Full Code Here

        replay(restTemplate);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive(context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate);
    }
View Full Code Here

        replay(restTemplate);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive(context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate);
    }
View Full Code Here

        final String responseBody = "<TestResponse><Message>Hello World!</Message></TestResponse>";

        endpointConfiguration.setRequestMethod(HttpMethod.GET);
        endpointConfiguration.setRequestUrl(requestUrl);

        HttpMessage requestMessage = new HttpMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")
                .setRequestMethod(HttpMethod.GET);

        endpointConfiguration.setRestTemplate(restTemplate);

        reset(restTemplate);

        restTemplate.setErrorHandler(anyObject(ResponseErrorHandler.class));
        expectLastCall().once();

        expect(restTemplate.exchange(eq(requestUrl), eq(HttpMethod.GET), anyObject(HttpEntity.class), eq(String.class)))
                .andAnswer(new IAnswer<ResponseEntity<String>>() {
                    public ResponseEntity<String> answer() throws Throwable {
                        HttpEntity<?> httpRequest = (HttpEntity<?>)getCurrentArguments()[2];

                        Assert.assertNull(httpRequest.getBody()); // null because of GET
                        Assert.assertEquals(httpRequest.getHeaders().size(), 1);

                        Assert.assertEquals(httpRequest.getHeaders().getContentType().toString(), "text/plain;charset=UTF-8");

                        return new ResponseEntity<String>(responseBody, HttpStatus.OK);
                    }
                }).once();

        replay(restTemplate);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive(context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate);
    }
View Full Code Here

        replay(restTemplate);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive(context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate);
    }
View Full Code Here

        replay(restTemplate);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive(context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate);
    }
View Full Code Here

        endpointConfiguration.setRequestUrl(requestUrl);

        MessageCorrelator correlator = EasyMock.createMock(MessageCorrelator.class);
        endpointConfiguration.setCorrelator(correlator);

        Message requestMessage = new HttpMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");

        endpointConfiguration.setRestTemplate(restTemplate);

        reset(restTemplate, correlator);

        restTemplate.setErrorHandler(anyObject(ResponseErrorHandler.class));
        expectLastCall().once();

        expect(restTemplate.exchange(eq(requestUrl), eq(HttpMethod.GET), anyObject(HttpEntity.class), eq(String.class)))
                .andReturn(new ResponseEntity<String>(responseBody, HttpStatus.OK)).once();

        expect(correlator.getCorrelationKey(requestMessage)).andReturn("correlationKey").once();

        replay(restTemplate, correlator);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive("correlationKey", context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate, correlator);
    }
View Full Code Here

        String responseBody = "<TestResponse><Message>Hello World!</Message></TestResponse>";

        endpointConfiguration.setRequestMethod(HttpMethod.GET);
        endpointConfiguration.setRequestUrl(requestUrl);

        Message requestMessage = new HttpMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");

        EndpointUriResolver endpointUriResolver = EasyMock.createMock(EndpointUriResolver.class);
        endpointConfiguration.setEndpointUriResolver(endpointUriResolver);

        endpointConfiguration.setRestTemplate(restTemplate);

        reset(restTemplate, endpointUriResolver);

        restTemplate.setErrorHandler(anyObject(ResponseErrorHandler.class));
        expectLastCall().once();

        expect(endpointUriResolver.resolveEndpointUri(requestMessage, "http://localhost:8088/test")).andReturn("http://localhost:8081/new").once();

        expect(restTemplate.exchange(eq("http://localhost:8081/new"), eq(HttpMethod.GET), anyObject(HttpEntity.class), eq(String.class)))
                .andReturn(new ResponseEntity<String>(responseBody, HttpStatus.OK)).once();

        replay(restTemplate, endpointUriResolver);

        httpClient.send(requestMessage, context);

        HttpMessage responseMessage = (HttpMessage) httpClient.receive(context, endpointConfiguration.getTimeout());
        Assert.assertEquals(responseMessage.getPayload(), responseBody);
        Assert.assertEquals(responseMessage.getStatusCode(), HttpStatus.OK);
        Assert.assertEquals(responseMessage.getReasonPhrase(), "OK");

        verify(restTemplate, endpointUriResolver);
    }
View Full Code Here

TOP

Related Classes of com.consol.citrus.http.message.HttpMessage

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.