当前位置: 首页>>代码示例>>Java>>正文


Java ResteasyProviderFactory.getContextData方法代码示例

本文整理汇总了Java中org.jboss.resteasy.spi.ResteasyProviderFactory.getContextData方法的典型用法代码示例。如果您正苦于以下问题:Java ResteasyProviderFactory.getContextData方法的具体用法?Java ResteasyProviderFactory.getContextData怎么用?Java ResteasyProviderFactory.getContextData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.resteasy.spi.ResteasyProviderFactory的用法示例。


在下文中一共展示了ResteasyProviderFactory.getContextData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCorrelationId

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@Override
public String getCorrelationId() {
  HttpHeaders headers = ResteasyProviderFactory.getContextData(HttpHeaders.class);

  String correlationId;
  if (headers != null) {
    correlationId = headers.getHeaderString(headerName);
    if (correlationId != null) {
      return correlationId;
    }
  }

  // Fall back to MDC to support beadledom-jaxrs 1.0. Retrieving from the headers is preferred.
  correlationId = MDC.get(mdcName);

  return correlationId;
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:18,代码来源:ResteasyCorrelationIdContext.java

示例2: filter

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext) throws IOException {
    HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
    RpcContext.getContext().setRequest(request);

    // this only works for servlet containers
    if (request != null && RpcContext.getContext().getRemoteAddress() == null) {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
    }

    RpcContext.getContext().setResponse(ResteasyProviderFactory.getContextData(HttpServletResponse.class));

    String headers = requestContext.getHeaderString(DUBBO_ATTACHMENT_HEADER);
    if (headers != null) {
        for (String header : headers.split(",")) {
            int index = header.indexOf("=");
            if (index > 0) {
                String key = header.substring(0, index);
                String value = header.substring(index + 1);
                if (!StringUtils.isEmpty(key)) {
                    RpcContext.getContext().setAttachment(key.trim(), value.trim());
                }
            }
        }
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:26,代码来源:RpcContextFilter.java

示例3: directSecurityContext

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@POST
@Path("/securitycontext")
@Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
public String directSecurityContext() {
    // Note: SecurityContext injected via @Context can't be cast
    SecurityContext context = ResteasyProviderFactory.getContextData(SecurityContext.class);
    if (context != null) {
        if (context instanceof Pac4JSecurityContext) {
            return "ok";
        } else {
            return "fail";
        }
    } else {
        return "error";
    }
}
 
开发者ID:pac4j,项目名称:jax-rs-pac4j,代码行数:17,代码来源:RestEasyResource.java

示例4: directContext

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@POST
@Path("/context")
@Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
public String directContext() {
    SecurityContext scontext = ResteasyProviderFactory.getContextData(SecurityContext.class);
    if (scontext != null && scontext instanceof Pac4JSecurityContext) {
        JaxRsContext context = ((Pac4JSecurityContext)scontext).getContext();
        if (context != null) {
            return "ok";
        } else {
            return "fail";
        }
    } else {
        return "error";
    }
}
 
开发者ID:pac4j,项目名称:jax-rs-pac4j,代码行数:17,代码来源:RestEasyResource.java

示例5: doProduce

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
protected T doProduce() {
    final Request request = ResteasyProviderFactory.getContextData(Request.class);
    final Variant variant = request.selectVariant(VARIANTS);
    if (variant == null) {
        throw new RuntimeException("Only HAL and Siren media types are supported");
    }
    else {
        final UriInfo uriInfo = ResteasyProviderFactory.getContextData(UriInfo.class);
        if (variant.getMediaType().equals(GENERIC_HAL)) {
            return hal(uriInfo);
        }
        else {
            return siren(uriInfo);
        }
    }
}
 
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:17,代码来源:BaseAssemblerProducer.java

示例6: testURIParamsAuthentication

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
/**
 * Test method for
 * {@link org.jboss.dcp.api.rest.AuthenticationInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod)}
 * .
 */
@Test
public void testURIParamsAuthentication() {
	AuthenticationInterceptor tested = getTested();

	HttpRequest requestMock = getHttpRequestMock();
	ResourceMethod methodMock = Mockito.mock(ResourceMethod.class);

	@SuppressWarnings("unchecked")
	MultivaluedMap<String, String> queryParamsMock = Mockito.mock(MultivaluedMap.class);
	Mockito.when(queryParamsMock.getFirst("provider")).thenReturn(uname);
	Mockito.when(queryParamsMock.getFirst("pwd")).thenReturn(pwd);

	Mockito.when(requestMock.getUri().getQueryParameters()).thenReturn(queryParamsMock);
	Mockito.when(tested.providerService.authenticate(uname, pwd)).thenReturn(true);

	ServerResponse res = tested.preProcess(requestMock, methodMock);
	Assert.assertNull(res);
	Mockito.verify(tested.providerService, Mockito.times(1)).authenticate(Mockito.anyString(), Mockito.anyString());

	SecurityContext ctx = ResteasyProviderFactory.getContextData(SecurityContext.class);
	Assert.assertEquals("uname", ctx.getUserPrincipal().getName());
	Assert.assertEquals("CUSTOM", ctx.getAuthenticationScheme());
}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:29,代码来源:AuthenticationInterceptorTest.java

示例7: getUpdateInfo

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
/**
 * Constructs and returns map, which contains document update information.
 *
 * @return map, which contains document update information.
 */
protected Optional<Map<String, Object>> getUpdateInfo() {

    Principal principal = ResteasyProviderFactory.getContextData(Principal.class);
    if (principal == null) {
        return Optional.empty();
    }

    Map<String, Object> userInfo = new HashMap<>();
    userInfo.put("user_id", principal.getName());
    userInfo.put("date_of_operation", System.currentTimeMillis());

    return Optional.of(userInfo);
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:19,代码来源:MaprDbDao.java

示例8: findURI

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
private static URI findURI(MethodFinder method, Object... params) {
	Method m = method.method();
	
	UriInfo uriInfo = ResteasyProviderFactory.getContextData(UriInfo.class);
	
	UriBuilder builder = uriInfo.getBaseUriBuilder().path(m.getDeclaringClass());
	if(m.isAnnotationPresent(Path.class))
		builder.path(m);
	return builder.build(params);
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:11,代码来源:Router.java

示例9: exec

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@Override
public Object exec(List arguments) throws TemplateModelException {
	if(arguments == null || arguments.size() < 1)
		throw new TemplateModelException("Syntax: route('Class.method', arg1, arg2…)");
	Object arg0 = arguments.get(0);
	if(arg0 instanceof SimpleScalar != true)
		throw new TemplateModelException("Syntax: route('Class.method', arg1, arg2…)");
	String arg1 = ((SimpleScalar)arg0).getAsString();
	int dot = arg1.indexOf('.');
	if(dot == -1)
		throw new TemplateModelException("Syntax: route('Class.method', arg1, arg2…)");
	String klass = arg1.substring(0, dot);
	String method = arg1.substring(dot+1);
	
	for (Class resource : AppGlobals.get().getDeployment().getActualResourceClasses()) {
		dot = resource.getName().lastIndexOf('.');
		String shortName = dot == -1 ? resource.getName() : resource.getName().substring(dot+1);
		if(shortName.equals(klass)) {
			for (Method m : resource.getMethods()) {
				// FIXME: overloading?
				if(m.getName().equals(method)
						&& Modifier.isPublic(m.getModifiers())) {
					UriInfo uriInfo = ResteasyProviderFactory.getContextData(UriInfo.class);
					UriBuilder builder = uriInfo.getBaseUriBuilder().path(resource);
					if(m.isAnnotationPresent(Path.class))
						builder.path(m);
					Object[] params = arguments.subList(1, arguments.size()).toArray();
					return builder.build(params).toString();
				}
			}
			throw new TemplateModelException("Could not find method named "+method+" in resource class "+resource.getName());
		}
	}
	throw new TemplateModelException("Could not find resource class named "+klass);
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:36,代码来源:RouterFunction.java

示例10: render

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@Override
public Single<Response> render(String name, Map<String, Object> variables) {
	RoutingContext context = ResteasyProviderFactory.getContextData(RoutingContext.class);
	for (Entry<String, Object> entry : variables.entrySet()) {
		context.put(entry.getKey(), entry.getValue());
	}
	context.put("route", new RouterFunction());
	return templateEngine.rxRender(context, name)
			// FIXME: other media types perhaps?
			.map(buffer -> Response.ok(buffer, MediaType.TEXT_HTML).build());
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:12,代码来源:FreeMarkerTemplateRenderer.java

示例11: filter

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
	User subject = ResteasyProviderFactory.getContextData(User.class);
	if(subject == null){
		UriBuilder builder = requestContext.getUriInfo().getBaseUriBuilder();
		Session session = ResteasyProviderFactory.getContextData(Session.class);
		session.put(BaseSecurityResource.REDIRECT_KEY, requestContext.getUriInfo().getPath(false));
		URI loginUri = builder.path(BaseSecurityResource.class).path(BaseSecurityResource.class, "login").build();
		requestContext.abortWith(Response.status(Status.TEMPORARY_REDIRECT).location(loginUri).build());
	}
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:12,代码来源:LoginRedirectFilter.java

示例12: filter

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
	Vertx vertx = ResteasyProviderFactory.getContextData(io.vertx.core.Vertx.class);
	ResteasyProviderFactory.pushContext(io.vertx.rxjava.core.Vertx.class, io.vertx.rxjava.core.Vertx.newInstance(vertx));
       HttpServerRequest req = ResteasyProviderFactory.getContextData(HttpServerRequest.class);
	ResteasyProviderFactory.pushContext(io.vertx.rxjava.core.http.HttpServerRequest.class, io.vertx.rxjava.core.http.HttpServerRequest.newInstance(req));
       HttpServerResponse resp = ResteasyProviderFactory.getContextData(HttpServerResponse.class);
	ResteasyProviderFactory.pushContext(io.vertx.rxjava.core.http.HttpServerResponse.class, io.vertx.rxjava.core.http.HttpServerResponse.newInstance(resp));

	ResteasyProviderFactory.pushContext(ServletContext.class, ServletContext);
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:12,代码来源:RxVertxProvider.java

示例13: getEntity

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
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);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:31,代码来源:ActiveMQ.java

示例14: writeTo

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@Override
public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
                    OutputStream entityStream) throws IOException, WebApplicationException {
    Viewable view = viewResolver.getView(obj, type, genericType, annotations);

    if (view == null)
        throw new InternalServerErrorException("No View annotation found for object of type " + type.getName());

    HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
    HttpServletResponse response = ResteasyProviderFactory.getContextData(HttpServletResponse.class);
    try {
        if (view.isRedirect()) {
            String contextPath = request.getContextPath();
            String path = view.getPath();
            if(view.isAbsolute()){
                response.sendRedirect(path);
            }else{
                response.sendRedirect(contextPath + path);
            }
        } else {
            String processedTemplate = view.render(request, response);
            String charset = mediaType.getParameters().get("charset");
            if (charset == null) entityStream.write(processedTemplate.getBytes());
            else entityStream.write(processedTemplate.getBytes(charset));
        }
    } catch (ServletException ex) {
        throw new WebApplicationException(ex);
    }
}
 
开发者ID:koenighotze,项目名称:Hotel-Reservation-Tool,代码行数:30,代码来源:ViewWriter.java

示例15: baseHTML

import org.jboss.resteasy.spi.ResteasyProviderFactory; //导入方法依赖的package包/类
@GET
@Produces({APPLICATION_XHTML_XML, TEXT_HTML})
public void baseHTML(@Context ServletContext context) throws Exception {
    HttpServletResponse response = ResteasyProviderFactory.getContextData(HttpServletResponse.class);
    addHeaders(response);
    response.sendRedirect("/hawkular/metrics" + ClientRouterDispatchingServlet.PATH_INDEX_HTML);
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:8,代码来源:BaseHandler.java


注:本文中的org.jboss.resteasy.spi.ResteasyProviderFactory.getContextData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。