org.jboss.resteasy.specimpl.ResteasyHttpHeaders Java Examples

The following examples show how to use org.jboss.resteasy.specimpl.ResteasyHttpHeaders. 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: VertxHttpRequest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public VertxHttpRequest(Context context,
        RoutingContext routingContext,
        ResteasyHttpHeaders httpHeaders,
        ResteasyUriInfo uri,
        String httpMethod,
        LazyHostSupplier remoteHost,
        SynchronousDispatcher dispatcher,
        VertxHttpResponse response, ManagedContext requestContext) {
    super(uri);
    this.context = context;
    this.response = response;
    this.httpHeaders = httpHeaders;
    this.httpMethod = httpMethod;
    this.remoteHost = remoteHost;
    this.executionContext = new VertxExecutionContext(this, response, dispatcher);
    this.requestContext = requestContext;
    this.requestContextState = requestContext.getState();
    this.routingContext = routingContext;
}
 
Example #2
Source File: SynchronousDispatcherInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSW6SerializedContextData() throws Throwable {
    MultivaluedMapImpl<String, String> multivaluedMap = new MultivaluedMapImpl<String, String>();
    multivaluedMap.putSingle(SW8CarrierItem.HEADER_NAME, "1-My40LjU=-MS4yLjM=-3-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA=");
    when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(multivaluedMap));

    synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
    synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null);

    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);

    AssertTools.assertHttpSpan(spans.get(0));
    AssertTools.assertTraceSegmentRef(traceSegment.getRefs().get(0));
}
 
Example #3
Source File: SynchronousDispatcherInterceptorTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws URISyntaxException {
    synchronousDispatcherInterceptor = new SynchronousDispatcherInterceptor();
    exceptionInterceptor = new SynchronousDispatcherExceptionInterceptor();
    when(request.getUri()).thenReturn(new ResteasyUriInfo(new URI("http://localhost:8080/test/testRequestURL")));
    when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(new MultivaluedMapImpl<String, String>()));
    when(response.getStatus()).thenReturn(200);
    when(request.getAsyncContext()).thenReturn(resteasyAsynchronousContext);
    when(request.getAsyncContext().isSuspended()).thenReturn(false);
    arguments = new Object[] {
        request,
        response,
        resourceInvoker
    };
    argumentType = new Class[] {
        request.getClass(),
        response.getClass(),
        resourceInvoker.getClass()
    };

    exceptionArguments = new Object[] {
        request,
        response,
        new RuntimeException()
    };
    exceptionArgumentType = new Class[] {
        request.getClass(),
        response.getClass(),
        new RuntimeException().getClass()
    };
}
 
Example #4
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void dispatch(RoutingContext routingContext, InputStream is, VertxOutput output) {
    ManagedContext requestContext = beanContainer.requestContext();
    requestContext.activate();
    routingContext.remove(QuarkusHttpUser.AUTH_FAILURE_HANDLER);
    QuarkusHttpUser user = (QuarkusHttpUser) routingContext.user();
    if (association != null) {
        association.setIdentity(QuarkusHttpUser.getSecurityIdentity(routingContext, null));
    }
    currentVertxRequest.setCurrent(routingContext);
    try {
        Context ctx = vertx.getOrCreateContext();
        HttpServerRequest request = routingContext.request();
        ResteasyUriInfo uriInfo = VertxUtil.extractUriInfo(request, rootPath);
        ResteasyHttpHeaders headers = VertxUtil.extractHttpHeaders(request);
        HttpServerResponse response = request.response();
        VertxHttpResponse vertxResponse = new VertxHttpResponse(request, dispatcher.getProviderFactory(),
                request.method(), allocator, output);

        // using a supplier to make the remote Address resolution lazy: often it's not needed and it's not very cheap to create.
        LazyHostSupplier hostSupplier = new LazyHostSupplier(request);

        VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx, routingContext, headers, uriInfo, request.rawMethod(),
                hostSupplier,
                dispatcher.getDispatcher(), vertxResponse, requestContext);
        vertxRequest.setInputStream(is);
        try {
            ResteasyContext.pushContext(SecurityContext.class, new QuarkusResteasySecurityContext(request, routingContext));
            ResteasyContext.pushContext(RoutingContext.class, routingContext);
            dispatcher.service(ctx, request, response, vertxRequest, vertxResponse, true);
        } catch (Failure e1) {
            vertxResponse.setStatus(e1.getErrorCode());
            if (e1.isLoggable()) {
                log.error(e1);
            }
        } catch (Throwable ex) {
            routingContext.fail(ex);
        }

        boolean suspended = vertxRequest.getAsyncContext().isSuspended();
        boolean requestContextActive = requestContext.isActive();
        if (!suspended) {
            try {
                if (requestContextActive) {
                    requestContext.terminate();
                }
            } finally {
                try {
                    vertxResponse.finish();
                } catch (IOException e) {
                    log.debug("IOException writing JAX-RS response", e);
                }
            }
        } else {
            //we need the request context to stick around
            requestContext.deactivate();
        }
    } catch (Throwable t) {
        try {
            routingContext.fail(t);
        } finally {
            if (requestContext.isActive()) {
                requestContext.terminate();
            }
        }
    }
}
 
Example #5
Source File: VertxPluginRequestHandler.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(HttpServerRequest request)
{
   request.bodyHandler(buff -> {
      Context ctx = vertx.getOrCreateContext();
      ResteasyUriInfo uriInfo = VertxUtil.extractUriInfo(request.getDelegate(), servletMappingPrefix);
      ResteasyHttpHeaders headers = VertxUtil.extractHttpHeaders(request.getDelegate());
      HttpServerResponse response = request.response();
      VertxHttpResponse vertxResponse = new VertxHttpResponseWithWorkaround(response.getDelegate(), dispatcher.getProviderFactory(), request.method());
      VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx.getDelegate(), headers, uriInfo, request.rawMethod(), dispatcher.getDispatcher(), vertxResponse, false);
      if (buff.length() > 0)
      {
         ByteBufInputStream in = new ByteBufInputStream(buff.getDelegate().getByteBuf());
         vertxRequest.setInputStream(in);
      }

      try
      {
     	AppGlobals.set(appGlobals);
     	appGlobals.injectGlobals();
         dispatcher.service(ctx.getDelegate(), request.getDelegate(), response.getDelegate(), vertxRequest, vertxResponse, true);
      } catch (Failure e1)
      {
         vertxResponse.setStatus(e1.getErrorCode());
      } catch (Exception ex)
      {
         vertxResponse.setStatus(500);
         LogMessages.LOGGER.error(Messages.MESSAGES.unexpected(), ex);
      }
      finally 
      {
     	 AppGlobals.set(null);
      }
      if (!vertxRequest.getAsyncContext().isSuspended())
      {
         try
         {
            vertxResponse.finish();
         } catch (IOException e)
         {
            e.printStackTrace();
         }
      }
   });
}
 
Example #6
Source File: VertxUtil.java    From quarkus with Apache License 2.0 3 votes vote down vote up
public static ResteasyHttpHeaders extractHttpHeaders(HttpServerRequest request) {

        MultivaluedMap<String, String> requestHeaders = extractRequestHeaders(request);
        ResteasyHttpHeaders headers = new ResteasyHttpHeaders(requestHeaders);

        Map<String, Cookie> cookies = extractCookies(requestHeaders);
        headers.setCookies(cookies);
        return headers;

    }