This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet filter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet filter " Watch "Servlet filter " New topic
Author

Servlet filter

sekar bala
Greenhorn

Joined: Oct 06, 2010
Posts: 27
Hi all



I am having a doubt with servlet filter.

If a user enters www.google.com in browser i need to intercept the user request using filter and send the reuest through my server and the same if the resoponse comes from the server i need to intercept the response and i want to add something in the response and send the response back to the client..

By using the servlet filter we can do this.But i don know how to redircect the user request to my application server..

I am using apache tomcat and eclipse.

can any one give me an idea..thanks in advance..


Regards
Sekar Bala
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


By using the servlet filter we can do this

No, we can't. A request for www.google.com goes to the server with the IP address that particular URI resolves to, which is not going to be your server.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
sekar bala
Greenhorn

Joined: Oct 06, 2010
Posts: 27
Then what is the way to intercept the request using filters.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You can only deal with requests that get sent to your server. As Paul said, if the request doesn't get sent to your server, then you don't get to do a thing.
sekar bala
Greenhorn

Joined: Oct 06, 2010
Posts: 27

Ok i agree.suppose if user enters www.google.com i redirect that to my server through proxy again from the proxy server i need to send the request to www.google.com again the same way the reponse.

How to do this one.Any idea?
Arun Krishnan Nair
Greenhorn

Joined: Aug 14, 2008
Posts: 18
Thats impossible. If you do that it will come under security violation :-)

If you were owning the www.google.com domain you could add an interceptor.

A simplest form of interceptor can be like,

suppose you have an application hosted on your server. You want to log all input requests and outgoing responses from your service.. You can add an interceptor to log the request and response without disturbing your service application.

-Arun


SCJP 5 - 100%
Aiming for SCBCD 5 & SCWCD 5
sekar bala
Greenhorn

Joined: Oct 06, 2010
Posts: 27
Its possible through proxy

for eg:

proxypass //ll.com http://www.google.com

In hosts file we need to define the ll.com.


Now i am able to redirect.But my problem is i am not able to intercept..

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

"red force", please check your private messages for an important administrative matter. Thanks.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please update your display name if you would like us to help.
At this stage it would be easier if you told us what you were trying to do.
sekar bala
Greenhorn

Joined: Oct 06, 2010
Posts: 27
Hi all


Anyone help me..its very urgent..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

What part of "this cannot be done" did you find confusing? There is no way that you can intercept traffic to google or any other site that you do not own the DNS rights to.
sekar bala
Greenhorn

Joined: Oct 06, 2010
Posts: 27
I am not intercepting some others.This is the situation if i am entering google in my browser before it google reaches the server i need to forward that request to my proxy and send it to corresponding server.And again if the response comes from the server first it must come to my proxy server and then i need to add something in that response and send that to server..


This is the one that i want to do.Can you have any idea?
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 274

You'd have to modify your browser in some way. It's impossible to do this to a random person of your choosing without their permission. You can configure your browser to communicate through a proxy by modifying its settings. For example, in Firefox, go to [Preferences > Advanced > Network > Settings].


SCJP 6 || SCWCD 5
sekar bala
Greenhorn

Joined: Oct 06, 2010
Posts: 27
I dont want to do it for random person.I am doing for myself only.

How to do that thing for myself.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

There are several Java based HTTP Proxies available, I suggest grabbing one of these and bending them to your will.
eg http://www.membrane-soa.org/soap-monitor/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet filter