當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。