10

We have the CID Filter setup on a Java webapp that was recently upgraded to CIL 8.5. To do so, we setup the following filter in our Web.xml:

<filter>
    <filter-name>CID filter</filter-name>
    <filter-class>com.sdl.delivery.image.filter.ContextualImageFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CID filter</filter-name>
    <url-pattern>/cid/*</url-pattern>
</filter-mapping>

We then attempt to hit a CID url like this: https://www.example.org/cid/scale/700x100/source/site/en/Images/our-image.jpg

We receive the following error:

com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[ServletNameNotFound]: java.lang.StringIndexOutOfBoundsException: String index out of range: 4
   at java.lang.String.substring(String.java:1377)
   at com.sdl.delivery.image.filter.ContextualImageFilter.doFilter(ContextualImageFilter.java:101)
   at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
   at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
   at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
   at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
   at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
   at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:967)
   at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1107)
   at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3951)
   at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
   at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1014)
   at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
   at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
   at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
   at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
   at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
   at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
   at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
   at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
   at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
   at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
   at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
   at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
   at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)

We decomipled the com.sdl.delivery.image.filter.ContextualImageFilter code and found that this issue occurs due to the fact that it uses the code:

String servletPath = servletRequest.getServletPath();

to get the path. In localhost, on Tomcat, the servletPath is resolved correctly to /cid/scale/700x100/source/site/en/Images/our-image.jpg but on our dev servers on WebSphere, the servletPath variable is set to the empty string.

To verify these findings, we changed the code to:

String servletPath = new org.springframework.web.util.UrlPathHelper().getPathWithinApplication(servletRequest);

When we do so, it works as intended and the filter runs correctly on requests. However, this required quite a bit of code duplication since we have basically re-implemented the filter except with this one change. We are wondering if there is any way to get this variable to populate correctly OOTB without modifying the original class?

What we have tried: Setting this custom property in websphere to true: com.ibm.ws.webcontainer.enabledefaultservletrequestpathelements But it appears to only work only for default servlets mapped to "/" and not ones mapped to "/cid/".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.