File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Passing around java object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Passing around java object" Watch "Passing around java object" New topic
Author

Passing around java object

Jack Adams
Greenhorn

Joined: Jun 08, 2004
Posts: 25
I have MyClass that will be on TomCat.
I have a "procedure" that will be run on BEA(maybe others). This service queries DB that returns a java object.
I plan to call a servlet on BEA that returns this object.
So, MyClass in TomCat sends request to BEA servlet using java.net classes. Response from BEA sends back java object.
Seems ok? I want to avoid VPN to BEA. Should I be looking at different solution? How do I return java object? I have so far only returned text and such.
I would prefer something simple.
Any ideas/comments?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Jack Adams wrote:sends request to BEA servlet using java.net classes.

We'll need more detail on this step.

Are you sending an HTTP request? If so, you are limited to text which is all that is supported by the protocol.

If you want true RPC capability you'll need to explore other mechanisms. Perhaps RMI?

In any case, this isn't a web services question as far as I can tell, so it's been moved along to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jack Adams
Greenhorn

Joined: Jun 08, 2004
Posts: 25
Hoping HTTP request

P.S. Any way of getting question out of sockets and protocols.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Again, if you need to use HTTP, you are limited to text responses. Is that what you want?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
This service queries DB that returns a java object.


In what form does this DB return a Java object?

You can serialize Java objects and move them around with HTTP just like other binary streams.

Bill
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
RMI can work over HTTP (HTTP Tunneling). See:
Frequently Asked Questions: JavaTM RMI and Object Serialization
C.10 How can I make outgoing Java RMI calls through a local firewall?
rmiservlethandler.zip
However:
The major disadvantage of HTTP tunneling is that it does not permit inward calls or multiplexed connections. A secondary disadvantage is that the http-to-cgi method opens a dramatic security hole on the server side, since without modification it will redirect any incoming request to any port.

With servlets you are dealing with "the Web" and "the Web" doesn't know anything about Java or Java objects - it's all about the HTTP protocol and IANA MIME Media Types (as specified by the HTTP Content-Type entity-header). JSPs generate "text/html" content - that is HTML intended for consumption by web browsers. Ultimately you are interrested in the data that is the result of your DB query. Popular web content-types for machine-readable data are "application/xml" and "application/json". "application/json" is more targeted towards consumption by browser-based JavaScript code as it is the case with the Google AJAX Search API (Using Google's AJAX Search API with Java (2008-Jun-10)).

"application/xml" carries the data within an XML document - this approach is often referred to as "POX over HTTP" (POX: plain old XML). You can simply use XML Schema to define the documents to carry your query and result set data and then use something like JAXB (Object Serialization with the JAXB Libraries†) to do the XML-to-Java (unmarshal) and Java-to-XML (marshal) translation work for you. SOAP web services take this approach to the extreme as they carry the XML document as the "payload" in their "body" while they use SOAP headers for all sorts of enterprisy extensions.

† This tip is based on JAXB 1.0 that was part of the Java Developer Web Services Pack - however the approach is valid for JAXB 2.0 which is part of Java 6 (or can be used with Java 5) and the sample code contains a JAXBServlet.java which could be used as a starting point
Sandeep Kumar Jakkaraju
Ranch Hand

Joined: Feb 25, 2009
Posts: 75
I can tell you about BlazeDS ....it converts Java Object into a Action Script Object .....!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing around java object