You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ivan Stork <iv...@fatline.com> on 2000/04/17 21:57:38 UTC
Way to create a Default servlet?
Hi, I'm trying to write my own proxy server. (I need to add some custom headers
to every HTTP request) I'm adapting a simple servlet to be the proxy server.
I'd like to set it up to handle EVERY request to http://localhost:8080
I edited the web.xml in /opt/tomcat/webapps/ROOT/WEB-INF to this:
<web-app>
<servlet>
<servlet-name>
FCProxy
</servlet-name>
<servlet-class>
FCProxy
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
FCProxy
</servlet-name>
<url-pattern>
*.fff
</url-pattern>
</servlet-mapping>
</web-app>
This works for all files ending in .fff. I have tried * and *.* to capture all
files, but I can't get either to work.
Anyone know what I am doing wrong?
--
Ivan Stork
VP, Business Development
Fatline.com - Cyber Intelligence
4865 Sterling Dr. #200, Boulder, CO, 80302, USA
tel:+1.303.245.9844
cell:+1.303.641.6741
fax:+1.425.671.3898
mailto:ivan@fatline.com
http://fatline.com
Re: http 400 error
Posted by Jeff Neuenschwander <je...@mixi.net>.
Great, thanks!
Jeff
----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, April 18, 2000 11:46 AM
Subject: Re: http 400 error
> Jeff Neuenschwander wrote:
>
> > What can an http 400 error indicate when calling a servlet?
> >
> > Just curious. When I call it from another web page, it works fine, but
when
> > I try to call it standalone, I get a 400 error.
> >
>
> HTTP status code 400 (in servlet parlance,
HttpServletResponse.SC_BAD_REQUEST)
> is supposed to be returned when the syntax of the HTTP request sent by the
> client is incorrect in some fashion. For example, the first line of a
request
> might look something like this:
>
> GET /index.html HTTP/1.0
>
> Tomcat will return an error 400 if the length if this line is too short,
or if
> the request URI does not start with a "/" character.
>
> >
> > Thanks,
> > Jeff
>
> Craig McClanahan
>
>
>
>
>
> --------------------------------------------------------------------------
> To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commmands, email: tomcat-user-help@jakarta.apache.org
>
>
Re: http 400 error
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Jeff Neuenschwander wrote:
> What can an http 400 error indicate when calling a servlet?
>
> Just curious. When I call it from another web page, it works fine, but when
> I try to call it standalone, I get a 400 error.
>
HTTP status code 400 (in servlet parlance, HttpServletResponse.SC_BAD_REQUEST)
is supposed to be returned when the syntax of the HTTP request sent by the
client is incorrect in some fashion. For example, the first line of a request
might look something like this:
GET /index.html HTTP/1.0
Tomcat will return an error 400 if the length if this line is too short, or if
the request URI does not start with a "/" character.
>
> Thanks,
> Jeff
Craig McClanahan
http 400 error
Posted by Jeff Neuenschwander <je...@mixi.net>.
What can an http 400 error indicate when calling a servlet?
Just curious. When I call it from another web page, it works fine, but when
I try to call it standalone, I get a 400 error.
Thanks,
Jeff
Re: Writing Proxy Servlets WAS Re: Way to create a Default servlet?
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Ivan Stork wrote:
> Thanks, Hans. The fix you gave works great.
> Anyone else attempted to write a proxy servlet using Tomcat?
> The problem I'm having is if I try to GET http://www.yahoo.com (by telneting to
> localhost 8080) I get a 400 Bad Request.
> It seems like my GET method only works for pages within the local site? (Works
> o.k. for GET /index.html
> Is this a Tomcat thing, or am I not writing my servlet correctly?
>
Tomcat does not currently support absolute URLs in the request URI, so you cannot
currently write a proxy in this way.
One thing that was experimented with earlier, but is also not currently suported, is a
means to let the document root of your web application live on a remote server, instead
of in the local file system. Then, you could sort of proxy by setting up a context
like this:
<Context path="/yahoo" docBase="http://www.yahoo.com"/>
and refer to Yahoo pages through Tomcat like this:
http://localhost:8080/yahoo/{yahoo-relative-URL-here}
of course, hyperlinks on these pages only work if they are relative, not absolute, so
it isn't a real proxy -- but it would support one form of load balancing.
I'm looking at various ways that this functionality might be restored to Tomcat --
there's a bunch of interesting issues related to accessing resources (for example, how
do you tell if a JSP page has been modified so you can recompile it) that have to be
adjusted to work in this kind of a situation.
Craig McClanahan
Writing Proxy Servlets WAS Re: Way to create a Default servlet?
Posted by Ivan Stork <iv...@fatline.com>.
Thanks, Hans. The fix you gave works great.
Anyone else attempted to write a proxy servlet using Tomcat?
The problem I'm having is if I try to GET http://www.yahoo.com (by telneting to
localhost 8080) I get a 400 Bad Request.
It seems like my GET method only works for pages within the local site? (Works
o.k. for GET /index.html
Is this a Tomcat thing, or am I not writing my servlet correctly?
On Mon, 17 Apr 2000, you wrote:
> Ivan Stork wrote:
> >
> > Hi, I'm trying to write my own proxy server. (I need to add some custom headers
> > to every HTTP request) I'm adapting a simple servlet to be the proxy server.
> > I'd like to set it up to handle EVERY request to http://localhost:8080
> >
>
> If you want one servlet to handle all requests, remove all other mappings
> and define a mapping for the default servlet pattern:
>
> Hans
> --
> Hans Bergsten hans@gefionsoftware.com
> Gefion Software http://www.gefionsoftware.com
>
> --------------------------------------------------------------------------
import java.io.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FCProxy extends HttpServlet
{ public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{ String query = null;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String clientIP = request.getRemoteAddr();
StringBuffer queryB = HttpUtils.getRequestURL(request);
query = queryB.toString();
Enumeration e = request.getHeaderNames();
out.println(query);
out.println("<br>");
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = request.getHeader(name);
out.println(name + " = " + value);
}
--
Ivan Stork
VP, Business Development
Fatline.com - Cyber Intelligence
4865 Sterling Dr. #200, Boulder, CO, 80302, USA
tel:+1.303.245.9844
cell:+1.303.641.6741
fax:+1.425.671.3898
mailto:ivan@fatline.com
http://fatline.com
Re: Way to create a Default servlet?
Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Ivan Stork wrote:
>
> Hi, I'm trying to write my own proxy server. (I need to add some custom headers
> to every HTTP request) I'm adapting a simple servlet to be the proxy server.
> I'd like to set it up to handle EVERY request to http://localhost:8080
>
> I edited the web.xml in /opt/tomcat/webapps/ROOT/WEB-INF to this:
>
> <web-app>
>
> <servlet>
> <servlet-name>
> FCProxy
> </servlet-name>
> <servlet-class>
> FCProxy
> </servlet-class>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>
> FCProxy
> </servlet-name>
> <url-pattern>
> *.fff
> </url-pattern>
> </servlet-mapping>
>
> </web-app>
>
> This works for all files ending in .fff. I have tried * and *.* to capture all
> files, but I can't get either to work.
If you want one servlet to handle all requests, remove all other mappings
and define a mapping for the default servlet pattern:
<servlet-mapping>
<servlet-name>
FCProxy
</servlet-name>
<url-pattern>
/
</url-pattern>
</servlet-mapping>
Note! There were some problems with this until very recently, so make sure
you grab the latest nightly build (or the latest source from CVS).
Hans
--
Hans Bergsten hans@gefionsoftware.com
Gefion Software http://www.gefionsoftware.com