Search in sources :

Example 1 with HttpRequest

use of org.mule.runtime.http.api.domain.message.request.HttpRequest in project mule by mulesoft.

the class HttpRequestBuilderTestCase method defaultRequest.

@Test
public void defaultRequest() {
    URI uri = getUriFromString("someUri");
    HttpRequest request = builder.uri(uri).build();
    assertThat(request.getMethod(), is("GET"));
    assertThat(request.getUri(), is(uri));
    assertThat(request.getEntity(), is(instanceOf(EmptyHttpEntity.class)));
    assertThat(request.getHeaderNames(), empty());
    assertThat(request.getQueryParams().keySet(), empty());
}
Also used : HttpRequest(org.mule.runtime.http.api.domain.message.request.HttpRequest) URI(java.net.URI) Test(org.junit.Test)

Example 2 with HttpRequest

use of org.mule.runtime.http.api.domain.message.request.HttpRequest 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 HttpRequest

use of org.mule.runtime.http.api.domain.message.request.HttpRequest in project mule by mulesoft.

the class HttpRequestBuilderTestCase method complexResponse.

@Test
public void complexResponse() {
    MultiMap<String, String> paramMap = new MultiMap<>();
    paramMap.put(name, value);
    HttpRequest request = builder.entity(new ByteArrayHttpEntity("test".getBytes())).uri(URI_VALUE).method(POST).queryParams(paramMap).headers(paramMap).addHeader(name.toUpperCase(), value.toUpperCase()).build();
    assertThat(request.getUri(), is(URI.create(URI_VALUE)));
    assertThat(request.getMethod(), is(POST.name()));
    assertThat(request.getEntity(), is(instanceOf(ByteArrayHttpEntity.class)));
    assertThat(request.getHeaderNames(), hasItems(name));
    assertThat(request.getHeaderValues(name), hasItems(value, value.toUpperCase()));
    MultiMap<String, String> requestQueryParams = request.getQueryParams();
    assertThat(requestQueryParams.keySet(), hasItems(name));
    assertThat(requestQueryParams.getAll(name), hasItems(value));
}
Also used : HttpRequest(org.mule.runtime.http.api.domain.message.request.HttpRequest) MultiMap(org.mule.runtime.api.util.MultiMap) UriCache.getUriFromString(org.mule.runtime.http.api.utils.UriCache.getUriFromString) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayHttpEntity(org.mule.runtime.http.api.domain.entity.ByteArrayHttpEntity) Test(org.junit.Test)

Aggregations

HttpRequest (org.mule.runtime.http.api.domain.message.request.HttpRequest)3 Test (org.junit.Test)2 MultiMap (org.mule.runtime.api.util.MultiMap)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 TimeoutException (java.util.concurrent.TimeoutException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)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 HttpResponse (org.mule.runtime.http.api.domain.message.response.HttpResponse)1 UriCache.getUriFromString (org.mule.runtime.http.api.utils.UriCache.getUriFromString)1 DispatchingException (org.mule.runtime.soap.api.exception.DispatchingException)1