Search in sources :

Example 46 with MultiMap

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..."));
}
Also used : MultiMap(io.vertx.core.MultiMap) Test(org.junit.Test)

Example 47 with MultiMap

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));
}
Also used : MultiMap(io.vertx.core.MultiMap) RoutingContext(io.vertx.ext.web.RoutingContext) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Handler(io.vertx.core.Handler) JsonObject(io.vertx.core.json.JsonObject) ServerErrorException(org.eclipse.hono.client.ServerErrorException) Test(org.junit.Test)

Example 48 with MultiMap

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");
}
Also used : MultiMap(io.vertx.core.MultiMap)

Example 49 with MultiMap

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();
        });
    });
}
Also used : MultiMap(io.vertx.core.MultiMap)

Example 50 with MultiMap

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"));
}
Also used : MultiMap(io.vertx.core.MultiMap)

Aggregations

MultiMap (io.vertx.core.MultiMap)89 Test (org.junit.Test)77 CaseInsensitiveHeaders (io.vertx.core.http.CaseInsensitiveHeaders)61 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)19 Map (java.util.Map)12 Buffer (io.vertx.core.buffer.Buffer)9 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)8 Handler (io.vertx.core.Handler)8 VertxException (io.vertx.core.VertxException)8 HttpClientRequest (io.vertx.core.http.HttpClientRequest)8 HttpMethod (io.vertx.core.http.HttpMethod)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)8 HeadersAdaptor (io.vertx.core.http.impl.HeadersAdaptor)8 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)7 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)7 Nullable (io.vertx.codegen.annotations.Nullable)7 AbstractVerticle (io.vertx.core.AbstractVerticle)7 AsyncResult (io.vertx.core.AsyncResult)7 Context (io.vertx.core.Context)7