@Decorate(id = "doesNotMatchAnyService") public static <T> T doesNotMatchAnyService(ServiceResources resources, T delegate, AspectDecorator aspectDecorator) { Assert.fail("Unexpected invocation"); return delegate; }
private void addDecoratorDef(Method method) { Decorate annotation = method.getAnnotation(Decorate.class); Class serviceInterface = annotation == null ? null : annotation.serviceInterface(); // TODO: methods just named "decorate" String decoratorId = annotation == null ? stripMethodPrefix(method, DECORATE_METHOD_NAME_PREFIX) : extractId( serviceInterface, annotation.id()); // TODO: Check for duplicates Class returnType = method.getReturnType(); if (returnType.isPrimitive() || returnType.isArray()) { throw new RuntimeException(String.format( "Method %s is named like a service decorator method, but the return type (%s) is not acceptable (try Object).", InternalUtils.asString(method), method.getReturnType().getCanonicalName())); } Set<Class> markers = extractMarkers(method, Decorate.class); DecoratorDef def = new DecoratorDefImpl(method, extractPatterns(decoratorId, method), extractConstraints(method), proxyFactory, decoratorId, serviceInterface, markers); decoratorDefs.put(decoratorId, def); }
@Decorate(id = "Cache", serviceInterface = StreamableResourceSource.class) @Order("after:GZipCompression") public StreamableResourceSource enableUncompressedCaching(StreamableResourceSource delegate, ResourceChangeTracker tracker) { return new SRSCachingInterceptor(delegate, tracker); }
private void addDecoratorDef(Method method) { Decorate annotation = method.getAnnotation(Decorate.class); Class serviceInterface = annotation == null ? null : annotation.serviceInterface(); // TODO: methods just named "decorate" String decoratorId = annotation == null ? stripMethodPrefix(method, DECORATE_METHOD_NAME_PREFIX) : extractId( serviceInterface, annotation.id()); // TODO: Check for duplicates Class returnType = method.getReturnType(); if (returnType.isPrimitive() || returnType.isArray()) { throw new RuntimeException(String.format( "Method %s is named like a service decorator method, but the return type (%s) is not acceptable (try Object).", InternalUtils.asString(method), method.getReturnType().getCanonicalName())); } Set<Class> markers = extractMarkers(method, Decorate.class); DecoratorDef def = new DecoratorDefImpl(method, extractPatterns(decoratorId, method), extractConstraints(method), proxyFactory, decoratorId, serviceInterface, markers); decoratorDefs.put(decoratorId, def); }
/** * Ensures that all "text/*" assets are given the UTF-8 charset. * * @since 5.4 */ @Decorate(id = "TextUTF8", serviceInterface = StreamableResourceSource.class) @Order("after:Cache") public StreamableResourceSource setupTextAssetsAsUTF8(StreamableResourceSource delegate) { return new UTF8ForTextAssets(delegate); }
@Decorate(id = "DisableMinificationForStacks", serviceInterface = StreamableResourceSource.class) @Order("before:Minification") public StreamableResourceSource setupDisableMinificationByJavaScriptStack(StreamableResourceSource delegate, @Symbol(SymbolConstants.MINIFICATION_ENABLED) boolean enabled, JavaScriptStackSource javaScriptStackSource, Request request) { return enabled ? new JavaScriptStackMinimizeDisabler(delegate, javaScriptStackSource, request) : null; }
@Decorate(id = "CacheCompressed", serviceInterface = StreamableResourceSource.class) @Order("before:GZIpCompression") public StreamableResourceSource enableCompressedCaching(StreamableResourceSource delegate, @Symbol(SymbolConstants.GZIP_COMPRESSION_ENABLED) boolean gzipEnabled, ResourceChangeTracker tracker) { return gzipEnabled ? new SRSCompressedCachingInterceptor(delegate, tracker) : null; }
@Decorate(id = "Minification", serviceInterface = StreamableResourceSource.class) @Order("after:Cache,TextUTF8") public StreamableResourceSource enableMinification(StreamableResourceSource delegate, ResourceMinimizer minimizer, @Symbol(SymbolConstants.MINIFICATION_ENABLED) boolean enabled) { return enabled ? new SRSMinimizingInterceptor(delegate, minimizer) : null; }
@Decorate(id = "CSSURLRewrite", serviceInterface = StreamableResourceSource.class) @Order("after:Minification") public StreamableResourceSource enableCSSURLRewriting(StreamableResourceSource delegate, OperationTracker tracker, AssetSource assetSource, AssetChecksumGenerator checksumGenerator, @Symbol(SymbolConstants.STRICT_CSS_URL_REWRITING) boolean strictCssUrlRewriting) { return new CSSURLRewriter(delegate, tracker, assetSource, checksumGenerator, strictCssUrlRewriting); }
@Decorate(serviceInterface = Sample.class) public static Sample enableJMXForSample(Sample service, MBeanSupport managedBeanSupport) { managedBeanSupport.register(service, "org.example.testapp.services:service=Sample"); return service; } }
@Decorate(id = "GZipCompression", serviceInterface = StreamableResourceSource.class) public StreamableResourceSource enableCompression(StreamableResourceSource delegate, @Symbol(SymbolConstants.GZIP_COMPRESSION_ENABLED) boolean gzipEnabled, @Symbol(SymbolConstants.MIN_GZIP_SIZE) int compressionCutoff, AssetChecksumGenerator checksumGenerator) { return gzipEnabled ? new SRSCompressingInterceptor(delegate, compressionCutoff, checksumGenerator) : null; }
@Decorate(serviceInterface = Greeter.class) @GreenMarker public static <T> T greeter(ServiceResources resources, T delegate, AspectDecorator aspectDecorator) { return doDecorate("foo", resources, delegate, aspectDecorator); }
@Decorate(serviceInterface = Greeter.class, id = "barney") @Local public static <T> T localAdvise(ServiceResources resources, T delegate, AspectDecorator aspectDecorator) { return doDecorate("barney", resources, delegate, aspectDecorator); }
@Decorate @Match("RedGreeter") public static <T> T byMatchAnnotation(ServiceResources resources, T delegate, AspectDecorator aspectDecorator) { return doDecorate("alpha", resources, delegate, aspectDecorator); }
@Decorate(serviceInterface = Greeter.class, id = "bar") @GreenMarker @Order("after:Greeter") public static <T> T greeter2(ServiceResources resources, T delegate, AspectDecorator aspectDecorator) { return doDecorate("bar", resources, delegate, aspectDecorator); }
@Decorate(id = "withMarker") @RedMarker @Order("before:*") public static <T> T byMarkerAnnotation(ServiceResources resources, T delegate, AspectDecorator aspectDecorator) { return doDecorate("beta", resources, delegate, aspectDecorator); }
@Decorate(serviceInterface = Greeter.class, id = "baz") @GreenMarker @Order({"after:Greeter", "before:bar"}) public static <T> T greeter3(ServiceResources resources, T delegate, AspectDecorator aspectDecorator) { return doDecorate("baz", resources, delegate, aspectDecorator); }
@Decorate(serviceInterface = AnnotatedServiceInterface.class) public static AnnotatedServiceInterface decorateAnnotated(AnnotatedServiceInterface delegate, AspectDecorator aspectDecorator) { final AspectInterceptorBuilder<AnnotatedServiceInterface> builder = aspectDecorator .createBuilder(AnnotatedServiceInterface.class, delegate, "!"); builder.adviseAllMethods(new TestAdvice()); return builder.build(); }
@Decorate(serviceInterface = NonAnnotatedServiceInterface.class) public static NonAnnotatedServiceInterface decorateNonAnnotated( NonAnnotatedServiceInterface delegate, AspectDecorator aspectDecorator) { final AspectInterceptorBuilder<NonAnnotatedServiceInterface> builder = aspectDecorator .createBuilder(NonAnnotatedServiceInterface.class, delegate, "!"); builder.adviseAllMethods(new TestAdvice()); return builder.build(); }