Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Axis Webservice - how to return XML-Document?

Thread Tools

Axis Webservice - how to return XML-Document?

Guenter Dannhaeuser
Posts: n/a


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:

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:


(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:

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

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

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

Thanks a lot for all help.
Reply With Quote
Posts: n/a
See if this helps..

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

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.

Reply With Quote
Guenter Dannhaeuser
Posts: n/a
On 17 Jan 2006 00:28:00 -0800, "Venky" <(E-Mail Removed)> wrote:


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.S END_TYPE_DIME);
DataHandler dh = new DataHandler(new
AttachmentPart attachment = new AttachmentPart(dh);
return "attachment";

For testing purposes i use following tempfile:

<?xml version="1.0" encoding="iso-8859-1" ?>
<rdf:RDF xmlns:rdf=""
<rdfescription rdf:about=""
dc:title="RDF/XML Syntax Specification (Revised)">
<rdfescription ex:fullName="Dave Beckett">
<ex:homePage rdf:resource="" />

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

MessageContext context = stub._getCall().getMessageContext();
Message msg = context.getCurrentMessage();

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

The clients output:

xmlns:rdf="" >

Any hints?
Reply With Quote
Guenter Dannhaeuser
Posts: n/a

Ok, got it ... Tomcat-logs are very useful ...
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to call a WEBSERVICE in another WEBSERVICE (AXIS/ TOMCAT) Cyril Java 2 06-01-2006 06:07 PM
Calling a Web Service using Axis, from within an Axis Web Service running under Tomcat hocho888 Java 1 04-29-2005 08:26 PM
AXIS jars org.apache.axis.wsi.* and org.apache.axis.transport.jms.* Java 0 02-23-2005 04:02 PM
Axis 1.1 don't delete attachments in the axis attachment cache Stefan Java 0 05-06-2004 08:00 PM
axis.jar does not contain org.apache.axis.client.ServiceClient? Joey Vendetta Java 0 04-01-2004 05:51 PM