Package ro.isdc.wro.config.jmx

Examples of ro.isdc.wro.config.jmx.WroConfiguration


  /**
   * Write to stream the content of the processed resource bundle.
   */
  public void serveProcessedBundle()
      throws IOException {
    final WroConfiguration configuration = context.getConfig();
    final HttpServletRequest request = context.getRequest();
    final HttpServletResponse response = context.getResponse();

    OutputStream os = null;
    try {

      final CacheKey cacheKey = getSafeCacheKey(request);
      initAggregatedFolderPath(request, cacheKey.getType());
      final CacheValue cacheValue = cacheStrategy.get(cacheKey);

      // TODO move ETag check in wroManagerFactory
      final String ifNoneMatch = request.getHeader(HttpHeader.IF_NONE_MATCH.toString());

      // enclose etag value in quotes to be compliant with the RFC
      final String etagValue = String.format("\"%s\"", cacheValue.getHash());

      if (etagValue != null && etagValue.equals(ifNoneMatch)) {
        LOG.debug("ETag hash detected: {}. Sending {} status code", etagValue, HttpServletResponse.SC_NOT_MODIFIED);
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        // because we cannot return null, return a stream containing nothing.
        // TODO close output stream?
        return;
      }
      /**
       * Set contentType before actual content is written, solves <br/>
       * <a href="http://code.google.com/p/wro4j/issues/detail?id=341">issue341</a>
       */
      response.setContentType(cacheKey.getType().getContentType() + "; charset=" + configuration.getEncoding());
      // set ETag header
      response.setHeader(HttpHeader.ETAG.toString(), etagValue);

      os = response.getOutputStream();
      if (cacheValue.getRawContent() != null) {
        // use gziped response if supported & Set content length based on gzip flag
        if (isGzipAllowed()) {
          response.setContentLength(cacheValue.getGzippedContent().length);
          // add gzip header and gzip response
          response.setHeader(HttpHeader.CONTENT_ENCODING.toString(), "gzip");
          response.setHeader("Vary", "Accept-Encoding");
          IOUtils.write(cacheValue.getGzippedContent(), os);
        } else {
          //using getRawContent().length() is not the same and can return 2Bytes smaller size.
          response.setContentLength(cacheValue.getRawContent().getBytes(configuration.getEncoding()).length);
          IOUtils.write(cacheValue.getRawContent(), os, configuration.getEncoding());
        }
      }
    } finally {
      if (os != null) {
        IOUtils.closeQuietly(os);
View Full Code Here


      throws IOException {
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    final HttpServletResponse response = Mockito.mock(HttpServletResponse.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(request.getRequestURI()).thenReturn("/app/g3.css");

    final WroConfiguration config = new WroConfiguration();
    config.setDebug(true);
    Context.unset();
    Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class)));

    final WroManager wroManager = managerFactory.create();
    wroManager.process();
View Full Code Here

    Validate.notNull(props);
    this.properties = props;
  }

  public WroConfiguration create() {
    final WroConfiguration config = new WroConfiguration();
    config.setDebug(valueAsBoolean(properties.get(ConfigConstants.debug.name()), true));
    config.setGzipEnabled(valueAsBoolean(properties.get(ConfigConstants.gzipResources.name()), true));
    config.setJmxEnabled(valueAsBoolean(properties.get(ConfigConstants.jmxEnabled.name()), true));
    config.setCacheUpdatePeriod(valueAsLong(properties.get(ConfigConstants.cacheUpdatePeriod.name()), 0));
    config.setModelUpdatePeriod(valueAsLong(properties.get(ConfigConstants.modelUpdatePeriod.name()), 0));
    config.setResourceWatcherUpdatePeriod(valueAsLong(
        properties.get(ConfigConstants.resourceWatcherUpdatePeriod.name()), 0));
    config.setResourceWatcherAsync(valueAsBoolean(properties.get(ConfigConstants.resourceWatcherAsync.name()), false));
    config.setMinimizeEnabled(valueAsBoolean(properties.get(ConfigConstants.minimizeEnabled.name()), true));
    config.setIgnoreMissingResources(valueAsBoolean(properties.get(ConfigConstants.ignoreMissingResources.name()), true));
    config.setIgnoreEmptyGroup(valueAsBoolean(properties.get(ConfigConstants.ignoreEmptyGroup.name()), true));
    config.setIgnoreFailingProcessor(valueAsBoolean(properties.get(ConfigConstants.ignoreFailingProcessor.name()), false));
    config.setEncoding(valueAsString(properties.get(ConfigConstants.encoding.name()), WroConfiguration.DEFAULT_ENCODING));
    config.setWroManagerClassName(valueAsString(properties.get(ConfigConstants.managerFactoryClassName.name())));
    config.setMbeanName(valueAsString(properties.get(ConfigConstants.mbeanName.name())));
    config.setHeader(valueAsString(properties.get(ConfigConstants.header.name())));
    config.setCacheGzippedContent(valueAsBoolean(properties.get(ConfigConstants.cacheGzippedContent.name()), false));
    config.setParallelPreprocessing(valueAsBoolean(properties.get(ConfigConstants.parallelPreprocessing.name()), false));
    config.setConnectionTimeout((int) valueAsLong(properties.get(ConfigConstants.connectionTimeout.name()),
        WroConfiguration.DEFAULT_CONNECTION_TIMEOUT));
    LOG.debug("WroConfiguration created: {}", config);
    return config;
  }
View Full Code Here

    Assert.assertNotNull(entry.getGzippedContent());
  }

  @Test
  public void changingFlagShouldHaveNoEffect() {
    final WroConfiguration config = Context.get().getConfig();
    config.setCacheGzippedContent(false);
    final CacheValue entry = CacheValue.valueOf(RAW_CONTENT, "hash");
    Assert.assertNull(null, entry.getGzippedContentInternal());

    config.setCacheGzippedContent(true);
    Assert.assertNull(null, entry.getGzippedContentInternal());

    Assert.assertNotNull(entry.getGzippedContent());
  }
View Full Code Here

      Mockito.when(response.getOutputStream()).thenReturn(
          new DelegatingServletOutputStream(new WriterOutputStream(writer)));
      Mockito.when(request.getRequestURI()).thenReturn("");

      final WroConfiguration config = new WroConfiguration();
      // we don't need caching here, otherwise we'll have clashing during unit tests.
      config.setDebug(true);
      Context.unset();
      Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class)), config);

      // create a groupExtractor which always return the same group name.
      final String groupName = "group";
View Full Code Here

    victim.setManagerFactory(null);
  }

  @Test
  public void shouldUseTheConfigurationSet() {
    final WroConfiguration configuration = new WroConfiguration();
    victim.setConfiguration(configuration);
    victim.contextInitialized(mockServletContextEvent);
    Assert.assertSame(configuration, victim.getConfiguration());
  }
View Full Code Here

  }


  @Test
  public void shouldUseOverridenConfiguration() {
    final WroConfiguration configuration = new WroConfiguration();
    victim = new WroServletContextListener() {
      @Override
      protected WroConfiguration newConfiguration() {
        return configuration;
      }
View Full Code Here

    assertFalse(Context.isContextSet());
  }
 
  @Test
  public void shouldUseWroConfigurationFoundInServletContext() throws Exception {
    final WroConfiguration config = new WroConfiguration();
    config.setCacheUpdatePeriod(1000);
   
    when(mockServletContextAttributeHelper.getWroConfiguration()).thenReturn(config);
    doAnswer(new Answer<Void>() {
      public Void answer(InvocationOnMock invocation)
          throws Throwable {
View Full Code Here

    assertEquals(0, Context.countActive());
  }
 
  @Before
  public void setUp() {
    final WroConfiguration config = new WroConfiguration();
    config.setIgnoreFailingProcessor(true);
    Context.set(Context.standaloneContext(), config);
    victim = new LessCssImportPreProcessor();
    WroTestUtils.initProcessor(victim);
  }
View Full Code Here

    when(mockRequest.getRequestURL()).thenReturn(new StringBuffer(""));
    when(mockRequest.getServletPath()).thenReturn("");
    when(mockFilterConfig.getServletContext()).thenReturn(mockServletContext);

    final Context context = Context.webContext(mockRequest, mockResponse, mockFilterConfig);
    final WroConfiguration config = new WroConfiguration();
    config.setConnectionTimeout(100);
    Context.set(context, config);

    victim = new ServletContextUriLocator();

    initLocator(victim);
View Full Code Here

TOP

Related Classes of ro.isdc.wro.config.jmx.WroConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.