Axis Webservice - how to return XML-Document?

Discussion in 'Java' started by Guenter Dannhaeuser, Jan 17, 2006.

  1. 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.
     
    Guenter Dannhaeuser, Jan 17, 2006
    #1
    1. Advertising

  2. Guenter Dannhaeuser

    Venky Guest

    Venky, Jan 17, 2006
    #2
    1. Advertising

  3. On 17 Jan 2006 00:28:00 -0800, "Venky" <> wrote:

    >http://www.opensubscriber.com/message//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, Jan 17, 2006
    #3
  4. Ok, got it ... Tomcat-logs are very useful ...
    Thanks!
     
    Guenter Dannhaeuser, Jan 17, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joey Vendetta
    Replies:
    0
    Views:
    3,508
    Joey Vendetta
    Apr 1, 2004
  2. Stefan
    Replies:
    0
    Views:
    772
    Stefan
    May 6, 2004
  3. Replies:
    0
    Views:
    990
  4. Tony Prichard
    Replies:
    0
    Views:
    788
    Tony Prichard
    Dec 12, 2003
  5. Cyril
    Replies:
    2
    Views:
    4,555
    Cyril
    Jun 1, 2006
Loading...

Share This Page