Is it possible (and sensible) to open ServerSocket in one of EJB? My web
application (realized in JEE) needs to establish TCP connection with
external application. Data exchange with this application is sometimes
initiated by the application and sometimes by web application on JEE server.
Maybe you have some other suggestions what kind of technology I should
use to establish connetion between client aplication and web application
on JEE server?
Regards
Mariusz
> Is it possible (and sensible) to open ServerSocket in one of EJB? My web
> application (realized in JEE) needs to establish TCP connection with
> external application. Data exchange with this application is sometimes
> initiated by the application and sometimes by web application on JEE
> server.
I don't know if it will work - i believe the EJB spec bans the use of
Socket and ServerSocket from EJBs. However, there's a vague chance it will
work, and if it does, i imagine opening a server socket right from an EJB
will be the simplest way of solving your problem. However, it's naughty,
since in J2EE, managing sockets and so on is the app server's job. But ...
> Maybe you have some other suggestions what kind of technology I should
> use to establish connetion between client aplication and web application
> on JEE server?
... that's the trouble. I'm not aware of a standard, portable way of
adding application-layer protocols to app servers.
The closest thing i can think of is the J2EE Connector Architecture, one
of the more arcane and mysterious corners of J2EE. You'd write a JCA
resource adaptor to handle the connection, configure an instance of it in
your app server, and use that from an EJB, just as you'd use a database
connection or message queue. Even JCA has no bearing on server sockets,
but i believe that in a resource adaptor, you're allowed to manipulate
them directly, which you can't do from an EJB.
However, i just had a read of the JCA spec, and i got two thirds of the
way through before going stark raving mad, so i'm not sure this is a
productive approach.
You could consider using JMS at the EJB, and then writing a little
standalone server app which would mediate between the external app and a
JMS queue. This is also not pretty, though.
tom
--
The future will accost us with boob-slapping ferocity. -- H. G. Wells
Using client sockets in an EJB is OK, using server sockets is not.
From EJB 3.0 Core:
"The EJB architecture allows an enterprise bean instance to be a network
socket client, but it does not allow it to be a network server.
Allowing the instance to become a network server would conflict with
the basic function of the enterprise bean — to serve the EJB clients."
Also:
"An enterprise bean must not attempt to listen on a socket, accept
connections on a socket, or use a socket for multicast."
This is in 21.1.2, Programming Restrictions.
AHS
Listening to socket is strictly forbidden in the EJB spec.
You can have the client use:
- EJB Calls
- web service calls
If you really want to use listen to socket, then it
must be done in a JCA adapter.
Arne
I would not be so worried about the management of sockets.
I would be more worried about the management of threads.
Threads being blocked while waiting for connection would
create a mess in thread management.
Arne
True. But you could set a timeout, and then do accepts in a polling way
from a managed thread. Your EJB's API could look like:
boolean checkForConnectionRequest(); // does ServerSocket.accept
DataObject processRequestFromClient(); // does Socket.read
etc. This would be a bit ugly, though.
tom
--
People don't want nice. People want London. -- Al
JCA is complex, indeed. For a good overview, try my JDJ article,
"Understanding JCA", at http://java.sys-con.com/node/46283.
--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
> On Mar 30, 11:40�am, Tom Anderson <t...@urchin.earth.li> wrote:
>> On Mon, 30 Mar 2009, mk wrote:
>>> Maybe you have some other suggestions what kind of technology I should
>>> use to establish connetion between client aplication and web application
>>> on JEE server?
>>
>> ... that's the trouble. I'm not aware of a standard, portable way of
>> adding application-layer protocols to app servers.
>>
>> The closest thing i can think of is the J2EE Connector Architecture, one
>> of the more arcane and mysterious corners of J2EE. You'd write a JCA
>> resource adaptor to handle the connection, configure an instance of it in
>> your app server, and use that from an EJB, just as you'd use a database
>> connection or message queue. Even JCA has no bearing on server sockets,
>> but i believe that in a resource adaptor, you're allowed to manipulate
>> them directly, which you can't do from an EJB.
>>
>> However, i just had a read of the JCA spec, and i got two thirds of the
>> way through before going stark raving mad, so i'm not sure this is a
>> productive approach.
>
> JCA is complex, indeed. For a good overview, try my JDJ article,
> "Understanding JCA", at http://java.sys-con.com/node/46283.
It's a good overview from the client point of view, although a bit heavy
on the enterprisey Big Words and light on code for my taste, but it
doesn't have much to say about implementing resource adaptors.
This guy came to the same conclusion we have about needing to write an RA
to use a server socket, but he then actually did it:
http://itdevworld.wordpress.com/2008/08/26/java-connector-architecture-jca/
Although as far as i can tell he never delivered on his promise to write
about it!
tom
--
You have now found yourself trapped in an incomprehensible maze.
As for inbound connectors I didn't had time to finish this yet but
I'll try to focus again on it on the next weeks. But, still there is
one:
http://itdevworld.wordpress.com/2008/12/24/inbound-jca-connectors-introduction/
As people already warned you here, a resource adapter isn't that easy
to implement, not to mention that there are slight differences between
containers and the spec (as always) isn't that clear on every aspect.
Feel free to post comments there!
regards,
Rafael Ribeiro
On 7 abr, 17:02, Tom Anderson <t...@urchin.earth.li> wrote:
> On Sat, 4 Apr 2009, Lee Fesperman wrote:
> > On Mar 30, 11:40�am, Tom Anderson <t...@urchin.earth.li> wrote:
> >> On Mon, 30 Mar 2009, mk wrote:
> >>> Maybe you have some other suggestions what kind of technology I should
> >>> use to establish connetion between client aplication and web application
> >>> on JEE server?
>
> >> ... that's the trouble. I'm not aware of a standard, portable way of
> >> adding application-layer protocols to app servers.
>
> >> The closest thing i can think of is the J2EE Connector Architecture, one
> >> of the more arcane and mysterious corners of J2EE. You'd write a JCA
> >> resource adaptor to handle the connection, configure an instance of it in
> >> your app server, and use that from an EJB, just as you'd use a database
> >> connection or message queue. Even JCA has no bearing on server sockets,
> >> but i believe that in a resource adaptor, you're allowed to manipulate
> >> them directly, which you can't do from an EJB.
>
> >> However, i just had a read of the JCA spec, and i got two thirds of the
> >> way through before going stark raving mad, so i'm not sure this is a
> >> productive approach.
>
> > JCA is complex, indeed. For a good overview, try my JDJ article,
> > "Understanding JCA", athttp://java.sys-con.com/node/46283.
>
> It's a good overview from the client point of view, although a bit heavy
> on the enterprisey Big Words and light on code for my taste, but it
> doesn't have much to say about implementing resource adaptors.
>
> This guy came to the same conclusion we have about needing to write an RA
> to use a server socket, but he then actually did it:
>
> http://itdevworld.wordpress.com/2008/08/26/java-connector-architectur...
JCA for socket comm must have been done a gazillion times.
It is not that unusual.
I even believe some of the more advanced IDE's has wizards to
generate a lot of the JCA stuff.
Arne
Wouldn't a single adapter with support for bidirectional communication
do fine ?
Arne