org.eclipse.jetty.server.HttpChannel Java Examples

The following examples show how to use org.eclipse.jetty.server.HttpChannel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HandleInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    HttpChannel httpChannel = (HttpChannel) objInst;
    HttpServletRequest servletRequest = httpChannel.getRequest();

    ContextCarrier contextCarrier = new ContextCarrier();

    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(servletRequest.getHeader(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(servletRequest.getRequestURI(), contextCarrier);
    Tags.URL.set(span, servletRequest.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, servletRequest.getMethod());
    span.setComponent(ComponentsDefine.JETTY_SERVER);
    SpanLayer.asHttp(span);
}
 
Example #2
Source File: HttpResponseStatisticsCollectorTest.java    From vespa with Apache License 2.0 5 votes vote down vote up
private Request testRequest(String scheme, int responseCode, String httpMethod, String path) throws Exception {
    HttpChannel channel = new HttpChannel(connector, new HttpConfiguration(), null, new DummyTransport());
    MetaData.Request metaData = new MetaData.Request(httpMethod, new HttpURI(scheme + "://" + path), HttpVersion.HTTP_1_1, new HttpFields());
    Request req = channel.getRequest();
    req.setMetaData(metaData);

    this.httpResponseCode = responseCode;
    channel.handle();
    return req;
}
 
Example #3
Source File: JettyService.java    From armeria with Apache License 2.0 5 votes vote down vote up
private void invoke(ServiceRequestContext ctx, HttpResponseWriter res,
                    ArmeriaHttpTransport transport, HttpChannel httpChannel) {

    final Queue<HttpData> out = transport.out;
    try {
        server.handle(httpChannel);
        httpChannel.getResponse().getHttpOutput().flush();

        final Throwable cause = transport.cause;
        if (cause != null) {
            throw cause;
        }

        final HttpHeaders headers = toResponseHeaders(transport);
        if (res.tryWrite(headers)) {
            for (;;) {
                final HttpData data = out.poll();
                if (data == null || !res.tryWrite(data)) {
                    break;
                }
            }
        }
    } catch (Throwable t) {
        logger.warn("{} Failed to produce a response:", ctx, t);
    } finally {
        res.close();
    }
}
 
Example #4
Source File: HandleInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    HttpChannel httpChannel = (HttpChannel) objInst;
    HttpServletResponse servletResponse = httpChannel.getResponse();
    AbstractSpan span = ContextManager.activeSpan();
    if (IS_SERVLET_GET_STATUS_METHOD_EXIST && servletResponse.getStatus() >= 400) {
        span.errorOccurred();
        Tags.STATUS_CODE.set(span, Integer.toString(servletResponse.getStatus()));
    }
    ContextManager.stopSpan();
    ContextManager.getRuntimeContext().remove(Constants.FORWARD_REQUEST_FLAG);
    return ret;
}
 
Example #5
Source File: LimitedMethodServer.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(HttpChannel channel) throws IOException, ServletException {
  if(prohibitedMethods.contains(channel.getRequest().getMethod().toUpperCase())) {
    channel.getRequest().setHandled(true);
    channel.getResponse().setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
  } else {
    super.handle(channel);
  }
}
 
Example #6
Source File: Jetty9xServerHandleInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
HttpServletRequest toHttpServletRequest(Object[] args) {
    if (args == null || args.length < 1) {
        return null;
    }

    if (args[0] instanceof HttpChannel) {
        final HttpChannel<?> channel = (HttpChannel<?>) args[0];
        return channel.getRequest();
    }
    return null;
}
 
Example #7
Source File: Jetty9xServerHandleInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
HttpServletResponse toHttpServletResponse(Object[] args) {
    if (args == null || args.length < 1) {
        return null;
    }

    if (args[0] instanceof HttpChannel) {
        final HttpChannel<?> channel = (HttpChannel<?>) args[0];
        return channel.getResponse();
    }
    return null;
}
 
Example #8
Source File: JettyHTTPDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Request getCurrentRequest() {
    try {
        HttpConnection con = HttpConnection.getCurrentConnection();

        HttpChannel channel = con.getHttpChannel();
        return channel.getRequest();
    } catch (Throwable t) {
        //
    }
    return null;
}
 
Example #9
Source File: KeycloakJettyAuthenticator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected Authentication createAuthentication(UserIdentity userIdentity, Request request) {
    return new KeycloakAuthentication(getAuthMethod(), userIdentity) {
        @Override
        public void logout() {
            logoutCurrent(HttpChannel.getCurrentHttpChannel().getRequest());
        }
    };
}
 
Example #10
Source File: KeycloakSamlAuthenticator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public Authentication createAuthentication(UserIdentity userIdentity, Request request) {
    return new KeycloakAuthentication(getAuthMethod(), userIdentity) {
        @Override
        public void logout() {
            logoutCurrent(HttpChannel.getCurrentHttpChannel().getRequest());
        }
    };
}
 
Example #11
Source File: AccessLogRequestLogTest.java    From vespa with Apache License 2.0 4 votes vote down vote up
private Response createResponseMock() {
    Response response = mock(Response.class);
    when(response.getHttpChannel()).thenReturn(mock(HttpChannel.class));
    when(response.getCommittedMetaData()).thenReturn(mock(MetaData.Response.class));
    return response;
}
 
Example #12
Source File: AuthenticatedEncryptedCookieFactory.java    From keywhiz with Apache License 2.0 4 votes vote down vote up
private Response newResponse() {
  return new Response(new HttpChannel(null, new HttpConfiguration(), null, null), null);
}
 
Example #13
Source File: KeycloakJettyAuthenticator.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
protected Request resolveRequest(ServletRequest req) {
    return (req instanceof Request) ? (Request)req : HttpChannel.getCurrentHttpChannel().getRequest();
}
 
Example #14
Source File: KeycloakSamlAuthenticator.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
protected Request resolveRequest(ServletRequest req) {
    return (req instanceof Request) ? (Request)req : HttpChannel.getCurrentHttpChannel().getRequest();
}