This discussion is archived
2 Replies Latest reply: Jan 2, 2012 6:21 AM by gimbal2 RSS

Cannot set status. Response already committed.

908463 Newbie
Currently Being Moderated
The Requirement is I need to change URL to HTTPS if user Uses HTTP, as below

http://localhost:9083/partnerworld/wps/sizing need to change to

https://localhost:9083/partnerworld/wps/sizing

for this i am doing the coding in FilterServlet.java as below

public final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
     {
          StringBuffer result = new StringBuffer();
          StringBuffer url = req.getRequestURL();
          if(url.toString().startsWith("http://")){
               String strColon = url.substring(7);
               System.out.println(strColon);
               if(strColon.indexOf(":") == -1){
                    result.append("https://");
                    result.append(strColon);
               }else{
                    result.append("https://");
                    int colonIndex = strColon.indexOf(":");
                    String portNumber = strColon.substring(0, colonIndex);
                    result.append(portNumber);
                    System.out.println("***"+" "+strColon+" "+colonIndex+" "+portNumber);
                    result.append(":9083" + strColon.substring(colonIndex+5));
               }
               
               
               if(resp.isCommitted()){
                    resp.resetBuffer();
               }
               
               resp.sendRedirect(result.toString());
          }

at the end i am doing sendRedirect with the new URL.

at that time i am getting below Exception.



[1/2/12 18:28:09:109 IST] 00000025 LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[1/2/12 18:28:09:109 IST] 00000025 WebApp E [Servlet Error]-[Cannot forward. Response already committed.]: java.lang.IllegalStateException: Cannot forward. Response already committed.
     at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:161)
     at servers.sizing.framework.filters.LanguageFilter.doFilter(LanguageFilter.java:147)
     at servers.sizing.framework.filters.FilterManager.doFilter(FilterManager.java:84)
     at servers.sizing.framework.filters.SecurityFilter.doFilter(SecurityFilter.java:291)
     at servers.sizing.framework.filters.FilterManager.doFilter(FilterManager.java:84)
     at servers.sizing.framework.filters.OutageFilter.doFilter(OutageFilter.java:146)
     at servers.sizing.framework.filters.FilterManager.doFilter(FilterManager.java:84)
     at servers.sizing.framework.filters.RequestFilter.doFilter(RequestFilter.java:71)
     at servers.sizing.framework.filters.FilterManager.doFilter(FilterManager.java:84)
     at servers.sizing.framework.filters.UserFilter.doFilter(UserFilter.java:341)
     at servers.sizing.framework.filters.FilterManager.doFilter(FilterManager.java:84)
     at servers.sizing.framework.filters.FilterServlet.doGet(FilterServlet.java:87)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1219)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:658)
     at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:526)
     at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:325)
     at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:630)
     at com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:113)
     at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3574)
     at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:269)
     at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:831)
     at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
     at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:133)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:450)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:508)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:296)
     at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
     at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
     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:136)
     at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:196)
     at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:751)
     at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:881)
     at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1551)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points