Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Axis Webservice - how to return XML-Document?

Thread view: 
Guenter Dannhaeuser - 17 Jan 2006 01:58 GMT
Hi,

I have a webservice using Jena on some RDF/XML data resulting in a
com.hp.hpl.jena.rdf.model.Model which I´d like to return to the client
as RDF/XML-Document.

com.hp.hpl.jena.rdf.model.Model has a method "write" to turn the Model
into RDF/XML and write it to an OutputStream.

First idea: return the XML in a string:

//webservice
public String lookup(String param1, String param2) {
       Model mymodel = ModelFactory.createDefaultModel();
       //do something ...
       ByteArrayOutputStream os = new ByteArrayOutputStream();
       mymodel.write(os, "RDF/XML-ABBREV");
       return os.toString();
}

... this works ok on the server-side
(System.out.println(os.toString()) = document as expected),

but on client-side all I get is:

    <rdf:RDF
       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    </rdf:RDF>

(first xmlns:rdf and all nodes missing)

//the client:
       //...
       myService service = new myServiceLocator();
       my_PortType stub = service.getMyMethod();
       System.out.println(stub.lookup("astring", "anotherstring"));
       //...

Next idea: put it in an attachment:

//webservice
       //...
       //do something ...
       MessageContext context = MessageContext.getCurrentContext();
       Message response = context.getResponseMessage();

response.getAttachmentsImpl().setSendType(Attachments.SEND_TYPE_DIME);
       DataHandler dh = new DataHandler(baos.toString(), "???");
       AttachmentPart attachment = response.createAttachmentPart(dh);
       attachment.setContentId("attachment");
       response.addAttachmentPart(attachment);

problems: how to get the DataHandler dh? how to unpack the attachment
on client-side?

Thanks a lot for all help.
Venky - 17 Jan 2006 08:28 GMT
See if this helps..
http://www.opensubscriber.com/message/axis-user@ws.apache.org/2751943.html

And also you should look at axis-user mailing list's archive.. Its a
very good place to find solutions for most of these problems..
http://marc.theaimsgroup.com/?l=axis-user&r=1&w=2

Its been a long time since I had used AXIS, but I think one straight
forward way of sending just attachments is to write a service which
returns DataHandler and make your client call that method.
Guenter Dannhaeuser - 17 Jan 2006 13:29 GMT
>http://www.opensubscriber.com/message/axis-user@ws.apache.org/2751943.html

Ok, thanks - now I have the webservice send an attachment and the
client receive the attachment using DataHandler.
But the output is still the same i.e. incomplete (see bottom).

The webservice:

public void lookup(<parameters>) {
...
       MessageContext context = MessageContext.getCurrentContext();
       Message msg = context.getResponseMessage();
msg.getAttachmentsImpl().setSendType(Attachments.SEND_TYPE_DIME);
       DataHandler dh = new DataHandler(new
FileDataSource("tempfile"));
       AttachmentPart attachment = new AttachmentPart(dh);
       msg.addAttachmentPart(attachment);
       return "attachment";
}

For testing purposes i use following tempfile:

<?xml version="1.0" encoding="iso-8859-1" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:ex="http://example.org/stuff/1.0/">
 <rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
          dc:title="RDF/XML Syntax Specification (Revised)">
   <ex:editor>
     <rdf:Description ex:fullName="Dave Beckett">
    <ex:homePage rdf:resource="http://purl.org/net/dajobe/" />
     </rdf:Description>
   </ex:editor>
 </rdf:Description>
</rdf:RDF>

The client looks like this:
       MyService service = new MyServiceLocator();
       MySoapBindingStub stub = (MySoapBindingStub) service.getgrs();

       stub.lookup(<parameters>);
       MessageContext context = stub._getCall().getMessageContext();
       Message msg = context.getCurrentMessage();

       Iterator attIter = msg.getAttachments();
       if (attIter.hasNext()) {
           AttachmentPart att = (AttachmentPart) attIter.next();
           DataHandler dh = att.getDataHandler();
           dh.writeTo(System.out);
       } else {
           System.out.println("No Attachment");
       }

The clients output:

<rdf:RDF
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
</rdf:RDF>

Any hints?
Thanks.
Guenter Dannhaeuser - 17 Jan 2006 19:00 GMT
Ok, got it ... Tomcat-logs are very useful ...
Thanks!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.