jersey
  1. jersey
  2. JERSEY-1695

Annotating Application subclass with @NameBinding annotation has no effect

    Details

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

      Description

      Spec. Section 6.5.2 says:

      the application subclass must be annotated
      as shown above in order for those filters or interceptors to be globally bound.

      @NameBinding
      @Target({ ElementType.TYPE, ElementType.METHOD })
      @Retention(value = RetentionPolicy.RUNTIME)
      public @interface GlobalNameBinding {
      }
      
      @Provider
      @GlobalNameBinding
      public class AddOneInterceptor implements
      		WriterInterceptor {
      	public void aroundWriteTo(WriterInterceptorContext context)
      			throws IOException, WebApplicationException {
      		String entity = (String) context.getEntity();
      		Integer i = Integer.parseInt(entity);
      		entity = String.valueOf(i + 1);
      		context.setEntity(entity);
      		context.proceed();
      	}
      }
      
      @Provider
      @GlobalNameBinding
      public class AddTenFilter implements ContainerResponseFilter {
      	@Override
      	public void filter(ContainerRequestContext requestContext,
      			ContainerResponseContext responseContext) throws IOException {
      		int status = responseContext.getStatus();
      		String entity = (String) responseContext.getEntity();
      		Integer i = Integer.valueOf(entity);
      		entity = String.valueOf(i + 10);
      		responseContext.setEntity(entity, (Annotation[]) null,
      					MediaType.WILDCARD_TYPE);
      	}
      }
      
      @GlobalNameBinding
      public class MyApp extends Application {
      
      	public java.util.Set<java.lang.Class<?>> getClasses() {
      		Set<Class<?>> resources = new HashSet<Class<?>>();
      		resources.add(Resource.class);
      		resources.add(AddOneInterceptor.class);
      		resources.add(AddTenFilter.class);
      		return resources;
      	}
      }
      
      @Path("resource")
      public class Resource {
      	
      	@POST
      	@Path("bind")
      	@GlobalNameBinding
      	public String echoWithBind(String echo){
      		return echo;
      	}
      	
      	@POST
      	@Path("nobind")
      	public String echoNoBind(String echo){
      		return echo;
      	}
      }
      

      Request:

      POST http://localhost:6080/resource/bind
      Accept:/, Content-Type:/,
      0

      gives 11, where as

      POST http://localhost:6080/resource/nobind
      Accept:/, Content-Type:/,
      0

      gives 0.

        Activity

        There are no comments yet on this issue.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 3 hours
              3h