Page 1 of 1

File not found exception for static files?

Posted: Fri May 23, 2014 4:00 pm
by daniel_locious
Hi guys,

What's the difference between development and production modes, in regarding static files in broadleaf?

I setup my test environment to production mode, under tomcat, configured postgres, and start the app on version 3.1.2-GA, up-to-date.

The problem is I can't get css files and images or any other static files that suppose not changed.

It seems broadleaf had some optimation strategy to bundle the css files into one, under production mode; but tomcat can't find it?!
May 22, 2014 1:26:13 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [admin] in context with path [/admin] threw exception [Request processing failed; nested exception is org.broadleafcommerce.common.file.FileServiceException: Error copying resource named bundles/admin/admin-1720203513.js from workArea /tmp/tomcat7-tomcat7-tmp/ad/f8/ to a4/66/admin-1720203513.js] with root cause
java.io.IOException: Destination '/broadleaf/assets/a4/66' directory cannot be created
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1085)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038)
at org.apache.commons.io.FileUtils.moveFile(FileUtils.java:2832)
at org.broadleafcommerce.common.file.service.FileSystemFileServiceProvider.addOrUpdateResources(FileSystemFileServiceProvider.java:102)
at org.broadleafcommerce.common.file.service.BroadleafFileServiceImpl.addOrUpdateResources(BroadleafFileServiceImpl.java:270)
at org.broadleafcommerce.common.file.service.BroadleafFileServiceImpl.addOrUpdateResource(BroadleafFileServiceImpl.java:250)
at org.broadleafcommerce.common.resource.service.ResourceBundlingServiceImpl.saveBundle(ResourceBundlingServiceImpl.java:182)
at org.broadleafcommerce.common.resource.service.ResourceBundlingServiceImpl.getBundle(ResourceBundlingServiceImpl.java:101)
at org.broadleafcommerce.common.web.resource.BroadleafResourceHttpRequestHandler.getResourceInternal(BroadleafResourceHttpRequestHandler.java:104)
at org.broadleafcommerce.common.web.resource.BroadleafResourceHttpRequestHandler.getResource(BroadleafResourceHttpRequestHandler.java:98)
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:113)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)


---------------------------------------------------------------
Here is another exception for images

May 22, 2014 1:10:30 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [icearn] in context with path [/icearn] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.io.FileNotFoundException: /broadleaf/assets/c7/ad/Hoppin-Hot-Sauce-Bottle.jpg (No such file or directory)] with root cause
java.io.FileNotFoundException: /broadleaf/assets/c7/ad/Hoppin-Hot-Sauce-Bottle.jpg (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at org.broadleafcommerce.cms.file.service.StaticAssetStorageServiceImpl.lookupAssetAndCreateLocalFile(StaticAssetStorageServiceImpl.java:118)
at org.broadleafcommerce.cms.file.service.StaticAssetStorageServiceImpl.getCacheFileModel(StaticAssetStorageServiceImpl.java:217)
at sun.reflect.GeneratedMethodAccessor160.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy177.getCacheFileModel(Unknown Source)
at org.broadleafcommerce.cms.web.file.StaticAssetViewController.handleRequestInternal(StaticAssetViewController.java:87)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
----------------------------------------------------------------------------------------------

Any idea what's this about? or is it just a bug for 3.1.2-GA?

Cheers,

Dan

Re: File not found exception for static files?

Posted: Fri May 23, 2014 4:15 pm
by daniel_locious
More information:

I rollbacked my test environment to development mode; just got the same errors.

Now I am pretty sure this is either because my tomcat doesn't have the rights to access/create the directory, or the issue in cms static asset; I might miss the configuration of the static asset?

If anyone has experienced this would you please help?

By the way, Broadleaf guys, may I suggest to have a search bar on your documents/wiki? I believe I saw something regarding the setting of cms in the documents, but just really hard to find it. I'll have to google again.

Regards,

Dan

Re: File not found exception for static files?

Posted: Sat May 24, 2014 4:17 pm
by daniel_locious
answer my own question first. to work around this issue, I create /broadleaf/ directory and chmod to accessable to tomcat.

and that's it, works.
Then I found the settings :cry:

# Allows us to load demo images from the classpath. This would be an expensive approach
# for most implementations and should only be done in dev. Images should be on a
# shared file system or the DB when in non-development environments
asset.server.file.classpath.directory=/cms/static

# Because we are blanking the value out here, broadleaf will use System.setProperty("java.io.tmpdir")
# This would NOT make sense in non-development environments since the OS may delete files in that
# directory.
#
# In non-development environments, this defaults to "/broadleaf/assets".
asset.server.file.system.path=

Re: File not found exception for static files?

Posted: Wed May 28, 2014 1:35 pm
by phillipuniverse
Yup, you got it. Thanks for reporting back the fix, sorry for the confusion.

Re: File not found exception for static files?

Posted: Thu May 29, 2014 7:49 am
by daniel_locious
Hi Phillip,

Just had some further thinking on architecture. If I understand this correct, when we add images from admin site, we are adding the images to admin server local file system, right? Then how do we get access to these images while demo site is not on the same sever with admin site?

My first thought is, create a cron job to copy the images to the demo site server...like every 5 mins or so.

I am thinking a better solution for this; I would assume you got better ideas?

Re: File not found exception for static files?

Posted: Thu May 29, 2014 10:14 am
by phillipuniverse
Yeah, so you have a few options:

1. If your servers are all on a private network, deem one instance as the file server and share the folder over NFS. We've deployed this architecture and it works pretty well. This is less fault-tolerant though because if the file server goes down then you will be hosed for a while
2. Utilize the Amazon S3 provider or the Rackspace Cloud Files provider. Whenever file operations are performed (like upload) they will go directly to the cloud vs staying on your local file system. Caching does take place on your server with those images so most of the time it's a single call to S3 to retrieve the file and then subsequent calls are just resolved on that server itself. This is the most fault-tolerant solution.