Search in sources :

Example 1 with HttpResponse

use of org.mule.runtime.http.api.domain.message.response.HttpResponse in project mule by mulesoft.

the class HttpResponseBuilderTestCase method complexResponse.

@Test
public void complexResponse() {
    HttpResponse response = builder.entity(new ByteArrayHttpEntity("test".getBytes())).statusCode(418).reasonPhrase("I'm a teapot").addHeader(header, value).build();
    assertThat(response.getStatusCode(), is(418));
    assertThat(response.getReasonPhrase(), is("I'm a teapot"));
    assertThat(response.getEntity(), is(instanceOf(ByteArrayHttpEntity.class)));
    assertThat(response.getHeaderNames(), hasItems(equalToIgnoringCase(header)));
    assertThat(response.getHeaderValuesIgnoreCase(header), hasItems(value));
}
Also used : HttpResponse(org.mule.runtime.http.api.domain.message.response.HttpResponse) ByteArrayHttpEntity(org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity) Test(org.junit.Test)

Example 2 with HttpResponse

use of org.mule.runtime.http.api.domain.message.response.HttpResponse in project mule by mulesoft.

the class DefaultHttpMessageDispatcher method dispatch.

/**
 * {@inheritDoc}
 * <p>
 * Dispatches a Soap message through http adding the SoapAction header, if required, and the content-type.
 */
@Override
public DispatchingResponse dispatch(DispatchingRequest context) {
    InputStream content = logIfNeeded("Soap Request to [" + context.getAddress() + "]", context.getContent());
    HttpRequest request = HttpRequest.builder().uri(context.getAddress()).method(POST).entity(new InputStreamHttpEntity(content)).headers(new MultiMap<>(context.getHeaders())).build();
    try {
        HttpResponse response = client.send(request, DEFAULT_TIMEOUT_MILLIS, false, null);
        return new DispatchingResponse(logIfNeeded("Soap Response", response.getEntity().getContent()), toHeadersMap(response));
    } catch (IOException e) {
        throw new DispatchingException("An error occurred while sending the SOAP request");
    } catch (TimeoutException e) {
        throw new DispatchingException("The SOAP request timed out", e);
    }
}
Also used : HttpRequest(org.mule.runtime.http.api.domain.message.request.HttpRequest) MultiMap(org.mule.runtime.api.util.MultiMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamHttpEntity(org.mule.runtime.http.api.domain.entity.InputStreamHttpEntity) HttpResponse(org.mule.runtime.http.api.domain.message.response.HttpResponse) IOException(java.io.IOException) DispatchingException(org.mule.runtime.soap.api.exception.DispatchingException) DispatchingResponse(org.mule.runtime.extension.api.soap.message.DispatchingResponse) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with HttpResponse

use of org.mule.runtime.http.api.domain.message.response.HttpResponse in project mule by mulesoft.

the class HttpResponseBuilderTestCase method defaultResponse.

@Test
public void defaultResponse() {
    HttpResponse response = builder.build();
    assertThat(response.getStatusCode(), is(200));
    assertThat(response.getReasonPhrase(), isEmptyString());
    assertThat(response.getEntity(), is(instanceOf(EmptyHttpEntity.class)));
    assertThat(response.getHeaderNames(), empty());
}
Also used : HttpResponse(org.mule.runtime.http.api.domain.message.response.HttpResponse) Test(org.junit.Test)

Aggregations

HttpResponse (org.mule.runtime.http.api.domain.message.response.HttpResponse)3 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TimeoutException (java.util.concurrent.TimeoutException)1 MultiMap (org.mule.runtime.api.util.MultiMap)1 DispatchingResponse (org.mule.runtime.extension.api.soap.message.DispatchingResponse)1 ByteArrayHttpEntity (org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity)1 InputStreamHttpEntity (org.mule.runtime.http.api.domain.entity.InputStreamHttpEntity)1 HttpRequest (org.mule.runtime.http.api.domain.message.request.HttpRequest)1 DispatchingException (org.mule.runtime.soap.api.exception.DispatchingException)1