本文整理匯總了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;
}
示例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());
}
}
}
}
}
示例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";
}
}
示例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";
}
}
示例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);
}
}
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}