You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mohit Anchlia <mo...@gmail.com> on 2011/08/05 19:59:35 UTC

Design Question

We are developing a new system that will run in parallel with old
system. So some requests will go to new system and some old based on
configuration. We will put software switch software which will read
configuration and the request and decide which system this will go to.
This switch calls HttpClient Post calls using thread pools to send the
request to other systems. One way is to put this code in Valve of
existing system and invoke Http call if request is bound to the new
system otherwise just call .invoke to the next in chain, is this the
good way? I personally don't like it.

What I like is separate switch servlet that receives the call and make
Http calls to both system. This switch code will also have live thread
to refresh it's cache from config file. This I think is more
consistent and manageable.

But I am looking for some advise from others as well.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by André Warnier <aw...@ice-sa.com>.
Mohit Anchlia wrote:
> We are developing a new system that will run in parallel with old
> system. So some requests will go to new system and some old based on
> configuration. We will put software switch software which will read
> configuration and the request and decide which system this will go to.
> This switch calls HttpClient Post calls using thread pools to send the
> request to other systems. One way is to put this code in Valve of
> existing system and invoke Http call if request is bound to the new
> system otherwise just call .invoke to the next in chain, is this the
> good way? I personally don't like it.
> 
> What I like is separate switch servlet that receives the call and make
> Http calls to both system. This switch code will also have live thread
> to refresh it's cache from config file. This I think is more
> consistent and manageable.
> 
> But I am looking for some advise from others as well.
> 

Essentially thus, what you propose to create is reverse proxy code.
This sounds like something I would do using an Apache httpd front-end, which already has a 
lot of machinery to inspect and direct requests to back-end systems.
Furthermore, this machinery is well-tested, widely used, and reliable.
There is more to proxying than just issuing HTTP Post calls (and GET's and HEAD's and 
rewriting redirect headers and cookies and...).


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mohit,

On 8/6/2011 9:41 PM, Mohit Anchlia wrote:
> thanks for your input. Is it ok to make Http Calls and wait for 
> response inside of Valve or Filter?

Sure. You can do whatever you'd like.

> Are there any problems that might arise because of this?

Obviously, proxying HTTP requests will reduce performance over just
handling the request yourself, but it sounds like that's kind of a
requirement, so I don't see any other way.

I am unaware of any existing utilities you could use to do this, unless
you had clean XHTML and could use something like Apache Cocoon that can
merge multiple XML sources together and even transform them arbitrarily.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4+0eQACgkQ9CaO5/Lv0PDhcACgnuhmHJdiQahyopISCzFlvng+
5VQAoKGt+SnFstFjlIzbEwi8ohRLqVPa
=QpFv
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by Mohit Anchlia <mo...@gmail.com>.
On Sat, Aug 6, 2011 at 6:10 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Mohit,
>
> On 8/5/2011 5:46 PM, Mohit Anchlia wrote:
>> I also need to use mod_rewrite to direct request to new Servlet. Can
>> I use rewrite to say abc.com/abc to abc.com/switch/abc?
>
> Of course. That's kind of what mod_rewrite was written to do... rewrite
> URLs.
>
>> Mess :) Yes kind of but there is a risk involved since all the
>> functionality is not moving to the new system. Yes requests split
>> accross 2 systems and merge them back.
>
> Yuck. Good luck. I think this design is going to make it very difficult
> to manage and maintain. If you can't migrate systems, can you migrate
> APIs? If you use SOA, you can just re-implement one service and then
> combine using any appropriate technology (e.g. XSLT) instead of having
> to combine HTML from bits and pieces.
>
>> Asking my previous question, do you think Valve is better or
>> Servlet? I like servlet better in this case.
>
> It depends upon the requirements.
>
> I would use a Filter over a Valve any day unless there is a real reason
> to dig-into the Tomcat internal classes.
>
> If you want your code to be able to modify/wrap the request and deliver
> it somewhere else, then use a Filter. If the code is really making all
> the decisions and generating content (or, in fact, merging content from
> other sources), then a Servlet is more appropriate IMO.

thanks for your input. Is it ok to make Http Calls and wait for
response inside of Valve or Filter? Are there any problems that might
arise because of this?
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk495hcACgkQ9CaO5/Lv0PC++ACcD0fI3jsxretus4qJzLBqxt//
> D4kAmwfwYUbJi1DctW3iT4WqtxWFysbB
> =kh5Q
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mohit,

On 8/5/2011 5:46 PM, Mohit Anchlia wrote:
> I also need to use mod_rewrite to direct request to new Servlet. Can
> I use rewrite to say abc.com/abc to abc.com/switch/abc?

Of course. That's kind of what mod_rewrite was written to do... rewrite
URLs.

> Mess :) Yes kind of but there is a risk involved since all the 
> functionality is not moving to the new system. Yes requests split 
> accross 2 systems and merge them back.

Yuck. Good luck. I think this design is going to make it very difficult
to manage and maintain. If you can't migrate systems, can you migrate
APIs? If you use SOA, you can just re-implement one service and then
combine using any appropriate technology (e.g. XSLT) instead of having
to combine HTML from bits and pieces.

> Asking my previous question, do you think Valve is better or
> Servlet? I like servlet better in this case.

It depends upon the requirements.

I would use a Filter over a Valve any day unless there is a real reason
to dig-into the Tomcat internal classes.

If you want your code to be able to modify/wrap the request and deliver
it somewhere else, then use a Filter. If the code is really making all
the decisions and generating content (or, in fact, merging content from
other sources), then a Servlet is more appropriate IMO.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk495hcACgkQ9CaO5/Lv0PC++ACcD0fI3jsxretus4qJzLBqxt//
D4kAmwfwYUbJi1DctW3iT4WqtxWFysbB
=kh5Q
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by Mohit Anchlia <mo...@gmail.com>.
On Fri, Aug 5, 2011 at 2:41 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Mohit,
>
> On 8/5/2011 5:05 PM, Mohit Anchlia wrote:
>> On Fri, Aug 5, 2011 at 1:37 PM, Christopher Schultz
>>> Uh, why not use an HTTP proxy instead of using HttpClient. Squid,
>>> Apache httpd, countless LBs, and many others have this capability
>>> without you having to re-write this type of logic. Those products
>>> will be faster, more configurable, and less buggy than your own
>>> hand-rolled code.
>>
>> I agree but the problem is that I need to perform some kind of merge
>> of responses and validation checks on the response before returning
>> to client. Also, need to route to appropriate host based on query
>> string values. In essense we need control over it. It's not just the
>> proxy.
>
> Gotcha. mod_rewrite might be able to help a lot, here, but probably not
> with merging of responses, whatever that means. Do you have some
> requests that need to be split across the two services and then
> re-combined before returning a response? That sounds like a mess.
>

I also need to use mod_rewrite to direct request to new Servlet. Can I
use rewrite to say abc.com/abc to abc.com/switch/abc?

Mess :) Yes kind of but there is a risk involved since all the
functionality is not moving to the new system. Yes requests split
accross 2 systems and merge them back.

Asking my previous question, do you think Valve is better or Servlet?
I like servlet better in this case.

Thanks

>>> I think using Java for this is a mistake.
>>
>> why?
>
> I was thinking that using Tomcat would be a waste of time if an HTTP
> proxy would meet your needs. Maybe they won't.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk48Y2wACgkQ9CaO5/Lv0PAuxQCglbtPGq5aeDZvtkT1xIQo7hc/
> THYAn3VtHvyfY02HFru9egtUwzoKKGCQ
> =gmkY
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mohit,

On 8/5/2011 5:05 PM, Mohit Anchlia wrote:
> On Fri, Aug 5, 2011 at 1:37 PM, Christopher Schultz
>> Uh, why not use an HTTP proxy instead of using HttpClient. Squid,
>> Apache httpd, countless LBs, and many others have this capability
>> without you having to re-write this type of logic. Those products
>> will be faster, more configurable, and less buggy than your own
>> hand-rolled code.
> 
> I agree but the problem is that I need to perform some kind of merge 
> of responses and validation checks on the response before returning
> to client. Also, need to route to appropriate host based on query
> string values. In essense we need control over it. It's not just the
> proxy.

Gotcha. mod_rewrite might be able to help a lot, here, but probably not
with merging of responses, whatever that means. Do you have some
requests that need to be split across the two services and then
re-combined before returning a response? That sounds like a mess.

>> I think using Java for this is a mistake.
> 
> why?

I was thinking that using Tomcat would be a waste of time if an HTTP
proxy would meet your needs. Maybe they won't.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk48Y2wACgkQ9CaO5/Lv0PAuxQCglbtPGq5aeDZvtkT1xIQo7hc/
THYAn3VtHvyfY02HFru9egtUwzoKKGCQ
=gmkY
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by Mohit Anchlia <mo...@gmail.com>.
On Fri, Aug 5, 2011 at 1:37 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Mohit,
>
> On 8/5/2011 1:59 PM, Mohit Anchlia wrote:
>> This switch calls HttpClient Post calls using thread pools to send
>> the request to other systems.
>
> Uh, why not use an HTTP proxy instead of using HttpClient. Squid, Apache
> httpd, countless LBs, and many others have this capability without you
> having to re-write this type of logic. Those products will be faster,
> more configurable, and less buggy than your own hand-rolled code.

I agree but the problem is that I need to perform some kind of merge
of responses and validation checks on the response before returning to
client. Also, need to route to appropriate host based on query string
values. In essense we need control over it. It's not just the proxy.
>
>> One way is to put this code in Valve of existing system and invoke
>> Http call if request is bound to the new system otherwise just call
>> .invoke to the next in chain, is this the good way? I personally
>> don't like it.
>
> I think using Java for this is a mistake.

why?

>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk48VH8ACgkQ9CaO5/Lv0PAk9ACfbZx8zoKJ15URnlZmjV0LYeKB
> L0kAn1wlOq33dV6DlXAmfYVgyKqFZ1/P
> =bJzo
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Design Question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mohit,

On 8/5/2011 1:59 PM, Mohit Anchlia wrote:
> This switch calls HttpClient Post calls using thread pools to send 
> the request to other systems.

Uh, why not use an HTTP proxy instead of using HttpClient. Squid, Apache
httpd, countless LBs, and many others have this capability without you
having to re-write this type of logic. Those products will be faster,
more configurable, and less buggy than your own hand-rolled code.

> One way is to put this code in Valve of existing system and invoke 
> Http call if request is bound to the new system otherwise just call 
> .invoke to the next in chain, is this the good way? I personally 
> don't like it.

I think using Java for this is a mistake.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk48VH8ACgkQ9CaO5/Lv0PAk9ACfbZx8zoKJ15URnlZmjV0LYeKB
L0kAn1wlOq33dV6DlXAmfYVgyKqFZ1/P
=bJzo
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org