JSP Loading Incompletely on Websphere Application Server 8.5 - html

I am planning to migrate from Websphere Application Server (WAS) 7 to version 8.5. I have deployed an application which runs fine on WAS 7 and I have not made any changes to it since migration.
However, on WAS 8.5, the JSP pages are not being getting loaded completely. When I examine these pages through "View Source," I can see that the HTML content is only half-loaded. Specifically, the HTML itself is not completed with closing tags.
In WAS 7, the result of "View Source" looks like this:
<html>
...
...
<td..../>
<td..../>
<td..../>
...
...
</html>
But the same in WAS 8.5 looks like:
<html>
...
...
<td..../>
<td..../>
<td..
I have done the following so far:
I compared the class files of compiled JSP on WAS 7 and WAS 8.5. They are almost same, so I assume that the compilation is done properly. However, displaying the page with in HTML is not getting done properly.
I tried enabling JavaScript debugging on IE, but it did not show any errors while loading.
There are no errors in application logs and server logs that I can see.
My questions:
The set of <td> tags above is generated through JSP custom tags. Should I check code of the tags?
Is there any Custom property in Web Container Settings in Websphere which control such behaviour?
Is there any timeout property which is causing page to stop loading half-way?
Please suggest what else should I check.

this is a well known behavior that happens when an Exception is thrown and Response has already been commited.
generally the exception is logged, but in some particular case it is not.
i read you workarounded removing EncodingFilter, but if you still want to find the problem you can try to code a Filter, that must be executed BEFORE EncodingFilter, wich sets response.setBufferSize to a larger size.
this can be such a filter:
public class ResponseBufferFilter implements Filter
{
private FilterConfig filterConfig;
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
try
{
// or better take the value from filterConfig.getInitParameter
response.setBufferSize(100000000);
chain.doFilter(request, response);
}
catch(Exception e)
{
e.printStackTrace();
throw new ServletException(e.getMessage(), e);
}
}
#Override
public void init(FilterConfig filterConfig) throws ServletException
{
this.filterConfig = filterConfig;
}
#Override
public void destroy()
{
filterConfig = null;
}
}
and this is the mapping:
<filter>
<filter-name>Response Buffer Filter</filter-name>
<filter-class>test.example.filter.ResponseBufferFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Response Buffer Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<!-- provide the class causing unwanted behavior -->
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
this will not solve the problem, but at least it should allow log of exception, one way or another, if any.

Related

html5 chrome video playback gets EofException,

I finally got video playback to work in chrome with seek feature using the headers Content-Range etc and status 206 returned. It worked well for smaller videos but fails with large videos. Just to note, I am not sending the actual byte ranges explicitly but deliver the entire stream to the webserver. I get the following errors:
org.eclipse.jetty.io.EofException,
this occurs in the backend dataserver that serves the entire inputstream to a servlet and jetty is the server being used. I am not sure how this process actually plays back and corrected the seek feature I needed but now the video fails after playing for a while. The following error also occurs in the browser debugger:
ERR_CONTENT_LENGTH_MISMATCH
I have an audio stream being requested at the same time and playedback as well since I do not know how to mix the two streams.
Any ideas or advice appreciated.
EDIT:
Thanks to the advice to change resourcehandler to defaultservlet; not sure where to do this so found the instances of where this is in the code:
private void addHttpContexts(ConfigNode cnode) throws Exception {
try {
// get all the http context nodes
ConfigNode[] httpContextNodes = cnode.getChildNode("HttpContextList").getChildNodes();
for (int s = 0; s < httpContextNodes.length; s++) {
String urlPath = httpContextNodes[s].getChildNode("ContextPath").getStringValueEx();
String resourceBase = httpContextNodes[s].getChildNode("ResourceBase").getStringValueEx();
ArrayList<String> welcomeFileList = new ArrayList<String>();
if (httpContextNodes[s].hasChildNode("WelcomeFile")) {
String welcomeFile = httpContextNodes[s].getChildNode("WelcomeFile").getStringValueEx();
welcomeFileList.add(welcomeFile);
}
ContextHandler context = new ContextHandler(contexts, urlPath);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(resourceBase);
resourceHandler.setWelcomeFiles((String[]) welcomeFileList.toArray(new String[welcomeFileList.size()]));
context.setHandler(resourceHandler);
} catch (Exception ex) {
trace.warning("Configuration of http contexts failed", ex);
throw ex;
}
}
What is the appropriate methods for setResourceBase(resourceBase) and
setWelcomeFiles((String[]) welcomeFileList.toArray(new String[welcomeFileList.size()]));
This is the other place in the the same class I found DefaultSErvlet
ServletHolder holderDefault = new ServletHolder("default",DefaultServlet.class);
holderDefault.setInitParameter("dirAllowed","false");
and also already defined in web.xml
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
By default, Jetty's DefaultServlet will handle range requests properly for static content served by Jetty itself.
No other component in Jetty handles range requests on its own.
If you have custom code, your own Servlets, your own Jetty Handlers, a REST endpoint, specialized Filters, spring-mvc setup, etc... then you have to handle the range request yourself.
This is because its very impractical for the webserver to support this for custom code. (It would have to request the entire content from the custom code, and then only send the specific byte range to the requesting client).

encoding filter , struts working just when using html:form tag

I face this problem. I have a filter that sets the character encoding of the request according to the filter's config (for example, to UTF-8). This works with forms coded using the struts html:form tag. However, if I use the ordinary HTML form tag, the data are not encoded correctly.
This is the filter definition in the web.xml:
<filter>
<filter-name>Encoding Filter</filter-name>
<filter-class>EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Encoding Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Here's the filter :
public class EncodingFilter implements javax.servlet.Filter {
private String encoding;
public void init(FilterConfig filterConfig) throws ServletException {
this.encoding = filterConfig.getInitParameter("encoding");
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
filterChain.doFilter(request, response);
}
public void destroy() {
}
}
If you use a Struts tag <html:form> and omit the METHOD attribute it defaults to POST.
If you use a standard HTML <form> and omit the METHOD attribute it defaults to GET.
Tomcat will process your POST and GET parameters differently:
POST: your filter will be used. Note that you should really only set the request character encoding if it has not been specified by the client (your filter is always setting it to UTF-8). Tomcat comes with a filter SetCharacterEncodingFilter.java that does this.
GET: Tomcat will use ISO-8859-1 as the default character encoding. There are two ways to specify how GET parameters are interpreted:
Set the URIEncoding attribute on the element in server.xml to something specific (e.g. URIEncoding="UTF-8").
Set the useBodyEncodingForURI attribute on the element in server.xml to true. This will cause the Connector to use the request body's encoding for GET parameters.
This is all in: http://wiki.apache.org/tomcat/FAQ/CharacterEncoding

Response encoding in Spring

I've got problem with character encoding of my http responses. I read many tips, tutorials etc., but I can't resolve my problem. We are using Spring MVC with Hibernate and ExtJS as view technology. All data are returns as JSON using #ResponseBody on controllers method. Example method:
#RequestMapping(method = RequestMethod.POST, value = "dispatcher")
#ResponseBody
public String dispatcherPost(HttpServletRequest req, HttpServletResponse resp, HttpSession session) {
return process(req, resp, session);
}
There is simple dispatching mechanism for dispatching url commands (not really important in this case). Process method is doing something with parameters and return JSON. This JSON contains for example data from database (PostgreSQL 9.1.4). Data in Postgres are stored in UTF-8 and are 'visible correctly' for example in pgAdmin. We can also see valid data (from database) while debuging in eclipse. It all looks like there is everything ok with getting data from the Postgres. Problem starts when we want to return them via #ResponseBody annotated method. Method 'process' returns valid string (I can see in debugging mode) with utf-8 characters but in web browser (chrome, firefox) there are '?' instead of polish characters which are stored in database. Looking into firebug I can see that response headers are partially valid: 'Content-type: text/html;charset=UTF-8'. I told 'partially', because I have this line of code in process method:
`resp.setContentType("application/json;charset=UTF-8");`
where resp is HttpServletResponse. I've tried adding springs bean post processor from this solution: http://stackoverflow.com/questions/3616359/who-sets-response-content-type-in-spring-mvc-responsebody/3617594#3617594 but it doesn't works. I've got also character encoding filter in web.xml
<!-- Force Char Encoding -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
So basically the problem is with returning well encoded JSON from server. Any idea?
EDIT:
I paste code into proccess method:
System.err.println("TEST " + System.getProperty("file.encoding"));
System.err.println("TEST normal: " + response);
System.err.println("TEST cp1250: " + new String(response.getBytes(),"cp1250"));
System.err.println("TEST UTF-8: " + new String(response.getBytes(),"UTF-8"));
And result is something like this:
TEST Cp1250
TEST normal: {"users":[{"login":"userąęśćółżń"}]}
TEST cp1250: {"users":[{"login":"userąęśćółżń"}]}
TEST UTF-8: {"users":[{"login":"user?????"}]}
Thanks, Arek
Ok, it seems to be something weird with http://static.springsource.org/spring/docs/3.0.x/reference/remoting.html#rest-message-conversion and #ResponseBody annotation which is using springs http message converters. I don't have time for go into creating custom message converters, so solution for me is remove #ResponseBody annotation and use something like this:
#RequestMapping(method = RequestMethod.GET, value = "dispatcher")
public void dispatcherGet(HttpServletRequest req, HttpServletResponse resp, HttpSession session) {
String response = process(req, resp, session);
try {
resp.getWriter().write(response);
resp.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
}
Maybe this will helps someone. Thanks, Arek

Turn on gzip compression for grizzly under JerseyTest

I have jersey implementation of web service. The response per requirements must be gzip-ed.
Client side contains following bootstrap code to switch gzip on:
Client retval = Client.create();
retval.addFilter(
new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
For Tomcat web.xml gzip is configured as follow
<servlet>
<display-name>JAX-RS REST Servlet</display-name>
<servlet-name>JAX-RS REST Servlet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value>
</init-param>
And everything works fine!
But I need write unit test that invokes my service. I'm using JerseyTest as base and in practice way it was shown that grizzly is not correctly handles gzip without explicit declaration. I have found code snippet how to switch it on similar problem, but I have no idea how to combine it with JerseyTest.
Thank you in advance
Here is a sample test case if you're using the jersey test Framwork:
#Test
public void testGet(){
WebResource webResource = resource();
ClientResponse result = webResource
.path("pathToResource")
.header("Accept-Encoding", "gzip")
.head();
assertEquals(
"response header must contain gzip encoding",
"[gzip]",
result.getHeaders().get("Content-Encoding").toString());
}
AS the client API changed in the current Jersey versions, this is a sample test which works with Jersey 2.6:
public class WebServicesCompressionTest extends JerseyTest {
#Path("/")
public static class HelloResource {
#GET
public String getHello() {
return "Hello World!";
}
}
#Override
protected Application configure() {
enable(TestProperties.LOG_TRAFFIC);
return new ResourceConfig(
HelloResource.class,
EncodingFilter.class,
GZipEncoder.class,
DeflateEncoder.class
);
}
#Test
public void testGzip() {
Response response = target().request().acceptEncoding("gzip").get(Response.class);
assertThat(response.getStatus(), is(200));
assertThat(response.getHeaderString("Content-encoding"), is("gzip"));
}
}

Grails - Exception when stopping/cancelling an upload

I have a very basic upload action in my controller. It looks something like the action below. It works great. The only problem I'm seeing is when a user cancels an upload (or hits stop on their browser). I am able to recover correctly, but not before seeing an uncaught exception in my logs. The exception is listed below. Any help or feedback on how to correctly catch the uncaught exception here would be appreciated. Seems like it's happening somewhere between the client and the controller action since the exception is being displayed but none of the log messages in the action are showing up.
def upload = {
def f = null
try {
f = request.getFile('assetFile')
if(!f || f.empty) {
log.warn "File is empty"
render(view:'upload')
return
}
} catch (Exception e) {
log.warn "Caught exception:", e
render(view:'upload')
return
}
}
Exception is:
2010-08-06 15:33:22,826 ERROR [TP-Processor8] filter.UrlMappingsFilter - Error when matching URL mapping [/(*)/(*)?/(*)?]:Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:384)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:183)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:775)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:704)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:897)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
... 25 more
Caused by: org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:983)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:887)
at java.io.InputStream.read(InputStream.java:85)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:94)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:64)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
... 26 more
I'm terribly late on this, but I just ran into the same problem today and resolved it by adding a servlet filter (I also tried a Grails filter, but the exception is thrown prior to hitting it).
First you need to create a web.xml in your project...
grails install-templates
Add a filter to web.xml (make sure not to put the filter-mapping before any other filters)...
<filter>
<filter-name>upload</filter-name>
<filter-class>com.myProject.UploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>upload</filter-name>
<url-pattern>/media/uploadMediaAsset/*</url-pattern>
</filter-mapping>
Create the filter class...
package com.myProject
import javax.servlet.*
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.springframework.web.multipart.MultipartException
public class UploadFilter implements Filter {
private Log log = LogFactory.getLog(getClass())
public void init(FilterConfig filterConfig) throws ServletException { /* Do nothing */ }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException {
log.debug 'Making sure file upload gets here.'
try {
chain.doFilter(request, response)
} catch (MultipartException mpE) {
log.error mpE
}
}
public void destroy() { /* Do nothing */ }
}
Late response. I was actually able to find the solution for anyone still working on this problem. See http://brainflush.wordpress.com/2008/12/04/how-to-gracefully-recover-from-file-upload-errors-in-grails/.