users@jaxb.java.net

marshal to an Output Stream which is derived from an urlConnection

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

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....