jersey
  1. jersey
  2. JERSEY-1117

hk2 throws an exception when cannot inject entity

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0-m04, 2.0-m12
    • Fix Version/s: 2.0-m05, 2.0-m13, 2.0
    • Component/s: core
    • Labels:
      None

      Description

      Suppose:

      public class ParamEntityThrowingWebApplicationException {
      
          public static ParamEntityThrowingWebApplicationException fromString(
                  String arg) {
              throw new WebApplicationException(Status.valueOf(parseArg(arg)));
          }
      
          protected static String parseArg(String arg) {
              return arg.contains("=") ? arg.replaceAll(".*=", "") : arg;
          }
      } 
      
      @Path(value = "/QueryParamTest")
      public class QueryParamTest extends ParamTest {
      	@QueryParam("FieldParamEntityThrowingWebApplicationException")
      	ParamEntityThrowingWebApplicationException fieldEntityThrowingWebApplicationException;
      
              @GET
          @Produces("text/plain")
          public String stringParamHandling(...)
      }
      

      When

      GET /jaxrs_ee_rs_queryparam_web/QueryParamTest?
      

      then

      org.jvnet.hk2.component.UnsatisfiedDependencyException: injection failed on com.sun.ts.tests.jaxrs.ee.rs.queryparam.QueryParamTest.fieldEntityThrowingWebApplicationException with class com.sun.ts.tests.jaxrs.ee.rs.ParamEntityThrowingWebApplicationException
      at org.jvnet.hk2.component.InjectionManager.syncDoInject(InjectionManager.java:211)
      at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:107)
      at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:127)
      at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:117)
      at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:84)
      at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:135)
      at org.jvnet.hk2.component.Habitat.getByType(Habitat.java:1387)
      at org.jvnet.hk2.component.Habitat.inject(Habitat.java:1196)
      at org.glassfish.jersey.server.internal.routing.PushResourceUriAndDelegateTreeAcceptor.pushMatchedToRoutingContext(PushResourceUriAndDelegateTreeAcceptor.java:74)
      at org.glassfish.jersey.server.internal.routing.AbstractPushRoutingInfoAndDelegateTreeAcceptor.apply(AbstractPushRoutingInfoAndDelegateTreeAcceptor.java:79)
      at org.glassfish.jersey.process.internal.HierarchicalRequestProcessor._apply(HierarchicalRequestProcessor.java:107)
      at org.glassfish.jersey.process.internal.HierarchicalRequestProcessor._apply(HierarchicalRequestProcessor.java:114)
      at org.glassfish.jersey.process.internal.HierarchicalRequestProcessor._apply(HierarchicalRequestProcessor.java:114)
      at org.glassfish.jersey.process.internal.HierarchicalRequestProcessor.apply(HierarchicalRequestProcessor.java:101)
      at org.glassfish.jersey.process.internal.RequestInvoker$AcceptingInvoker.apply(RequestInvoker.java:252)
      at org.glassfish.jersey.process.internal.RequestInvoker$AcceptingInvoker.apply(RequestInvoker.java:236)
      at org.glassfish.jersey.process.internal.AsyncInflectorAdapter.apply(AsyncInflectorAdapter.java:121)
      at org.glassfish.jersey.process.internal.RequestInvoker$2.runInScope(RequestInvoker.java:212)
      at org.glassfish.jersey.process.internal.RequestInvoker$2.run(RequestInvoker.java:187)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
      at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:44)
      at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:41)
      at org.glassfish.jersey.process.internal.RequestInvoker.apply(RequestInvoker.java:220)
      at org.glassfish.jersey.server.ApplicationHandler.apply(ApplicationHandler.java:477)
      at org.glassfish.jersey.server.ApplicationHandler.apply(ApplicationHandler.java:445)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:226)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:323)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:290)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:176)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1815)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)

        Activity

        Hide
        Pavel Bucek added a comment -
        --- a/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/ParamInjectionResolver.java
        +++ b/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/ParamInjectionResolver.java
        @@ -94,7 +94,7 @@ public abstract class ParamInjectionResolver<A extends Annotation> extends Injec
         
             @Override
             public boolean isOptional(AnnotatedElement annotated, A annotation) {
        -        return false; // TODO - is this ok?
        +        return true;
             }
         
        Show
        Pavel Bucek added a comment - --- a/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/ParamInjectionResolver.java +++ b/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/ParamInjectionResolver.java @@ -94,7 +94,7 @@ public abstract class ParamInjectionResolver<A extends Annotation> extends Injec @Override public boolean isOptional(AnnotatedElement annotated, A annotation) { - return false ; // TODO - is this ok? + return true ; }
        Hide
        jan.supol added a comment -

        The problem persists. Specifically, the Spec. Section 3.2 says:

        A WebApplicationException thrown during construction of field or property values using 2 or 3 above
        is processed directly as described in Section 3.3.4. Other exceptions thrown during construction of field
        or property values using 2 or 3 above are treated as client errors: if the field or property is annotated with
        @MatrixParam, @QueryParam or @PathParam then an implementation MUST generate an instance of
        NotFoundException (404 status) that wraps the thrown exception and no entity; if the field or property is
        annotated with @HeaderParam or @CookieParam then an implementation MUST generate an instance of
        BadRequestException (400 status) that wraps the thrown exception and no entity. Exceptions MUST be
        processed as described in Section 3.3.4.

        The exception thrown is in wrapped hk2 runtime exception and exception mapper catching webapplicationexception is of no use here.

        Show
        jan.supol added a comment - The problem persists. Specifically, the Spec. Section 3.2 says: A WebApplicationException thrown during construction of field or property values using 2 or 3 above is processed directly as described in Section 3.3.4. Other exceptions thrown during construction of field or property values using 2 or 3 above are treated as client errors: if the field or property is annotated with @MatrixParam, @QueryParam or @PathParam then an implementation MUST generate an instance of NotFoundException (404 status) that wraps the thrown exception and no entity; if the field or property is annotated with @HeaderParam or @CookieParam then an implementation MUST generate an instance of BadRequestException (400 status) that wraps the thrown exception and no entity. Exceptions MUST be processed as described in Section 3.3.4. The exception thrown is in wrapped hk2 runtime exception and exception mapper catching webapplicationexception is of no use here.

          People

          • Assignee:
            Pavel Bucek
            Reporter:
            jan.supol
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 2 hours, 30 minutes Time Not Required
              2h 30m