Adobe-Consulting-Services / acs-aem-commons

http://adobe-consulting-services.github.io/acs-aem-commons/
Apache License 2.0
453 stars 600 forks source link

500 Server Error from AemEnvironmentIndicatorFilter when using Assets HTTP API (GET request) #2371

Closed oksana-dersovitz closed 4 years ago

oksana-dersovitz commented 4 years ago

Required Information

Expected Behavior

When making Assets HTTP API requests, GET /api/assets/myFolder.json should return a 200 OK Success and properties of the folder.

Actual Behavior

Actual request: GET /api/assets/wakefern/web-and-client-app.json HTTP/1.1

Result:

Error 500 Server Error

HTTP ERROR 500 Server Error

URI:/api/assets/wakefern/web-and-client-app.json
STATUS:500
MESSAGE:Server Error
SERVLET:org.apache.felix.http.base.internal.dispatch.DispatcherServlet-1fea4adb
CAUSED BY:java.lang.IllegalStateException: Cannot invoke getBufferedString() once getOutputStream() has been called.

Caused by:

java.lang.IllegalStateException: Cannot invoke getBufferedString() once getOutputStream() has been called.
        at com.adobe.acs.commons.util.BufferedServletOutput.getBufferedString(BufferedServletOutput.java:125)
        at com.adobe.acs.commons.util.BufferedServletOutput.close(BufferedServletOutput.java:172)
        at com.adobe.acs.commons.util.BufferedHttpServletResponse.close(BufferedHttpServletResponse.java:73)
        at com.adobe.acs.commons.wcm.impl.AemEnvironmentIndicatorFilter.doFilter(AemEnvironmentIndicatorFilter.java:222)
        at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
        at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
        at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:308)
        at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
        at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
        at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:131)
        at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
        at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
        at org.apache.sling.featureflags.impl.FeatureManager.doFilter(FeatureManager.java:116)
        at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
        at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
        at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:75)
        at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
        at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
        at org.apache.sling.engine.impl.parameters.RequestParameterSupportConfigurer.doFilter(RequestParameterSupportConfigurer.java:67)
        at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:142)
        at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81)
        at org.apache.felix.http.base.internal.dispatch.Dispatcher$1.doFilter(Dispatcher.java:146)
        at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1002)
        at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:326)
        at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:136)
        at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1008)
        at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:97)
        at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:136)
        at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1008)
        at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.invokePreprocessors(WhiteboardManager.java:1012)
        at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:91)
        at org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1607)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1577)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.Server.handle(Server.java:500)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:388)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
        at java.lang.Thread.run(Thread.java:748)

If we clear the values from the Environment Indicator configuration, then the GET request is successful. But we need environment indicators, and we have been successfully using them prior to upgrading to Assets 6.5 (from Assets 6.5) and AEM Commons 4.7.

Steps to Reproduce

  1. Install Assets 6.5.5
  2. Install ACS AEM Commons 4.7
  3. Configure Environment Indicator with values
  4. Issue HTTP API GET request on a folder

Links

Links to related assets, e.g. content packages containing test components

joerghoh commented 4 years ago

Might be related to #2271 where I worked in that area, and which has been introduced with version 4.7.0; can you validate if it works with an earlier version?

joerghoh commented 4 years ago

I cannot reproduce it on AEM 6.5.5 and acs-aem-commons 4.7.0: When I request

curl -u admin:admin http://localhost:4502/api/assets/wknd/en/activities/hiking.json

I get a proper non-empty JSON. @oksana-dersovitz can you provide a reproducable example, e.g using WKND?

oksana-dersovitz commented 4 years ago

@joerghoh , yes it worked with acs-aem-commons 4.4.2. Do you have your Environment Indicator values configured? This is what we have in the Felix console: aem-environment-indicator

joerghoh commented 4 years ago

@oksana-dersovitz thanks, forgot to configure that. Now I can reproduce it.

joerghoh commented 4 years ago

@oksana-dersovitz can you check if https://github.com/Adobe-Consulting-Services/acs-aem-commons/pull/2372 works for you?

oksana-dersovitz commented 4 years ago

@joerghoh , thank you. Our engineer was unable to build the bundle with code from #2372 .

image

davidjgonzalez commented 4 years ago

@oksana-dersovitz - here's a build of @joerghoh 's branch:

acs-aem-commons-bundle-4.8.1-SNAPSHOT.jar.rename-me.txt

acs-aem-commons-ui.apps-4.8.1-SNAPSHOT-min.zip

ui.apps contains the bundle, but attached that (have to rename) if you just want to upload the bundle without installing the package

oksana-dersovitz commented 4 years ago

@davidjgonzalez and @joerghoh : thank you both. This build does resolve the API issue we are having.

joerghoh commented 4 years ago

is part of next release (4.8.2)

davidjgonzalez commented 4 years ago

I just cut 4.8.4 (4.8.2 release got botched :() ... should be avail on maven central in a few hours