java - solucion - una aplicacion sin firma de la siguiente ubicacion esta solicitando permiso
Se detectó una falla HK2 en un código que no se ejecuta en un alcance de error Jersey activo (3)
Actualmente estoy desarrollando una aplicación RESTful basada en jersey y me gustaría usar DPI en mis recursos. (Nota: la versión de jersey es 2.23.1 y el contenedor de servlets es tomcat 8.5.3.)
Por lo tanto, seguí el tutorial Capítulo 23. Inyección personalizada y gestión del ciclo de vida en los documentos del jersey y creé un recurso, una fábrica y enlacé la fábrica a una clase como esta:
Recurso:
@Path("/{project}/catalogs")
public class ProjectsResource {
@Inject
Project project;
...
}
Fábrica:
public class ProjectFactory extends Factory<Project> {
private final Cache cache = cache.getInstance();
@PathParam("project")
private String project;
private HttpServletRequest request;
@Inject
public ProjectFactory(HttpServletRequest request) {
this.request = request;
}
@Override
public Project provide() {
return cache.get(project, Project.class);
}
@Override
public void dispose(Project instance) {}
}
También tengo una función, que registra un AbstractBinder, que une mi ProjectFactory a mi clase Project.
@Provider
public class ProjectFeature implements Feature {
@Override
public boolean configure(FeatureContext context) {
context.register(new AbstractBinder() {
@Override
protected void configure() {
bindFactory(ProjectFactory.class)
.to(Project.class)
.proxy(false)
.proxyForSameScope(true)
.in(RequestScoped.class);
});
return true;
}
}
El problema real es que cuando llamo a mi Recurso todo está bien y puedo acceder a mi instancia de proyecto, pero en mis registros de tomcat catalina estoy obteniendo el siguiente stacke trace:
22-Jul-2016 16:29:46.510 WARNING [pool-24-thread-1] org.glassfish.jersey.internal.Errors.logErrors The following warnings have been detected: WARNING: HK2 failure has been detected in a code that does not run in an active Jersey Error scope. WARNING: Unknown HK2 failure detected: MultiException stack 1 of 3 java.lang.IllegalStateException: Not inside a request scope. at jersey.repackaged.com.google.common.base.Preconditions.checkState(Preconditions.java:173) at org.glassfish.jersey.process.internal.RequestScope.current(RequestScope.java:233) at org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:158) at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2022) at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:765) at org.jvnet.hk2.internal.ServiceLocatorImpl.getUnqualifiedService(ServiceLocatorImpl.java:772) at org.jvnet.hk2.internal.IterableProviderImpl.get(IterableProviderImpl.java:111) at org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory.getContainerRequest(AbstractContainerRequestValueFactory.java:71) at org.glassfish.jersey.server.internal.inject.PathParamValueFactoryProvider$PathParamValueFactory.provide(PathParamValueFactoryProvider.java:93) at org.glassfish.jersey.server.internal.inject.ParamInjectionResolver.resolve(ParamInjectionResolver.java:134) at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:211) at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:234) at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:357) at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471) at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70) at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2022) at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114) at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88) at org.jvnet.hk2.internal.FactoryCreator.dispose(FactoryCreator.java:175) at org.jvnet.hk2.internal.SystemDescriptor.dispose(SystemDescriptor.java:526) at org.glassfish.jersey.process.internal.RequestScope$Instance.remove(RequestScope.java:532) at org.glassfish.jersey.process.internal.RequestScope$Instance.release(RequestScope.java:549) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:968) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:922) at de.moss.ems.rest.resource.AbstractBaseResource.send(AbstractBaseResource.java:118) at de.moss.ems.rest.resource.AbstractBaseResource.resume(AbstractBaseResource.java:165) at de.moss.ems.rest.resource.catalog.CatalogsResource.handleGet(CatalogsResource.java:49) at de.moss.ems.rest.resource.catalog.AbstractCatalogResource.lambda$asyncGetRequest$0(AbstractCatalogResource.java:44) at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) MultiException stack 2 of 3 java.lang.IllegalArgumentException: While attempting to resolve the dependencies of de.moss.ems.rest.factory.ProjectFactory errors were found at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:246) at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:357) at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471) at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70) at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2022) at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114) at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88) at org.jvnet.hk2.internal.FactoryCreator.dispose(FactoryCreator.java:175) at org.jvnet.hk2.internal.SystemDescriptor.dispose(SystemDescriptor.java:526) at org.glassfish.jersey.process.internal.RequestScope$Instance.remove(RequestScope.java:532) at org.glassfish.jersey.process.internal.RequestScope$Instance.release(RequestScope.java:549) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:968) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:922) at de.moss.ems.rest.resource.AbstractBaseResource.send(AbstractBaseResource.java:118) at de.moss.ems.rest.resource.AbstractBaseResource.resume(AbstractBaseResource.java:165) at de.moss.ems.rest.resource.catalog.CatalogsResource.handleGet(CatalogsResource.java:49) at de.moss.ems.rest.resource.catalog.AbstractCatalogResource.lambda$asyncGetRequest$0(AbstractCatalogResource.java:44) at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) MultiException stack 3 of 3 java.lang.IllegalStateException: Unable to perform operation: resolve on de.moss.ems.rest.factory.ProjectFactory at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:386) at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471) at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70) at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2022) at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114) at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88) at org.jvnet.hk2.internal.FactoryCreator.dispose(FactoryCreator.java:175) at org.jvnet.hk2.internal.SystemDescriptor.dispose(SystemDescriptor.java:526) at org.glassfish.jersey.process.internal.RequestScope$Instance.remove(RequestScope.java:532) at org.glassfish.jersey.process.internal.RequestScope$Instance.release(RequestScope.java:549) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:968) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:922) at de.moss.ems.rest.resource.AbstractBaseResource.send(AbstractBaseResource.java:118) at de.moss.ems.rest.resource.AbstractBaseResource.resume(AbstractBaseResource.java:165) at de.moss.ems.rest.resource.catalog.CatalogsResource.handleGet(CatalogsResource.java:49) at de.moss.ems.rest.resource.catalog.AbstractCatalogResource.lambda$asyncGetRequest$0(AbstractCatalogResource.java:44) at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
¿Alguna idea de cómo puedo resolver estas advertencias?
Pude solucionar este error inyectando Factory
lugar de la clase directa. También probé con la inyección HttpServletRequest
y también funciona. Sin embargo, ni @PathParam
ni ninguna otra anotación inteligente funcionó para mí, por lo que es probable que tenga que solucionar su uso.
Mi viejo código:
@Inject
public void setContext(ContainerRequestContext context) {
this.context = context;
}
@Override
public SomeInfo provide() {
return (SomeInfo) context.getProperty(SOME_KEY);
}
Mi nuevo código:
@Inject
public void setContext(Factory<ContainerRequestContext> contextFactory) {
this.contextFactory = contextFactory;
}
@Override
public SomeInfo provide() {
ContainerRequestContext ctx = contextFactory.provide();
try {
return (SomeInfo) ctx.getProperty(SOME_KEY);
} finally {
contextFactory.dispose(ctx);
}
}
Pude resolver este problema utilizando la anotación org.glassfish.hk2.api.PerLookup de org.glassfish.hk2.api.PerLookup
lugar de la anotación Jerseys org.glassfish.jersey.process.internal.RequestScoped
en mi clase AbstractBinder cuando org.glassfish.jersey.process.internal.RequestScoped
mi fábrica a mi interfaz.
import org.glassfish.hk2.api.PerLookup;
@Provider
public class ProjectFeature implements Feature {
@Override
public boolean configure(FeatureContext context) {
context.register(new AbstractBinder() {
@Override
protected void configure() {
bindFactory(ProjectFactory.class)
.to(Project.class)
.proxy(false)
.proxyForSameScope(true)
.in(PerLookup.class);
});
return true;
}
}
Puede verificar si tiene un error de sintaxis en uno de sus métodos en la clase que no puede "importar" con Jersey, para mí este fue el caso. Tenía dos ventajas sin cerrar en una cadena.