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());
}
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);
}
}
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));
}
Aggregations