/** * {@inheritDoc} */ public static <PC extends PipelineComponent> LinkedPipelineStarterBuilder<PC> newCachingPipeline() { return newPipeline(new CachingPipeline<PC>()); }
@Override public void setup(OutputStream outputStream, Map<String, Object> parameters) { // create a caching output stream to intercept the result this.cachingOutputStream = new CachingOutputStream(outputStream); super.setup(this.cachingOutputStream, parameters); this.cacheKey = this.constructCacheKey(); }
@Override public void execute() throws Exception { if (this.logger.isDebugEnabled()) { this.logger.debug("Used cache: " + this.cache); } // checked for a cached value first CacheValue cachedValue = this.getCachedValue(this.cacheKey); if (this.isCacheKeyValid(cachedValue)) { // cached value found if (this.logger.isDebugEnabled()) { this.logger.debug("Write cache value to output stream: " + cachedValue); } cachedValue.writeTo(this.cachingOutputStream.getOutputStream()); return; } // execute the pipeline this.invokeStarter(); // cache the result CompleteCacheValue cacheValue = new CompleteCacheValue(this.cachingOutputStream.getContent(), this.cacheKey); this.setCachedValue(this.cacheKey, cacheValue); }
for (PipelineComponent pipelineComponent : this.getComponents()) { if (pipelineComponent instanceof CachingPipelineComponent) { CachingPipelineComponent cachablePipelineComponent = (CachingPipelineComponent) pipelineComponent;
if (pipeline instanceof CachingPipeline) { CachingPipeline<PipelineComponent> cachingPipeline = (CachingPipeline<PipelineComponent>) pipeline; CacheKey cacheKey = cachingPipeline.getCacheKey(); if (cacheKey != null) { setETag(Integer.toHexString(cacheKey.hashCode()));
/** * {@inheritDoc} */ public static LinkedSAXPipelineStarterBuilder newCachingPipeline() { return newPipeline(new CachingPipeline<SAXPipelineComponent>()); }
@GET @Path("schema/json") public Response schemaJson(@Context final HttpServletRequest request, @Context final HttpServletResponse response) throws Exception { final Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<SAXPipelineComponent>(); pipeline.addComponent(new XMLGenerator(applicationWADL())); final XSLTTransformer schemaXSLT = new XSLTTransformer(getClass().getResource("/jsonxsd.xsl")); final Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("contextPath", request.getContextPath()); parameters.put("schema-position", 1); parameters.put("schema-prefix", "schema"); schemaXSLT.setParameters(parameters); pipeline.addComponent(schemaXSLT); pipeline.addComponent(XMLSerializer.createHTML4Serializer()); pipeline.setup(response.getOutputStream()); pipeline.execute(); return Response.ok().build(); }
@GET public Response doGet(@Context final HttpServletRequest request, @Context final HttpServletResponse response) throws Exception { final Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<SAXPipelineComponent>(); pipeline.addComponent(new XMLGenerator(applicationWADL())); final XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/indexnew.xsl")); final Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("contextPath", request.getContextPath()); parameters.put("application", "application"); xslt.setParameters(parameters); pipeline.addComponent(xslt); pipeline.addComponent(XMLSerializer.createHTML4Serializer()); pipeline.setup(response.getOutputStream()); pipeline.execute(); return Response.ok().build(); }
@GET @Path("schema") public Response schema(@Context final HttpServletRequest request, @Context final HttpServletResponse response) throws Exception { final Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<SAXPipelineComponent>(); pipeline.addComponent(new XMLGenerator(applicationWADL())); final XSLTTransformer schemaXSLT = new XSLTTransformer(getClass().getResource("/schemanew.xsl")); final Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("contextPath", request.getContextPath()); parameters.put("schema-position", 1); parameters.put("schema-prefix", "schema"); schemaXSLT.setParameters(parameters); pipeline.addComponent(schemaXSLT); pipeline.addComponent(XMLSerializer.createHTML4Serializer()); pipeline.setup(response.getOutputStream()); pipeline.execute(); return Response.ok().build(); }
String wadl = wadlGenerator.getWadl(); Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<>(); pipeline.addComponent(new XMLGenerator(wadl)); if ("/index.html".equals(request.getServletPath())) {
public byte[] applicationWADL() throws Exception { final ByteArrayOutputStream baos; final Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<SAXPipelineComponent>(); final Application application = wadlContext.getApplication(uriInfo, false).getApplication(); /* * Get the current XML WADL into a byte array. */ final Marshaller marshaller = wadlContext.getJAXBContext().createMarshaller(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); marshaller.marshal(application, os); final byte[] wadlXmlRepresentation = os.toByteArray(); final XMLGenerator pipelineComponent = new XMLGenerator(wadlXmlRepresentation); pipeline.addComponent(pipelineComponent); pipeline.addComponent(new XSLTTransformer(getClass().getResource("/prepare-includenew.xsl"))); pipeline.addComponent(new XIncludeTransformer(getClass().getResource("/"))); pipeline.addComponent(XMLSerializer.createXMLSerializer()); baos = new ByteArrayOutputStream(); pipeline.setup(baos); pipeline.execute(); return baos.toByteArray(); }