Java Code Examples for org.jboss.resteasy.spi.ResteasyProviderFactory#pushContext()

The following examples show how to use org.jboss.resteasy.spi.ResteasyProviderFactory#pushContext() . 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: RxVertxProvider.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
	Vertx vertx = ResteasyProviderFactory.getContextData(io.vertx.core.Vertx.class);
	HttpServerRequest req = ResteasyProviderFactory.getContextData(HttpServerRequest.class);
	HttpServerResponse resp = ResteasyProviderFactory.getContextData(HttpServerResponse.class);
	
	// rx2
	ResteasyProviderFactory.pushContext(io.vertx.reactivex.core.Vertx.class, 
			io.vertx.reactivex.core.Vertx.newInstance(vertx));
	ResteasyProviderFactory.pushContext(io.vertx.reactivex.core.http.HttpServerRequest.class, 
			io.vertx.reactivex.core.http.HttpServerRequest.newInstance(req));
	ResteasyProviderFactory.pushContext(io.vertx.reactivex.core.http.HttpServerResponse.class, 
			io.vertx.reactivex.core.http.HttpServerResponse.newInstance(resp));
	// rx1
	ResteasyProviderFactory.pushContext(io.vertx.rxjava.core.Vertx.class, 
			io.vertx.rxjava.core.Vertx.newInstance(vertx));
	ResteasyProviderFactory.pushContext(io.vertx.rxjava.core.http.HttpServerRequest.class, 
			io.vertx.rxjava.core.http.HttpServerRequest.newInstance(req));
	ResteasyProviderFactory.pushContext(io.vertx.rxjava.core.http.HttpServerResponse.class, 
			io.vertx.rxjava.core.http.HttpServerResponse.newInstance(resp));

	ResteasyProviderFactory.pushContext(ServletContext.class, AppGlobals.get().getGlobal(ServletContext.class));
}
 
Example 2
Source File: ActiveMQ.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static <T> T getEntity(ClientMessage msg, Class<T> type, Type genericType, ResteasyProviderFactory factory) {
   int size = msg.getBodySize();
   if (size <= 0)
      return null;

   byte[] body = new byte[size];
   msg.getBodyBuffer().readBytes(body);

   String contentType = msg.getStringProperty(HttpHeaderProperty.CONTENT_TYPE);
   if (contentType == null) {
      throw new UnknownMediaType("Message did not have a Content-Type header cannot extract entity");
   }
   MediaType ct = MediaType.valueOf(contentType);
   MessageBodyReader<T> reader = factory.getMessageBodyReader(type, genericType, null, ct);
   if (reader == null) {
      throw new UnmarshalException("Unable to find a JAX-RS reader for type " + type.getName() + " and media type " + contentType);
   }

   Providers current = ResteasyProviderFactory.getContextData(Providers.class);
   ResteasyProviderFactory.pushContext(Providers.class, factory);
   try {
      return reader.readFrom(type, genericType, null, ct, new Headers<String>(), new ByteArrayInputStream(body));
   } catch (IOException e) {
      throw new RuntimeException(e);
   } finally {
      ResteasyProviderFactory.popContextData(Providers.class);
      if (current != null)
         ResteasyProviderFactory.pushContext(Providers.class, current);
   }
}
 
Example 3
Source File: HelloFilter.java    From Embedded-Jetty-RESTEasy-Guice-Example with Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) sr;

    //System.out.println("filter: " + req.getRequestURI() + " user: " + sr.getParameter("user"));
    if (sr.getParameter("user") != null) {
        ResteasyProviderFactory.pushContext(User.class, new User(sr.getParameter("user")));
        fc.doFilter(new UserRoleRequestWrapper("user", sr.getParameter("user"), req), sr1);
    } else {
        fc.doFilter(req, sr1);
    }

}
 
Example 4
Source File: UserPrincipalContextFilter.java    From mapr-music with Apache License 2.0 4 votes vote down vote up
@Override
public void filter(ContainerRequestContext context) throws IOException {
    SecurityContext securityContext = context.getSecurityContext();
    ResteasyProviderFactory.pushContext(Principal.class, securityContext.getUserPrincipal());
}
 
Example 5
Source File: ResteasyFilterContext.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@Override
	public void setSession(Session session) {
//		System.err.println("setSession: "+session);
		ResteasyProviderFactory.pushContext(io.vertx.reactivex.ext.web.Session.class, io.vertx.reactivex.ext.web.Session.newInstance(session));
		delegate.setSession(session);
	}
 
Example 6
Source File: ResteasyFilterContext.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@Override
	public void setUser(User user) {
//		System.err.println("setUser: "+user);
		ResteasyProviderFactory.pushContext(io.vertx.reactivex.ext.auth.User.class, io.vertx.reactivex.ext.auth.User.newInstance(user));
		delegate.setUser(user);
	}
 
Example 7
Source File: AppGlobals.java    From redpipe with Apache License 2.0 4 votes vote down vote up
public void injectGlobals() {
	// FIXME: inject using the more precise Type using the new resteasy injection API
	for (Entry<Class<?>, Object> entry : typedGlobals.entrySet()) {
		ResteasyProviderFactory.pushContext((Class)entry.getKey(), entry.getValue());
	}
}
 
Example 8
Source File: Resteasy3Provider.java    From spring-security-oauth with MIT License 4 votes vote down vote up
@Override
public void pushContext(Class type, Object instance) {
	ResteasyProviderFactory.getInstance();
	ResteasyProviderFactory.pushContext(type, instance);
}
 
Example 9
Source File: Resteasy3Provider.java    From spring-security-oauth with MIT License 4 votes vote down vote up
@Override
public void pushContext(Class type, Object instance) {
	ResteasyProviderFactory.getInstance();
	ResteasyProviderFactory.pushContext(type, instance);
}
 
Example 10
Source File: Resteasy3Provider.java    From spring-security-oauth with MIT License 4 votes vote down vote up
@Override
public void pushContext(Class type, Object instance) {
	ResteasyProviderFactory.getInstance();
	ResteasyProviderFactory.pushContext(type, instance);
}
 
Example 11
Source File: HelloResourceTest.java    From Embedded-Jetty-RESTEasy-Guice-Example with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureRequestContext() {
    ResteasyProviderFactory.pushContext(User.class, new User("Kalle"));
}