You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Karthikeyani K <ka...@yahoo.com> on 2004/08/04 17:20:42 UTC
Invoke a httpclient in a EJB
Hi,
We have all requests posted to a servlet which delegates the request to a Stateless Session Bean. Does creatring and invoking a Httpclient postmethod in a helper class invoked by the Stateless Session Bean violate any of the EJB specifications. (EJB spec says sockets are not to be created in EJB code etc. ). Please suggest.
Thanks,
Karthi
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: Invoke a httpclient in a EJB
Posted by dan tran <da...@gmail.com>.
hmmm, EJB + remote DB via jdbc needs sockets?
You can use EJB with socket, as long as the operation is quick.
In some case http socket operation can hang due to long response delay.
-D
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Invoke a httpclient in a EJB
Posted by Michael Becke <be...@u.washington.edu>.
Hi Karthi,
Unfortunately I don't have much experience with EJBs, but if the spec
says that you can't open sockets, then it will be pretty hard to use
HttpClient. Perhaps someone else on this list has some more experience
in this matter.
Any EJB + HttpClient users out there?
Mike
On Aug 4, 2004, at 11:20 AM, Karthikeyani K wrote:
> Hi,
> We have all requests posted to a servlet which delegates the
> request to a Stateless Session Bean. Does creatring and invoking a
> Httpclient postmethod in a helper class invoked by the Stateless
> Session Bean violate any of the EJB specifications. (EJB spec says
> sockets are not to be created in EJB code etc. ). Please suggest.
>
>
> Thanks,
> Karthi
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Invoke a httpclient in a EJB
Posted by Ortwin Glück <or...@nose.ch>.
Michael Becke wrote:
> Both of
> these will create threads.
As I read the spec (but I am completely unfamiliar with EJB and I may be
dead wrong), you can do what you like during a method call. But before
returning form a method call you must ensure that there are no threads
and sockets left behind.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Invoke a httpclient in a EJB
Posted by Karthikeyani K <ka...@yahoo.com>.
thanks mike.
Michael Becke <be...@u.washington.edu> wrote:Hi Karthi,
> So does the following code snippet perform what Mike have mentioned...
> HttpClient client=new HttpClient(); // Which will create a
> SimpleHttpConnectionManager
> // by default. So we
> need not create an explicit
>
> //HttpconnectionManager
>
> // Perform post
> ..........
> //Release the connection
> postmethod.releaseConnection();
> // Close the socket connection
> client.getHttpConnectionManager().getConnection().close();
>
> Is this the correct way of closing the connection.
That should work just fine.
Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
Re: Invoke a httpclient in a EJB
Posted by Michael Becke <be...@u.washington.edu>.
Hi Karthi,
> So does the following code snippet perform what Mike have mentioned...
> HttpClient client=new HttpClient(); // Which will create a
> SimpleHttpConnectionManager
> // by default. So we
> need not create an explicit
>
> //HttpconnectionManager
>
> // Perform post
> ..........
> //Release the connection
> postmethod.releaseConnection();
> // Close the socket connection
> client.getHttpConnectionManager().getConnection().close();
>
> Is this the correct way of closing the connection.
That should work just fine.
Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Invoke a httpclient in a EJB
Posted by Karthikeyani K <ka...@yahoo.com>.
Mike stated
<< I would suggest creating a simple HttpConnectionManager (very similar to
SimpleHttpConnectionManager) that you can force close the connection with. >>
So does the following code snippet perform what Mike have mentioned...
HttpClient client=new HttpClient(); // Which will create a SimpleHttpConnectionManager
// by default. So we need not create an explicit
//HttpconnectionManager
// Perform post
..........
//Release the connection
postmethod.releaseConnection();
// Close the socket connection
client.getHttpConnectionManager().getConnection().close();
Is this the correct way of closing the connection.
Thanks,
Karthi
Karthikeyani K <ka...@yahoo.com> wrote:
Thanks Mike. Now I understand that we can use HttpClient from within EJB as long as we close the connection. Also Httpclient does not create a Server socket.
Michael Becke wrote:
Hi Karthi,
>From the wording it sounds like you are not supposed to run a server
from an EJB. HttpClient creates sockets but it does not listen to or
accept connections, it's a client only. As someone already mentioned it
would be pretty useless if you couldn't make network connections from an
EJB as that would eliminate JDBC as well.
It sounds like the real issue is going to be thread creation and
connection reuse. To avoid creating threads you should use neither the
MultiThreadedHttpConnectionManager nor connection timeouts. Both of
these will create threads. You will also need to ensure that all
HttpConnections are closed when the EJB exists. I would suggest
creating a simple HttpConnectionManager (very similar to
SimpleHttpConnectionManager) that you can force close the connection with.
Mike
Karthikeyani K wrote:
> Thanks everyone.
>
> The EJB restrictions specified at
> http://java.sun.com/blueprints/qanda/ejb_tier/restrictions.html state
> that Enterprise beans should not listen on, accept connections on, or
> mutlicast from a network socket. Why can an enterprise bean not
> listen to or accept connections on a socket? Because if an enterprise
> bean is listening on a socket, it can't be passivated -- it must
> always be available. Enterprise beans can be network socket clients,
> and so they can use other network resources (including other
> enterprise bean servers) to do their jobs. Just as with a database
> connection, don't hang on to open client sockets across method calls;
> instead, open them, communicate through the socket, and close it
> before returning from the method.
>
> So does it mean that we cannot use a HttpClient to invoke a
> postmethod from within a EJB, as httpclient creates sockets. Please
> clarify. Is there any other alternate way.
>
> Thanks,
>
> Karthi
>
>
> Gareth Davis wrote: EJB + threads +
> httpclient... yes does break the letter of the spec's, but yep it
> works and it works just fine.
>
> Who ever wrote the spec that said you couldn't open a socket in an
> EJB really wasn't living in the real world.
>
> The only thing to watch is that MultiThreadedConnectionManager does
> start it's own thread for managing the pool, this does work in an EJB
> but it won't be shutdown correctly when the application is stopped,
> you may find that you create a thread leak.
>
> Having said this I've only tried this in WebSphere 4 and 5. Version 4
> it wasn't a big deal as the process for the appserver got restarted
> when re-installing the app, but in websphere 5 it caused a leak.
>
> Gareth Davis Logical Practice Systems Limited
>
> gareth@logicalpractice.com On 4 Aug 2004, at 16:20, Karthikeyani K
> wrote:
>
>
>> Hi, We have all requests posted to a servlet which delegates the
>> request to a Stateless Session Bean. Does creatring and invoking a
>> Httpclient postmethod in a helper class invoked by the Stateless
>> Session Bean violate any of the EJB specifications. (EJB spec says
>> sockets are not to be created in EJB code etc. ). Please suggest.
>>
>>
>> Thanks, Karthi
>>
>> __________________________________________________ Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org For additional
> commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
>
>
> --------------------------------- Do you Yahoo!? New and Improved
> Yahoo! Mail - Send 10MB messages!
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
Re: Invoke a httpclient in a EJB
Posted by Karthikeyani K <ka...@yahoo.com>.
Thanks Mike. Now I understand that we can use HttpClient from within EJB as long as we close the connection. Also Httpclient does not create a Server socket.
Michael Becke <be...@u.washington.edu> wrote:
Hi Karthi,
>From the wording it sounds like you are not supposed to run a server
from an EJB. HttpClient creates sockets but it does not listen to or
accept connections, it's a client only. As someone already mentioned it
would be pretty useless if you couldn't make network connections from an
EJB as that would eliminate JDBC as well.
It sounds like the real issue is going to be thread creation and
connection reuse. To avoid creating threads you should use neither the
MultiThreadedHttpConnectionManager nor connection timeouts. Both of
these will create threads. You will also need to ensure that all
HttpConnections are closed when the EJB exists. I would suggest
creating a simple HttpConnectionManager (very similar to
SimpleHttpConnectionManager) that you can force close the connection with.
Mike
Karthikeyani K wrote:
> Thanks everyone.
>
> The EJB restrictions specified at
> http://java.sun.com/blueprints/qanda/ejb_tier/restrictions.html state
> that Enterprise beans should not listen on, accept connections on, or
> mutlicast from a network socket. Why can an enterprise bean not
> listen to or accept connections on a socket? Because if an enterprise
> bean is listening on a socket, it can't be passivated -- it must
> always be available. Enterprise beans can be network socket clients,
> and so they can use other network resources (including other
> enterprise bean servers) to do their jobs. Just as with a database
> connection, don't hang on to open client sockets across method calls;
> instead, open them, communicate through the socket, and close it
> before returning from the method.
>
> So does it mean that we cannot use a HttpClient to invoke a
> postmethod from within a EJB, as httpclient creates sockets. Please
> clarify. Is there any other alternate way.
>
> Thanks,
>
> Karthi
>
>
> Gareth Davis wrote: EJB + threads +
> httpclient... yes does break the letter of the spec's, but yep it
> works and it works just fine.
>
> Who ever wrote the spec that said you couldn't open a socket in an
> EJB really wasn't living in the real world.
>
> The only thing to watch is that MultiThreadedConnectionManager does
> start it's own thread for managing the pool, this does work in an EJB
> but it won't be shutdown correctly when the application is stopped,
> you may find that you create a thread leak.
>
> Having said this I've only tried this in WebSphere 4 and 5. Version 4
> it wasn't a big deal as the process for the appserver got restarted
> when re-installing the app, but in websphere 5 it caused a leak.
>
> Gareth Davis Logical Practice Systems Limited
>
> gareth@logicalpractice.com On 4 Aug 2004, at 16:20, Karthikeyani K
> wrote:
>
>
>> Hi, We have all requests posted to a servlet which delegates the
>> request to a Stateless Session Bean. Does creatring and invoking a
>> Httpclient postmethod in a helper class invoked by the Stateless
>> Session Bean violate any of the EJB specifications. (EJB spec says
>> sockets are not to be created in EJB code etc. ). Please suggest.
>>
>>
>> Thanks, Karthi
>>
>> __________________________________________________ Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org For additional
> commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
>
>
> --------------------------------- Do you Yahoo!? New and Improved
> Yahoo! Mail - Send 10MB messages!
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
Re: Invoke a httpclient in a EJB
Posted by Michael Becke <be...@u.washington.edu>.
Hi Karthi,
From the wording it sounds like you are not supposed to run a server
from an EJB. HttpClient creates sockets but it does not listen to or
accept connections, it's a client only. As someone already mentioned it
would be pretty useless if you couldn't make network connections from an
EJB as that would eliminate JDBC as well.
It sounds like the real issue is going to be thread creation and
connection reuse. To avoid creating threads you should use neither the
MultiThreadedHttpConnectionManager nor connection timeouts. Both of
these will create threads. You will also need to ensure that all
HttpConnections are closed when the EJB exists. I would suggest
creating a simple HttpConnectionManager (very similar to
SimpleHttpConnectionManager) that you can force close the connection with.
Mike
Karthikeyani K wrote:
> Thanks everyone.
>
> The EJB restrictions specified at
> http://java.sun.com/blueprints/qanda/ejb_tier/restrictions.html state
> that Enterprise beans should not listen on, accept connections on, or
> mutlicast from a network socket. Why can an enterprise bean not
> listen to or accept connections on a socket? Because if an enterprise
> bean is listening on a socket, it can't be passivated -- it must
> always be available. Enterprise beans can be network socket clients,
> and so they can use other network resources (including other
> enterprise bean servers) to do their jobs. Just as with a database
> connection, don't hang on to open client sockets across method calls;
> instead, open them, communicate through the socket, and close it
> before returning from the method.
>
> So does it mean that we cannot use a HttpClient to invoke a
> postmethod from within a EJB, as httpclient creates sockets. Please
> clarify. Is there any other alternate way.
>
> Thanks,
>
> Karthi
>
>
> Gareth Davis <ga...@logicalpractice.com> wrote: EJB + threads +
> httpclient... yes does break the letter of the spec's, but yep it
> works and it works just fine.
>
> Who ever wrote the spec that said you couldn't open a socket in an
> EJB really wasn't living in the real world.
>
> The only thing to watch is that MultiThreadedConnectionManager does
> start it's own thread for managing the pool, this does work in an EJB
> but it won't be shutdown correctly when the application is stopped,
> you may find that you create a thread leak.
>
> Having said this I've only tried this in WebSphere 4 and 5. Version 4
> it wasn't a big deal as the process for the appserver got restarted
> when re-installing the app, but in websphere 5 it caused a leak.
>
> Gareth Davis Logical Practice Systems Limited
>
> gareth@logicalpractice.com On 4 Aug 2004, at 16:20, Karthikeyani K
> wrote:
>
>
>> Hi, We have all requests posted to a servlet which delegates the
>> request to a Stateless Session Bean. Does creatring and invoking a
>> Httpclient postmethod in a helper class invoked by the Stateless
>> Session Bean violate any of the EJB specifications. (EJB spec says
>> sockets are not to be created in EJB code etc. ). Please suggest.
>>
>>
>> Thanks, Karthi
>>
>> __________________________________________________ Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org For additional
> commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
>
>
> --------------------------------- Do you Yahoo!? New and Improved
> Yahoo! Mail - Send 10MB messages!
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Invoke a httpclient in a EJB
Posted by Karthikeyani K <ka...@yahoo.com>.
Thanks everyone.
The EJB restrictions specified at http://java.sun.com/blueprints/qanda/ejb_tier/restrictions.html state that
Enterprise beans should not listen on, accept connections on, or mutlicast from a network socket.
Why can an enterprise bean not listen to or accept connections on a socket?
Because if an enterprise bean is listening on a socket, it can't be passivated -- it must always be available. Enterprise beans can be network socket clients, and so they can use other network resources (including other enterprise bean servers) to do their jobs. Just as with a database connection, don't hang on to open client sockets across method calls; instead, open them, communicate through the socket, and close it before returning from the method.
So does it mean that we cannot use a HttpClient to invoke a postmethod from within a EJB, as httpclient creates sockets. Please clarify. Is there any other alternate way.
Thanks,
Karthi
Gareth Davis <ga...@logicalpractice.com> wrote:
EJB + threads + httpclient... yes does break the letter of the spec's,
but yep it works and it works just fine.
Who ever wrote the spec that said you couldn't open a socket in an EJB
really wasn't living in the real world.
The only thing to watch is that MultiThreadedConnectionManager does
start it's own thread for managing the pool, this does work in an EJB
but it won't be shutdown correctly when the application is stopped, you
may find that you create a thread leak.
Having said this I've only tried this in WebSphere 4 and 5. Version 4
it wasn't a big deal as the process for the appserver got restarted
when re-installing the app, but in websphere 5 it caused a leak.
Gareth Davis
Logical Practice Systems Limited
gareth@logicalpractice.com
On 4 Aug 2004, at 16:20, Karthikeyani K wrote:
> Hi,
> We have all requests posted to a servlet which delegates the
> request to a Stateless Session Bean. Does creatring and invoking a
> Httpclient postmethod in a helper class invoked by the Stateless
> Session Bean violate any of the EJB specifications. (EJB spec says
> sockets are not to be created in EJB code etc. ). Please suggest.
>
>
> Thanks,
> Karthi
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
Re: Invoke a httpclient in a EJB
Posted by Gareth Davis <ga...@logicalpractice.com>.
EJB + threads + httpclient... yes does break the letter of the spec's,
but yep it works and it works just fine.
Who ever wrote the spec that said you couldn't open a socket in an EJB
really wasn't living in the real world.
The only thing to watch is that MultiThreadedConnectionManager does
start it's own thread for managing the pool, this does work in an EJB
but it won't be shutdown correctly when the application is stopped, you
may find that you create a thread leak.
Having said this I've only tried this in WebSphere 4 and 5. Version 4
it wasn't a big deal as the process for the appserver got restarted
when re-installing the app, but in websphere 5 it caused a leak.
Gareth Davis
Logical Practice Systems Limited
gareth@logicalpractice.com
On 4 Aug 2004, at 16:20, Karthikeyani K wrote:
> Hi,
> We have all requests posted to a servlet which delegates the
> request to a Stateless Session Bean. Does creatring and invoking a
> Httpclient postmethod in a helper class invoked by the Stateless
> Session Bean violate any of the EJB specifications. (EJB spec says
> sockets are not to be created in EJB code etc. ). Please suggest.
>
>
> Thanks,
> Karthi
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Invoke a httpclient in a EJB
Posted by Roland Weber <RO...@de.ibm.com>.
Hello Karthi,
HttpClient does create sockets. And it creates threads
in some situations, for example when using timeouts
while creating sockets. It's definitely not EJB friendly.
cheers,
Roland
Karthikeyani K <ka...@yahoo.com>
04.08.2004 17:20
Please respond to
"Commons HttpClient Project"
To
commons-httpclient-dev@jakarta.apache.org
cc
Subject
Invoke a httpclient in a EJB
Hi,
We have all requests posted to a servlet which delegates the
request to a Stateless Session Bean. Does creatring and invoking a
Httpclient postmethod in a helper class invoked by the Stateless Session
Bean violate any of the EJB specifications. (EJB spec says sockets are not
to be created in EJB code etc. ). Please suggest.
Thanks,
Karthi
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com