I am trying to implement AJAX Crawling for my Webpage.
To get a feeling I created a new GWT Project with sample code.
I created a filter
public final class CrawlServlet implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException {
PrintWriter out = response.getWriter();
if (request.toString().contains("_escaped_fragment=")) {
out.write("yo");
} else {
try {
chain.doFilter(request, response);
return;
} catch (ServletException e) {
e.printStackTrace();
}
}
}`
I get the correct response if browse this site: http://127.0.0.1:8888/URLFilter.html?gwt.codesvr=127.0.0.1:9997?_escaped_fragment=key=#!yo
and I see the GWT Sample Application if my URL is not escaped_fragment. But when I hit ‘Send’ (calling the RPC) I get a IllegalStatementException.
[WARN] Exception while dispatching incoming RPC call
java.lang.IllegalStateException: WRITER
at test.server.CrawlServlet.doFilter(CrawlServlet.java:32)
(this is the chain.doFilter(request, response);
My web.xml
<!-- Servlets -->
<filter>
<filter-name>crawlServlet</filter-name>
<filter-class>test.server.CrawlServlet</filter-class>
</filter>
<filter-mapping>
<filter-name>crawlServlet</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>test.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/urlfilter/greet</url-pattern>
</servlet-mapping>
As i haven’t found much of tutorials/example regarding filter/rpc in GWT I gladly appreciate any help.
Thanks
Is your problem – you are getting a reference to the writer in the filter, then the servlet (or another filter) is using
getOutputStream()to do its own work. From the javadocs forgetWriter:…
The standard approach is to only use the writer/output stream if no other filter/servlet can possible do any writing – this includes even calling the getter. If you always want to write something, whether or not a later filter/servlet in the chain will also respond, then wrap the current
responseobject up in something like aHttpServletResponseWrapper, possibly with a custom output stream or writer so that others can continue.