use of io.vertx.core.MultiMap in project java-chassis by ServiceComb.
the class RestUtilsTest method defaultHeadersContainServiceRegistryAndAuthentication.
@Test
public void defaultHeadersContainServiceRegistryAndAuthentication() throws Exception {
MultiMap headers = RestUtils.getDefaultHeaders();
assertThat(headers.get("Content-Type"), is("application/json"));
assertThat(headers.get("User-Agent"), is("cse-serviceregistry-client/1.0.0"));
assertThat(headers.get("x-domain-name"), is("default"));
assertThat(headers.get("X-Service-AK"), is("blah..."));
}
use of io.vertx.core.MultiMap in project hono by eclipse.
the class HonoAuthHandlerImplTest method testHandleFailsWithStatusCodeFromAuthProvider.
/**
* Verifies that the handler returns the status code conveyed in a
* failed @{@code AuthProvider} invocation in the response.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testHandleFailsWithStatusCodeFromAuthProvider() {
// GIVEN an auth handler configured with an auth provider that
// fails with a 503 error code during authentication
final int EXPECTED_ERROR_CODE = 503;
doAnswer(invocation -> {
Handler handler = invocation.getArgument(1);
handler.handle(Future.failedFuture(new ServerErrorException(EXPECTED_ERROR_CODE)));
return null;
}).when(authProvider).authenticate(any(JsonObject.class), any(Handler.class));
// WHEN trying to authenticate a request using the HTTP BASIC scheme
final String authorization = new StringBuffer().append("BASIC ").append(Base64.getEncoder().encodeToString("user:password".getBytes(StandardCharsets.UTF_8))).toString();
MultiMap headers = mock(MultiMap.class);
when(headers.get(eq(HttpHeaders.AUTHORIZATION))).thenReturn(authorization);
HttpServerRequest req = mock(HttpServerRequest.class);
when(req.headers()).thenReturn(headers);
HttpServerResponse resp = mock(HttpServerResponse.class);
RoutingContext ctx = mock(RoutingContext.class);
when(ctx.request()).thenReturn(req);
when(ctx.response()).thenReturn(resp);
authHandler.handle(ctx);
// THEN the request context is failed with the 503 error code
ArgumentCaptor<Throwable> failureCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(ctx).fail(failureCaptor.capture());
ServerErrorException ex = (ServerErrorException) failureCaptor.getValue();
assertThat(ex.getErrorCode(), is(EXPECTED_ERROR_CODE));
}
use of io.vertx.core.MultiMap in project vert.x by eclipse.
the class HTTPExamples method example21.
public void example21(HttpServerRequest request) {
HttpServerResponse response = request.response();
MultiMap headers = response.headers();
headers.set("content-type", "text/html");
headers.set("other-header", "wibble");
}
use of io.vertx.core.MultiMap in project vert.x by eclipse.
the class HTTPExamples method example12.
public void example12(HttpServer server) {
server.requestHandler(request -> {
request.setExpectMultipart(true);
request.endHandler(v -> {
MultiMap formAttributes = request.formAttributes();
});
});
}
use of io.vertx.core.MultiMap in project vert.x by eclipse.
the class HTTPExamples method example8.
public void example8(HttpServerRequest request) {
MultiMap headers = request.headers();
// Get the User-Agent:
System.out.println("User agent is " + headers.get("user-agent"));
// You can also do this and get the same result:
System.out.println("User agent is " + headers.get("User-Agent"));
}
Aggregations