Why doesn't doFilter work was expected when a .jsp page is accessed?

I'm hoping an expert could point me in the right direction or tell me
          if this is a bug in WebLogic.
          My environment is WebLogic 6.1 (service pack 4), on Windows 2000.
          I need to capture all the response data that comes back from the
          servlet. So, I have a simple filter that wraps the response object,
          and sends the wrapped object into filterChain.doFilter() method.
          I've set up the web.xml so that any servlet access should trigger my
          filter (the <url-pattern> is /*). I've also configured a sample
          web-app called TEST to serve .html/.jsp pages.
          When the browser makes a .html request, everything works as expected.
          After the filterChain.doFilter(), I can take a look at the wrapped
          response object and print the contents of the response.
          However, when I access a .jsp page as part of form data submit, the
          output stream of my wrapper is empty after the filterChain.doFilter()
          completes.
          If I don't wrap the response, then everything seems to work fine. The
          .jsp gets interpreted properly by the servlet container, I can see the
          result page in the browser just fine.
          By inserting debug statements, I can see that if I wrap the responses,
          for a .html request, under the covers, wrapper's getOutputStream()
          gets called. But for a .jsp request, under the covers, wrapper's
          getWriter() gets called. I don't know how significant this is, but
          this is the only difference I see!
          If I don't wrap the response, I am not sure how to get at the response
          data. All I need to do is to take certain actions depending on the
          response. That is why I'm using a wrapper to get at the response data.
          In the JRun AppServer, the code just works fine.
          I've enclosed the source code & the output that demonstrates the
          problem.
          What am I doing wrong? Or, is this a bug in WebLogic? If this is a
          bug, is there a patch available?
          Thanks,
          --Sridhar
          // HeaderFilter.java
          // This is the filter that gets invoked through the web.xml
          configuration
          import javax.servlet.*;
          import javax.servlet.http.*;
          import java.io.*;
          import java.util.*;
          public class HeaderFilter implements Filter {
          public FilterConfig filterConfig;
          public void destroy() {
                    this.filterConfig = null;
               public void init(FilterConfig filterConfig) {
                    this.filterConfig = filterConfig;
          public FilterConfig getFilterConfig() {
          return filterConfig;
          public void setFilterConfig(FilterConfig filterConfig) {
          this.filterConfig = filterConfig;
          public void doFilter(ServletRequest req, ServletResponse resp,
          FilterChain chain)
          throws java.io.IOException, javax.servlet.ServletException {
          ServletContext context = filterConfig.getServletContext();
          HttpServletResponse response = (HttpServletResponse)resp;
          TestResponseWrapper wrapper = new
          TestResponseWrapper(response);
          chain.doFilter(req, wrapper);
          OutputStream out = resp.getOutputStream();
          System.out.println("The content length is :" +
          wrapper.getContentLength());
          if ("text/html".equals(wrapper.getContentType())) {
          byte[] data = wrapper.getData();
          System.out.println("TEXT RESPONSE, length is " +
          data.length);
          System.out.println(new String(data));
          out.write(data);
          // out.close();
          // TestResponseWrapper.java
          // This class wraps the response object so that you could take a look
          at
          // the response contents after the filterConfig.doFilter() method
          import javax.servlet.ServletOutputStream;
          import javax.servlet.http.HttpServletResponse;
          import javax.servlet.http.HttpServletResponseWrapper;
          import java.io.ByteArrayOutputStream;
          import java.io.PrintWriter;
          public class TestResponseWrapper extends HttpServletResponseWrapper{
          private ByteArrayOutputStream output;
          private int contentLength;
          private String contentType;
          public TestResponseWrapper(HttpServletResponse response) {       
          super(response);
          output = new ByteArrayOutputStream();
          public ServletOutputStream getOutputStream() {    
          System.out.println("****** getOutputStream() called *******");
          return new FilterServletOutputStream(output);
          public byte[] getData() {
          return output.toByteArray();
          public PrintWriter getWriter() {   
          System.out.println("****** getWriter() called *******");
          return new PrintWriter(getOutputStream(), false);
          public void setContentType(String type) {       
          System.out.println("**** Wrapper setContentType called ****");
          this.contentType = type;
          super.setContentType(type);
          public String getContentType() {       
          return this.contentType;
          public int getContentLength() {    
          return contentLength;
          public void setContentLength(int length) {       
          System.out.println("**** Wrapper setContentLength called
          this.contentLength=length;
          super.setContentLength(length);
          // FilterServletOutputStream.java
          // This class is used by the wrapper for getOutputStream() method
          // to return a ServletOutputStream object.
          import javax.servlet.ServletOutputStream;
          import java.io.DataOutputStream;
          import java.io.IOException;
          import java.io.OutputStream;
          import java.io.*;
          public class FilterServletOutputStream extends ServletOutputStream {
          private DataOutputStream stream;
          public FilterServletOutputStream(OutputStream output) {       
          stream = new DataOutputStream(output);
          public void write(int b) throws IOException {       
          stream.write(b);
          public void write(byte[] b) throws IOException {       
          stream.write(b);
          public void write(byte[] b, int off, int len) throws IOException {
          stream.write(b, off, len);
          // test.html
          <html>
          <head>
          <meta http-equiv="Content-Type"
          content="text/html; charset=iso-8859-1">
          <title> Web Posting Information </title>
          </head>
          <body>
          <form name="myform" method="POST" action="resource.jsp">
          <input type="TEXT" name="input"></input>
          <br>
          <input type="SUBMIT" value="done"></input>
          </form>
          </body>
          </html>
          // resource.jsp
          // This gets referenced by the test.html file
          <HTML><BODY>
          <head>
          <title>JRun Programming Techniques</title>
          <meta http-equiv="Content-Type" content="text/html;
          charset=iso-8859-1">
          </head>
          <body>
          <H3>Secure Resource Page</H3>
          <p>This is a secure page.</p>
          <BR><B>User: </B>
          <%
          //     out.write(request.getParameter("input"));
          %>
          </BODY></HTML>
          // HERE IS THE OUTPUT
          // HERE IS WHAT I SEE WHEN I ACCESS
          // http://localhost:7001/TEST/test.html
          **** Wrapper setContentType called ****
          **** Wrapper setContentLength called ****
          ****** getOutputStream() called *******
          The content length is :331
          TEXT RESPONSE, length is 331
          <html>
          <head>
          <meta http-equiv="Content-Type"
          content="text/html; charset=iso-8859-1">
          <title> Web Posting Information </title>
          </head>
          <body>
          <form name="myform" method="POST" action="resource.jsp">
          <input type="TEXT" name="input"></input>
          <br>
          <input type="SUBMIT" value="done"></input>
          </form>
          </body>
          </html>
          // HERE IS WHAT I SEE WHEN I enter some value in the "input" field
          // of the form, and click on the "submit" button.
          // Why isn't setContentLength() getting called on the wrapper?
          // It appears as if the wrapper's output stream isn't getting used
          // at all!!!
          **** Wrapper setContentType called ****
          ****** getWriter() called *******
          ****** getOutputStream() called *******
          The content length is :0
          TEXT RESPONSE, length is 0
          

If someone else runs into this, here is how I solved the problem -
          If you create a PrintWriter object with the autoflush option, it
          doesn't flush the underlying buffer till you call println on it. I
          looked through the generated code for the servlet, and it was doing a
          JSPWriter.print() to output information.
          So, I changed the ResponseWrapper to keep a handle to the PrintWriter
          object, and then flush it in the filter, and that works.
          Why the same code behaves differently in JRun & Weblogic, I'm not sure
          --Sridhar
          

Similar Messages

  • I recently bought a lightning to 30 pin adapter for my new iPad so that I could continue to use my 30 pin to VGA cord, but when I plug the VGA cord into it it says it is not supported. They are all apple products, so why doesn't it work?

    I recently bought a lightning to 30 pin adapter for my new iPad so that I could continue to use my 30 pin to VGA cord, but when I plug the VGA cord into it it says it is not supported. They are all apple products, so why doesn't it work?

    If it is a lightning to 30 pin adaptor, and you have a 7th Generation Nano it has to fit the Nano.
    This is lightning to 30 pin adapter: http://www.bestbuy.com/site/Apple%26%23174%3B---Lightning-to-30-Pin-Adapter/6651 936.p?id=1218803450821&skuId=6651936#tab=overview
    Is this what you bought?
    You need to contact Sony and see if they model you have is compatible with the docking adapter. It may not be.

  • I have Elements 12 installed.  When I am in the catalog, click on a photo, then want to open the Editor, I get an error message.  If I click on Editor from the Welcome screen, I get the same error message.  Why doesn't Editor work?  Thanks.

    I have Elements 12 installed.  When I am in the catalog, click on a photo, then want to open the Editor, I get an error message.  If I click on Editor from the Welcome screen, I get the same error message.  Why doesn't Editor work?  Thanks.

    You'd better ask in the Elements forum.
    Photoshop Elements

  • Why doesn't siri work away from home

    why doesn't siri work way from home

    It does for me. But it requires an Internet connection, so if you don't have mobile data turned on or your account isn't provisioned for it or you are out of range of a cell tower Siri can't talk to the servers.

  • Why doesn't my imac turn on when I turn on Apple TV?

    Why doesn’t my imac turn on when I turn on Apple TV?

    Yes, otherwise some people might have to walk up to the third floor and turn on iMac,
    and then go back down to living room in order to stream form iTunes. My iMac is close,
    but not in same room. There must be something I don't have set up right.

  • Why doesn't LightScribe work with my Snow Leopard?

    Why doesn't LightScribe work with my Snow Leopard? It downloaded and is in my printer folder, but won't open.

    Are you really still running 10.6.3? If you are you should run the combo update as many issues were resolved within the updates themselves.
    Mac OS X 10.6.8 Update Combo v1.1

  • Why doesn't flash work during panorama pictures

         why doesn't flash work during panorama pictures

    HI..
    Try troubleshooting the Flash plugin ..
    Quit Safari.
    Open System Preferences > Flash Player then select the Storage tab. Click: Delete All
    Now uninstall the Flash plugin then reinstall new >  Troubleshoot Flash Player | Mac OS
    Very important to uninstall the currently installed Flash plugin before reinstalling.
    Launch Safari From your Safari menu bar click Safari > Empty Cache
    Now try a video.
    BTW... if you have the ClickToFlash extension installed, that can prevent Flash based video from streaming. It can also be installed as a plugin in /Library/Internet-Plug-Ins.
    And check to see if Safari is running in 32 bit mode. Right or control click the Safari icon in your Applications folder then click Get Info. If the box next to:  Open in 32 bit mode  is selected, deselect, quit then relaunch Safari.

  • Iphone 3g - why doesn't it work?

    I purchased a new pair of Nike running shoes excited to link up the sensor and get started using with my iphone 3G. However, I find out the Nike Plus only works with an iphone 3GS. I'm now going to have to return the Nike Sensor for a refund instead of having to upgrade to another Iphone model. Is there anyway around this? Why doesn't it work with the Iphone 3G? What makes the operating system in the 3GS different so it works?

    As evidence too there is a hack which gets it working as well:
    http://mymojo.ca/index.php/2009/12/31/weekend-project-nike-and-iphone-3g-part-1/

  • I've got a serial number for Contribute but it won't activate on one of our computers. Right now we have to use the 30 day trial. Why doesn't it work?

    I've got a serial number for Contribute but it won't activate on one of our computers. Right now we have to use the 30 day trial. Why doesn't it work? Marianne Stanton, The Inquirer and Mirror, Nantucket, MA: Sign in: [email protected]

    Here's the serial number I have and have used on other machines:
    < Removed by Moderator >
    "This serial number is not valid for this product."
    OS 10.7.5
    Contribute 6.5
    Greg Derr
    <Removed by Moderator>

  • Why doesn't Nike+ work with the 1st Gen Ipod touch with 2.1 software?

    Why doesn't Nike+ work with the 1st Gen Ipod Touch with 2.1 software?

    The second gen iPod Touch has firmware version 2.1.1(5F138) whereas the 1st Gen only allows 2.1 (5F137). Don't know if that has anything to do with it, but it's likely.
    Why doesn't Apple allow those with the Nike+iPod sports kit to use their external sensor on the 1st Gen iPod Touch?!?! I can't see why the sensor would be incompatible with the right firmware upgrade!!

  • Error when requesting JSP page

    We have just finished getting our environment set up. We are running
    WebLogic 4.5.1 sp7 on a Sun server, and are frontending it with IIS 4.0
    SP6a using the iisproxy.dll WebLogic plugin.
    We can get things working for a while, but eventually, we get the
    following error in the NT event log when requesting the first JSP on our
    site:
    "Out of process application '/LM/W3SVC/1/Root' terminated unexpectedly"
    The Web server is still up, it's just when the JSP page is called that
    we get "Page can not be displayed" errors. Any HTML pages come up just
    fine. To fix the problem, we just stop and restart the Web Publishing
    service.
    Has anyone seen this error or does anyone know what events cause this
    problem?
    Thanks,
    -Mike

    There is a big difference between this;
    http://www.mydomain.com/blabla
    and this;
    http://www.mydomain.com/blah.jsp
    blabla - this is the name of the Web application. When you reference this Web application name Tomcat will check the welcom file descriptor and redirect for that web application.
    blah.jsp - is the name of a JSP page. When you reference this page the way you did above, you are not stating where the JSP page is located. It would be locatied in the "http://www.mydomain.com/blabla/blah.jsp" location.

  • "No bean found under attribute key" exception when a JSP is not accessed

    HI,
    We are using weblogic 7.1 SP6, Oblix and TRC struts in our application. During normal access to various pages system works fine. When the application is not accessed for 30 minutes system displays session expired exception. But some time when a page is not accessed for some time, say 15 - 20 minutes and user clicks any link system displays a exception dump in the screen. The exception displays for pages with track changes. The exception starts with following line
    [ServletException in:/jsp/include/Header.jsp] No bean found under attribute key HomepageFormBean' javax.servlet.jsp.JspException: No bean bound under attribute key HomePageFormBean at org.apache.struts.taglib.logic.CompareTagBase.condition(CompareTagBase.java:221) at org.apache.struts.taglib.logic.EqualTag.condition(EqualTag.java:90)
    After closing the window and tried to access the same page then the system works fine. The above exception is intermittent.
    Any help is highly appreciated.
    Thanks,
    K.Pushparaj

    Hi dear use this code i modified
    <logic:iterate id="lstDelNotificationData" name="institutionHomeForm" property="delNotification_data" indexId="i" >
    <table cellpadding="0" cellspacing="0" width="320" border="0">
    <tr>
    <td valign="top"><img src="/images/bullet2.gif" alt=" "></td>
    <td>
    "sm"> Your FYE <bean:write name="lstDelNotificationData" property="ins_fye"/> Annual ......is
    Now u will not get bean problem

  • Silverlight 5 binding on a property with logic in its setter does not work as expected when debug is attached

    My problem is pretty easy to reproduce.
    I created a project from scratch with a view model.
    As you can see in the setter of "Age" property I have a simple logic.
        public class MainViewModel : INotifyPropertyChanged
                public event PropertyChangedEventHandler PropertyChanged;
                private int age;
                public int Age
                    get
                        return age;
                    set
                        /*Age has to be over 18* - a simple condition in the setter*/
                        age = value;
                        if(age <= 18)
                            age = 18;
                        OnPropertyChanged("Age");
                public MainViewModel(int age)
                    this.Age = age;
                private void OnPropertyChanged(string propertyName)
                    if (this.PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    In the MainPage.xaml 
         <Grid x:Name="LayoutRoot" Background="White">
                <TextBox 
                    Text="{Binding Path=Age, Mode=TwoWay}" 
                    HorizontalAlignment="Left"
                    Width="100"
                    Height="25"/>
                <TextBlock
                    Text="{Binding Path=Age, Mode=OneWay}"
                    HorizontalAlignment="Right"
                    Width="100"
                    Height="25"/>
            </Grid>
    And MainPage.xaml.cs I simply instantiate the view model and set it as a DataContext.
        public partial class MainPage : UserControl
            private MainViewModel mvm;
            public MainPage()
                InitializeComponent();
                mvm = new MainViewModel(20);
                this.DataContext = mvm;
    I expect that this code will limit set the Age to 18 if the value entered in the TextBox is lower than 18.
    Scenario: Insert into TextBox the value "5" and press tab (for the binding the take effect, TextBox needs to lose the focus)
    Case 1: Debugger is attached =>
    TextBox value will be "5" and TextBlock value will be "18" as expected. - WRONG
    Case 2: Debugger is NOT attached => 
    TextBox value will be "18" and TextBlock value will be "18" - CORRECT
    It seems that when debugger is attached the binding does not work as expected on the object that triggered the update of the property value. This happens only if the property to which we are binding has some logic into the setter or getter.
    Has something changed in SL5 and logic in setters is not allowed anymore?
    Configuration:
    VisualStudio 2010 SP1
    SL 5 Tools 5.1.30214.0
    SL5 sdk 5.0.61118.0
    IE 10
    Thanks!                                       

    Inputting the value and changing it straight away is relatively rare.
    Very few people are now using Silverlight because it's kind of deprecated...
    This is why nobody has reported this.
    I certainly never noticed this problem and I have a number of live Silverlight systems out there.
    Some of which are huge.
    If you want a "fix":
    private void OnPropertyChanged(string propertyName)
    if (this.PropertyChanged != null)
    //PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    Storyboard sb = new Storyboard();
    sb.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 100));
    sb.Completed += delegate
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    sb.Begin();
    The fact this works is interesting because (I think ) it means the textbox can't be updated at the point the propertychanged is raised.
    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

  • Why doesn't the result look right when comparing?

    Why doesn't the result look right even I used higlight execution to check true and false and found to be correct right?
    Attachments:
    comparenresult.zip ‏27 KB

    At first I was not sure what you were asking. After looking more closely, I think I can answer your question.
    First of all, you need to initialize your shift register. This is the array of Boolean results. The first time through it works OK, but subsequent runs are also added on instead of replacing the results, even though you used a local to "clear" the array first.
    You are adding 2 to the iterations and indexing on the new number. This is a so that you skip the first two "bad" values. Therefore, you only have 13 data points and should only be running the FOR loop 13 times. Change the FOR loop count constant to 13 (or get the array size and subtract 2 and wire it in if the number of tests is variable).
    Also, there is an 'In Range a
    nd Coerce' node that will perform the two tests and the AND all in one node. This was not an error, of course, but it does make it a bit easier to read.
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]
    Attachments:
    fixed_test4a.vi ‏73 KB

  • Why Doesn't "find" work in VBS?

    I'm trying to write a VBS module that will
    detect when the data in a channel crosses
    some threshold. As an example, I include
    a line to check when channel 56 becomes
    greater than 5.0
    Here is the VBS line that checks for this:
    FirstValue = find( Ch(56) > 5.0, 1 )
    When ever I execute this script, DIAdem displays
    an error dialog with this message:
    Error in (Row:52, Column:9):
    Error message from DIAdem OCMD-interface:
    Invalid return value of the DIAdem kernel !
    What does this mean? Why doesn't the "find" function
    work? What other means can I use to do this operation?

    Hi jbrandim,
    The first parameter in the find() function is a string, so when you use this function with VBS syntax, you need to enclose it in double quotes:
    FirstValue = find("Ch(56) > 5.0", 1)
    Additionally, you can also call this function as a Formula Calculator function, since it is in fact a DIAdem function and not a VBS function:
    Call FormulaCalc("L1:= find(Ch(56) > 5.0, 1)")
    FirstValue = L1
    The cryptic error message is an artifact of the translation process between VBScript and the DIAdem find function. DIAdem automatically maps the return value of the find function, which is an integer, to the variant variable "FirstValue", as well as the input parameters. The mapping process from Variant to string in the first find() parameter failed, and
    that led to the error message you received.

Maybe you are looking for

  • Ipod mini will not update, it gives an error message

    I deleted some things from itunes and when I tried to update my ipod it said "the ipod cannot be updated because all of the playlists selected for updating no longer exist.

  • Having trouble with DV NTSC export file for Pro Tools.

    Pro Tools only takes NTSC format video. For some reason every single DV NTSC file that has been exported freezes in a certain spot and in other portions tends to flicker. I'm not so sure as to why that is. I tried exporting it through the QuickTime M

  • Raising exceptions in event handlers?

    Hi Is it possible to raise exceptions in event handler? As an example, I added a listener to a UnitOfWork, and implemented the preCommitUnitOfWork() method. In the method, I'm performing some operations, and if something goes wrong, I need to roll ba

  • Need to download Acrobat X Pro for Mac

    I have Adobe Acrobat X Pro 10.1.9 on a Macbook Pro, which I purchased last year on Adobe.com. I want to install it onto a new iMac. I understand it's possible to have the application on 2 systems but I need to download it rather than copying the file

  • Create/Manage WF approval - Admin Console

    Hi Gurus, OIM 9.1.0.2 I have an user group in the OIM that need only be able to create/manage resource's approval workflow thru Admin Console. (Resource Management / Manage / Select Resource Name - Resource Detail - Resource Workflow) I have already