users@jaxb.java.net

marshal to an Output Stream which is derived from an urlConnection Part II

From: ray_lukas <ray_lukas_at_comcast.net>
Date: Fri, 21 Jan 2005 15:59:13 -0500

I would like to add one, well two, more things to this problem description
which might prove useful. I added a network packet monitoring system to the
web server. The Get packet is seen and processed correctly and the Java
model is instantiated by JAXB. There are no packets sent to the web server
from the code below which I included in my first message. The code below
never seems to send anything to the web server which is serving my XML file.

 

Also a closer inspection of the marshaller.marshal(clientConfig,
urlOutPutStream); command shows 2655 bytes have been sent to the web server,
which never seems to make it there. I can see the counts set from within the
Eclipse debugging session but no such packet is sent over the network to the
web server.

 

Is there a problem in JAXB?

 

Previous message text below:

 

 

It is my understanding that JAXB can marshal to an Output Stream which is
derived from an urlConnection. Is this correct? Here is the code which I
think should work. Certainly it marshals the ClientConfiguartion object to
the fileOutPutStream. But not to the urlOutPutStream. Can anyone see why? I
have been using JAXB for quite some time and it is great, but I have to get
this working because I can not have these files sit on the client machines.

 

I have included my policy file entry which only seems to be needed to
Marshalling, Un-Marshalling is working perfectly from the web server.

 

The code executes all the way through successfully, no exceptions are
thrown, no visible errors. I am using an ISP so I can not examine the log
files.

 

Does anyone have this working.

 

Many thanks!

Ray Lukas

Ray_lukas_at_comcast.net

 

 

private void marshallTask(ClientConfiguartion clientConfig) throws Exception
{

            this is where I set up a marshaller, I like pretty output so I
use the set Property

                        JAXBContext jc = JAXBContext.newInstance(
"client.generated" );

                        Marshaller marshaller = jc.createMarshaller();

 
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));


                        

here is the section that tries to marshal the ClientConfiguartion object to
a web page.

I left out the actual web page name so you will have to use one of your own
to run this.

                        URL url = new URL( "http://www.myPage.com/" +
task.getClientName() + "ConfigFileA.xml" );

                        URLConnection urlConnection = url.openConnection();

                        urlConnection.setDoOutput(true);

                        OutputStream urlOutPutStream =
urlConnection.getOutputStream();

                        marshaller.marshal(clientConfig, urlOutPutStream);

                        urlOutPutStream.flush();

                        urlOutPutStream.close();

                                    

just as a sanity check I am also going to set up a file Output Stream and
marshal to that.

                        OutputStream fileOutPutStream = new
FileOutputStream("config.xml");

                        marshaller.marshal(clientConfig, fileOutPutStream);

                        fileOutPutStream.flush();

                        fileOutPutStream.close();

            }

 

 

policy file on the local machine contains and is accessed.

permission java.net.SocketPermission "www.myPage.com:80", "connect,resolve";

 

State of a policy file on the ISP is unknown and might be the cause for my
misery, there is none I would guess....