UrlUriLocator handling of compressed/gzipped javascript without vary : accept-encoding header

97 views
Skip to first unread message

Eric Sun

unread,
Jun 19, 2014, 11:52:42 PM6/19/14
to wr...@googlegroups.com
Hi I am trying to include an external JS hosted on AWS which is gzipped. Wro4j went and grabbed the file but did not uncompress it before concatenates it to the rest of the files.

Many CDN hosts such as google would have the vary : accept-encoding to signify that the content-length cannot be trusted so use the uncompress one instead (?) but Amazon doesn't allow that. 

Has anyone ran into this issue? I have search and look anywhere with no lucky. Any pointer is appreciated.

Alex Objelean

unread,
Jun 20, 2014, 4:01:38 AM6/20/14
to wr...@googlegroups.com
Hi Eric,

The external resources are grabbed by UrlUriLocator, which just open a connection and read the content as is. 
The quickest solution, is to replace UrlUriLocator with a custom one which would handle this situation. 
Could you open an issue? 
If you have a suggestion regarding implementation, a pull request is welcome anytime.

Cheers,
Alex


--
You received this message because you are subscribed to the Google Groups "wro4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wro4j+un...@googlegroups.com.
To post to this group, send email to wr...@googlegroups.com.
Visit this group at http://groups.google.com/group/wro4j.
For more options, visit https://groups.google.com/d/optout.

Eric Sun

unread,
Jun 30, 2014, 12:36:48 PM6/30/14
to wr...@googlegroups.com
Hi Alex, thanks for your reply, I am trying to override the newUriLocatorFactory 


public class CustomWroManagerFactory   extends DefaultStandaloneContextAwareManagerFactory {

@Override
      protected UriLocatorFactory newUriLocatorFactory() {

               SimpleUriLocatorFactory factory = new SimpleUriLocatorFactory();

               factory.addUriLocator(new ServletContextUriLocator());

               factory.addUriLocator(new ClasspathUriLocator());

               factory.addUriLocator(new CustomUrlUriLocator());


                return factory;


        }


But I am getting Null Pointer Exception at ServletContextUriLocator, I am using wro4j 1.4.5, do you know why this would happen? Thanks

Alex Objelean

unread,
Jun 30, 2014, 12:41:44 PM6/30/14
to wr...@googlegroups.com
Hi,

first, you could try upgrading to newer version 1.7.6. 
Second, provide some stacktrace, otherwise I don't have enough information to understand what the problem is.

Thanks,
Alex

Eric Sun

unread,
Jun 30, 2014, 1:13:05 PM6/30/14
to wr...@googlegroups.com
Sorry here is the stack trace

[ERROR] Failed to execute goal ro.isdc.wro4j:wro4j-maven-plugin:1.4.5:run (V1) on projectjavascript-sdk: Exception occured while processing: null: NullPointerException -> [Help 1]

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal ro.isdc.wro4j:wro4j-maven-plugin:1.4.5:run (V1) on project ius-javascript-sdk: Exception occured while processing: null

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)

at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)

at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)

at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)

at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)

at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)

at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)

at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)

at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)

at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)

at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)

at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)

at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Caused by: org.apache.maven.plugin.MojoExecutionException: Exception occured while processing: null

at ro.isdc.wro.maven.plugin.AbstractWro4jMojo.execute(AbstractWro4jMojo.java:108)

at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)

... 19 more

Caused by: java.lang.NullPointerException

at ro.isdc.wro.model.resource.locator.DispatcherStreamLocator.computeServletContextPath(DispatcherStreamLocator.java:56)

at ro.isdc.wro.model.resource.locator.DispatcherStreamLocator.getInputStream(DispatcherStreamLocator.java:47)

at ro.isdc.wro.model.resource.locator.ServletContextUriLocator.dispatcherBasedStreamLocator(ServletContextUriLocator.java:187)

at ro.isdc.wro.model.resource.locator.ServletContextUriLocator.dispatcherFirstStreamLocator(ServletContextUriLocator.java:174)

at ro.isdc.wro.model.resource.locator.ServletContextUriLocator.locate(ServletContextUriLocator.java:149)

at ro.isdc.wro.model.resource.locator.factory.AbstractUriLocatorFactory.locate(AbstractUriLocatorFactory.java:39)

at ro.isdc.wro.model.group.processor.PreProcessorExecutor.getResourceContent(PreProcessorExecutor.java:191)

at ro.isdc.wro.model.group.processor.PreProcessorExecutor.applyPreProcessors(PreProcessorExecutor.java:161)

at ro.isdc.wro.model.group.processor.PreProcessorExecutor.processAndMerge(PreProcessorExecutor.java:82)

at ro.isdc.wro.model.group.processor.GroupsProcessor$1.processAndMerge(GroupsProcessor.java:90)

at ro.isdc.wro.model.group.processor.GroupsProcessor.process(GroupsProcessor.java:71)

at ro.isdc.wro.manager.WroManager.getContentHashEntry(WroManager.java:287)

at ro.isdc.wro.manager.WroManager.serveProcessedBundle(WroManager.java:176)

at ro.isdc.wro.manager.WroManager.process(WroManager.java:129)

at ro.isdc.wro.maven.plugin.Wro4jMojo.processGroup(Wro4jMojo.java:213)

at ro.isdc.wro.maven.plugin.Wro4jMojo.doExecute(Wro4jMojo.java:118)

at ro.isdc.wro.maven.plugin.AbstractWro4jMojo.execute(AbstractWro4jMojo.java:106)

... 21 more

Alex Objelean

unread,
Jun 30, 2014, 2:11:21 PM6/30/14
to wr...@googlegroups.com

Have you tried upgrading to a newer version?

Eric Sun

unread,
Jul 1, 2014, 1:35:24 PM7/1/14
to wr...@googlegroups.com
Hi Alex,

our project is still on JDK 1.6 but running with wro4j 1.7.6 I encountered

Failed to execute goal ro.isdc.wro4j:wro4j-maven-plugin:1.7.6:run (V1) on project javascript-sdk: Execution V1 of goal ro.isdc.wro4j:wro4j-maven-plugin:1.7.6:run failed: An API incompatibility was encountered while executing ro.isdc.wro4j:wro4j-maven-plugin:1.7.6:run: java.lang.UnsupportedClassVersionError: com/google/javascript/jscomp/CodingConvention : Unsupported major.minor version 51.0

It seems like it's expecting JDK 1.7? What's the highest wro4j release that support JDK 1.6?

Also in the wiki, it states as long as you have JDK 1.6 you would be ok.

https://code.google.com/p/wro4j/wiki/GettingStarted

Thanks

Eric

Alex Objelean

unread,
Jul 1, 2014, 4:19:44 PM7/1/14
to wr...@googlegroups.com
That is correct. The wro4j-maven-plugin require JDK 1.6 (while wro4j-core accepts also JDK 1.5.0).
I have tried it locally, using the wro4j-standalone example project. On my laptop, the java version is:
java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1ubuntu1~0.12.04.2)
OpenJDK Server VM (build 23.25-b01, mixed mode)

Running mvn clean wro4j:run from console doesn't show any error related to jdk incompatibility. 

Could you try using wro4j-standalone project as well? You could also try forking it and apply any change which would help to reproduce the issue.

Thanks,
Alex

Eric Sun

unread,
Jul 18, 2014, 6:00:43 PM7/18/14
to wr...@googlegroups.com

Ok i finally got it working.

First the problem was I was using standaloneContextAwareManagerFactory and i had to get the context into the new factory by calling super.newServletContextUriLocator()

@Override
protected UriLocatorFactory newUriLocatorFactory() {
     
SimpleUriLocatorFactory factory = new SimpleUriLocatorFactory();

      factory
.addLocator(super.newServletContextUriLocator());
            factory.addLocator(new ClasspathUriLocator());
            factory.addLocator(new CustomUrlUriLocator());
            return factory;
 }

Then in the CustomUrlUriLocator I extended the UrlUriLocator and override the locate function with gzip encoding check.


@Override
 public InputStream locate(final String uri) throws IOException {
...                


           if ("gzip".equals(connection.getContentEncoding())) {
                        return new GZIPInputStream(connection.getInputStream());
                   }

                   return new BufferedInputStream(connection.getInputStream());


        }


didn't check the JDK 1.7 requirement with wro4j-standalone project for wro4j 1.7.6 but I suspect if GoogleClosureCompiler is use it will give it the error.
Reply all
Reply to author
Forward
0 new messages