You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by James CE Johnson <jc...@tragus.org> on 2004/03/18 18:21:32 UTC
Can someone help a newbie help with attachments?
Hi,
We're working on a "file archive" service. This service will need to let
its clients upload files for archiving and later retrive them. (Ok, its
more complex than that but that's the relevant bit...)
What I have thus far is working OK but I would appreciate some more
experienced eyes on it and their opinions of my approach. I'm always
anxious to hear a Better Way.
I started with this interface:
public interface EchoService
{
public void echo();
}
That was given to java2wsdl and the resulting wsdl was then given to
wsdl2java. I wrote the following EchoClient to use the generated service
locator and binding stub:
public class EchoClient
{
private static Logger log = Logger.getLogger(EchoClient.class);
public static void main(String [] args)
{
try
{
System.err.println("Sending /etc/profile");
EchoServiceSoapBindingStub c = (EchoServiceSoapBindingStub)
(new EchoServiceServiceLocator().getEchoService());
DataHandler dh = new DataHandler(new
FileDataSource("/etc/profile"));
c.addAttachment(dh);
c.echo();
Object [] attachments = c.getAttachments();
System.err.println("Hello World");
for(int i = 0 ; i < attachments.length ; ++i)
{
AttachmentPart part = (AttachmentPart) attachments[i];
System.err.println("getSize = " + part.getSize());
System.err.println("getAttachmentFile = " +
part.getAttachmentFile());
System.err.println("getContentLocation = " +
part.getContentLocation());
dh = part.getDataHandler();
System.err.println("dh.getName() = " + dh.getName());
// Create a File using dh.getName() and do whatever with
its contents.
// Then delete that file so that we don't fillup our
/tmp space.
}
}
catch(Exception e)
{
log.error("oops", e);
}
}
}
I then implemented this simple server object to handle the 'echo' requests:
public class EchoService
{
private static Logger log = Logger.getLogger(EchoService.class);
public void echo()
{
log.info("Hello World");
try
{
MessageContext msgContext = MessageContext.getCurrentContext();
Message reqMsg = msgContext.getRequestMessage();
Attachments messageAttachments = reqMsg.getAttachmentsImpl();
if (messageAttachments == null)
{
log.info("No Attachments");
return;
}
log.info(
messageAttachments.getAttachmentCount() + " attachments");
int attachmentCount = messageAttachments.getAttachmentCount();
AttachmentPart attachments[] =
new AttachmentPart[attachmentCount];
Iterator it = messageAttachments.getAttachments().iterator();
int count = 0;
while (it.hasNext())
{
AttachmentPart part = (AttachmentPart) it.next();
log.info("getSize = " + part.getSize());
log.info("getAttachmentFile = " + part.getAttachmentFile());
log.info("getContentLocation = " +
part.getContentLocation());
DataHandler dh = part.getDataHandler();
log.info("dh.getName() = " + dh.getName());
// Create a File using dh.getName() and do whatever with
its contents.
// Then delete that file so that we don't fillup our
/tmp space.
}
Message resp = msgContext.getResponseMessage();
log.info("Response message is " + resp);
AttachmentPart part = (AttachmentPart)
resp.createAttachmentPart();
part.setContent("I like cheese", "text/plain");
resp.addAttachmentPart(part);
}
catch (Exception e)
{
log.error(e);
}
}
}
Thanks in advance!
James
Re: Can someone help a newbie help with attachments?
Posted by Jim Collins <ja...@blueyonder.co.uk>.
Here is the URL for the Slide project:
http://jakarta.apache.org/slide/index.html
Regards
Jim.
----- Original Message -----
From: "James CE Johnson" <jc...@tragus.org>
To: <ax...@ws.apache.org>
Sent: Monday, March 22, 2004 2:26 PM
Subject: Re: Can someone help a newbie help with attachments?
> > Have you had a look at the Slide project?
>
> No, I haven't heard of it. Googling for "axis +slide" turns up some
> interesting things but not, I think, what you're talking about. Do you
> have a URL handy?
>
> >
> > Regards
> >
> > Jim.
>
> Thanks!
> James
>
>
Re: Can someone help a newbie help with attachments?
Posted by James CE Johnson <jc...@tragus.org>.
> Have you had a look at the Slide project?
No, I haven't heard of it. Googling for "axis +slide" turns up some
interesting things but not, I think, what you're talking about. Do you
have a URL handy?
>
> Regards
>
> Jim.
Thanks!
James
Re: Can someone help a newbie help with attachments?
Posted by Jim Collins <ja...@blueyonder.co.uk>.
Have you had a look at the Slide project?
Regards
Jim.
----- Original Message -----
From: "James CE Johnson" <jc...@tragus.org>
To: <ax...@ws.apache.org>
Sent: Thursday, March 18, 2004 5:21 PM
Subject: Can someone help a newbie help with attachments?
> Hi,
>
> We're working on a "file archive" service. This service will need to let
> its clients upload files for archiving and later retrive them. (Ok, its
> more complex than that but that's the relevant bit...)
>
> What I have thus far is working OK but I would appreciate some more
> experienced eyes on it and their opinions of my approach. I'm always
> anxious to hear a Better Way.
>
> I started with this interface:
>
> public interface EchoService
> {
> public void echo();
> }
>
> That was given to java2wsdl and the resulting wsdl was then given to
> wsdl2java. I wrote the following EchoClient to use the generated service
> locator and binding stub:
>
> public class EchoClient
> {
> private static Logger log = Logger.getLogger(EchoClient.class);
>
> public static void main(String [] args)
> {
> try
> {
> System.err.println("Sending /etc/profile");
> EchoServiceSoapBindingStub c = (EchoServiceSoapBindingStub)
> (new EchoServiceServiceLocator().getEchoService());
> DataHandler dh = new DataHandler(new
> FileDataSource("/etc/profile"));
> c.addAttachment(dh);
> c.echo();
> Object [] attachments = c.getAttachments();
> System.err.println("Hello World");
> for(int i = 0 ; i < attachments.length ; ++i)
> {
> AttachmentPart part = (AttachmentPart) attachments[i];
> System.err.println("getSize = " + part.getSize());
> System.err.println("getAttachmentFile = " +
> part.getAttachmentFile());
> System.err.println("getContentLocation = " +
> part.getContentLocation());
>
> dh = part.getDataHandler();
> System.err.println("dh.getName() = " + dh.getName());
>
> // Create a File using dh.getName() and do whatever with
> its contents.
> // Then delete that file so that we don't fillup our
> /tmp space.
> }
> }
> catch(Exception e)
> {
> log.error("oops", e);
> }
> }
> }
>
>
> I then implemented this simple server object to handle the 'echo'
requests:
>
> public class EchoService
> {
> private static Logger log = Logger.getLogger(EchoService.class);
>
> public void echo()
> {
> log.info("Hello World");
>
> try
> {
> MessageContext msgContext =
MessageContext.getCurrentContext();
> Message reqMsg = msgContext.getRequestMessage();
> Attachments messageAttachments = reqMsg.getAttachmentsImpl();
> if (messageAttachments == null)
> {
> log.info("No Attachments");
> return;
> }
>
> log.info(
> messageAttachments.getAttachmentCount() + " attachments");
> int attachmentCount = messageAttachments.getAttachmentCount();
> AttachmentPart attachments[] =
> new AttachmentPart[attachmentCount];
> Iterator it = messageAttachments.getAttachments().iterator();
> int count = 0;
> while (it.hasNext())
> {
> AttachmentPart part = (AttachmentPart) it.next();
> log.info("getSize = " + part.getSize());
> log.info("getAttachmentFile = " +
part.getAttachmentFile());
> log.info("getContentLocation = " +
> part.getContentLocation());
>
> DataHandler dh = part.getDataHandler();
> log.info("dh.getName() = " + dh.getName());
>
> // Create a File using dh.getName() and do whatever with
> its contents.
> // Then delete that file so that we don't fillup our
> /tmp space.
> }
>
> Message resp = msgContext.getResponseMessage();
> log.info("Response message is " + resp);
> AttachmentPart part = (AttachmentPart)
> resp.createAttachmentPart();
> part.setContent("I like cheese", "text/plain");
> resp.addAttachmentPart(part);
>
> }
> catch (Exception e)
> {
> log.error(e);
> }
> }
> }
>
> Thanks in advance!
> James
>
>