Example usage for io.netty.handler.codec.http HttpHeaderNames LOCATION

List of usage examples for io.netty.handler.codec.http HttpHeaderNames LOCATION

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpHeaderNames LOCATION.

Prototype

AsciiString LOCATION

To view the source code for io.netty.handler.codec.http HttpHeaderNames LOCATION.

Click Source Link

Document

"location"

Usage

From source file:com.cmz.http.file.HttpStaticFileServerHandler.java

License:Apache License

private static void sendRedirect(ChannelHandlerContext ctx, String newUri) {
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, FOUND);
    response.headers().set(HttpHeaderNames.LOCATION, newUri);

    // Close the connection as soon as the error message is sent.
    ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}

From source file:com.tc.websocket.server.handler.RedirectionHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, FOUND);

    HttpHeaders headers = req.headers();

    IConfig cfg = Config.getInstance();//  w w  w.  j av a2s  .c  o  m

    StringBuilder sb = new StringBuilder();

    if (cfg.isEncrypted()) {
        sb.append(StringCache.HTTPS);
    } else {
        sb.append(StringCache.HTTP);
    }

    //finish up the url.
    sb.append(headers.get(HttpHeaderNames.HOST)).append(StringCache.COLON).append(cfg.getPort())
            .append(req.uri());

    //apply the redirect url
    response.headers().set(HttpHeaderNames.LOCATION, sb.toString());

    // Close the connection as soon as the redirect is sent.
    ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}

From source file:gribbit.http.response.RedirectResponse.java

License:Open Source License

public RedirectResponse(Request request, String redirectURL) {
    super(request, HttpResponseStatus.FOUND);
    addHeader(HttpHeaderNames.LOCATION, redirectURL);
}

From source file:io.crate.protocols.http.HttpBlobHandler.java

License:Apache License

private void sendRedirect(String newUri) {
    HttpResponse response = prepareResponse(TEMPORARY_REDIRECT);
    response.headers().add(HttpHeaderNames.LOCATION, newUri);
    sendResponse(response);
}

From source file:io.netty.example.http.file.HttpStaticFileServerHandler.java

License:Apache License

private void sendRedirect(ChannelHandlerContext ctx, String newUri) {
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, FOUND, Unpooled.EMPTY_BUFFER);
    response.headers().set(HttpHeaderNames.LOCATION, newUri);

    this.sendAndCleanupConnection(ctx, response);
}

From source file:org.ballerinalang.test.service.http.sample.HttpStatusCodeTestCase.java

License:Open Source License

@Test(description = "Test ballerina created() function with entity body")
public void testCreatedWithBody() throws IOException {
    HttpResponse response = HttpClientRequest
            .doGet(serverInstance.getServiceURLHttp(servicePort, "code/createdWithBody"));
    assertEquals(response.getResponseCode(), 201, "Response code mismatched");
    assertEquals(response.getHeaders().get(HttpHeaderNames.CONTENT_TYPE.toString()),
            TestConstant.CONTENT_TYPE_TEXT_PLAIN, "Content-Type mismatched");
    assertEquals(response.getHeaders().get(HttpHeaderNames.LOCATION.toString()), newResourceURI,
            "Incorrect location header value");
    assertEquals(response.getData(), "Created Response", "Message content mismatched");
}

From source file:org.ballerinalang.test.service.http.sample.HttpStatusCodeTestCase.java

License:Open Source License

@Test(description = "Test ballerina created() function without entity body")
public void testCreatedWithoutBody() throws IOException {
    HttpResponse response = HttpClientRequest
            .doGet(serverInstance.getServiceURLHttp(servicePort, "code/createdWithoutBody"));
    assertEquals(response.getResponseCode(), 201, "Response code mismatched");
    assertEquals(response.getHeaders().get(HttpHeaderNames.LOCATION.toString()), newResourceURI,
            "Incorrect location header value");
    assertEquals(response.getData(), "", "Message body should be empty");
}

From source file:org.ballerinalang.test.service.http.sample.HttpStatusCodeTestCase.java

License:Open Source License

@Test(description = "Test ballerina created() function with an empty URI")
public void testCreatedWithEmptyURI() throws IOException {
    HttpResponse response = HttpClientRequest
            .doGet(serverInstance.getServiceURLHttp(servicePort, "code/createdWithEmptyURI"));
    assertEquals(response.getResponseCode(), 201, "Response code mismatched");
    assertEquals(response.getHeaders().get(HttpHeaderNames.LOCATION.toString()), null,
            "No location header should be received");
    assertEquals(response.getData(), "", "Message body should be empty");
}

From source file:org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations.java

License:Apache License

private static String extractJobId(HttpClientResponse response) {
    List<String> pathSegments = UriComponentsBuilder
            .fromUriString(response.responseHeaders().get(HttpHeaderNames.LOCATION)).build().getPathSegments();
    return pathSegments.get(pathSegments.size() - 1);
}

From source file:org.glowroot.ui.GlowrootLogHttpService.java

License:Apache License

@Override
public CommonResponse handleRequest(CommonRequest request, Authentication authentication) throws Exception {
    List<String> maxLinesParams = request.getParameters("max-lines");
    if (maxLinesParams.isEmpty()) {
        CommonResponse response = new CommonResponse(FOUND);
        response.setHeader(HttpHeaderNames.LOCATION, "log?max-lines=" + DEFAULT_MAX_LINES);
        return response;
    }//ww  w  . j  a  v a2  s . co m
    int maxLines = Integer.parseInt(maxLinesParams.get(0));

    File[] list = logDir.listFiles();
    if (list == null) {
        throw new IllegalStateException("Could not list directory: " + logDir.getAbsolutePath());
    }
    List<File> files = Lists.newArrayList();
    for (File file : list) {
        if (file.isFile() && file.getName().matches("glowroot.*\\.log")) {
            files.add(file);
        }
    }
    files = byLastModified.reverse().sortedCopy(files);
    List<String> lines = Lists.newArrayList();
    for (File file : files) {
        // logback writes logs in default charset
        List<String> olderLines = Files.readLines(file, Charset.defaultCharset());
        olderLines.addAll(lines);
        lines = olderLines;
        if (lines.size() >= maxLines) {
            break;
        }
    }
    List<ChunkSource> chunkSources = Lists.newArrayList();
    if (lines.size() > maxLines) {
        // return last 'maxLines' lines from aggregated log files
        lines = lines.subList(lines.size() - maxLines, lines.size());
        chunkSources.add(ChunkSource.wrap("[earlier log entries truncated]\n\n"));
    }
    for (String line : lines) {
        chunkSources.add(ChunkSource.wrap(line + '\n'));
    }
    return new CommonResponse(OK, MediaType.PLAIN_TEXT_UTF_8, ChunkSource.concat(chunkSources));
}