aspose file tools*
The moose likes Web Services and the fly likes Retrieving an SOAP Attachement with Axis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Retrieving an SOAP Attachement with Axis" Watch "Retrieving an SOAP Attachement with Axis" New topic
Author

Retrieving an SOAP Attachement with Axis

Torsten Schindler
Greenhorn

Joined: Aug 18, 2004
Posts: 13
Hi *,

Status:

Problem:
Retrieving an attachement with an Axis client from an SOAP server
using SOAP::Lite

Details:
I created a Java Interface for my SOAP web service written in Perl
with SOAP::Lite and generated a WSDL description with Java2WSDL (from Axis)
to get the corresponing WSDL file for my (Perl-)SOAP web service.
Then the Java client stubs were generated with WSDL2Java.
Now I'm able to access the web service with:
...
ModelService service = new ModelServiceLocator();
Model port = service.getModel();
String[] result = port.getModelResult("doit");
...
This works.

(1) Problem:
When returning "big arrays" (6.6 MByte) containing the content of
multiple ASCII files the following error is thrown:

nested exception is: java.lang.ArrayStoreException: [B

What are the limit for arrays and how to surround them?

(2) Is it possible to solve problem (1) with using MIME attachements?

(3) Given the generated Java client stubs, how to get the
MIME attachement?

(4) What is the intention of the method extractAttachements
in ModelSoapBindingStub and how does it work?
E.g.:
public java.lang.String[] getModelResult(java.lang.String in0) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[0]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI("");
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName("urn:Model", "getModelResult"));

setRequestHeaders(_call);
setAttachments(_call);
java.lang.Object _resp = _call.invoke(new java.lang.Object[] {in0});

if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachements(_call); // <--- ???
try {
return (java.lang.String[]) _resp;
} catch (java.lang.Exception _exception) {
return (java.lang.String[]) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String[].class);
}
}
}


In Perl one can add the MIME attachement with, e.g.:
#!/usr/bin/perl
use SOAP::Transport::HTTP;
use SOAP::MIME;
SOAP::Transport::HTTP::CGI
->dispatch_to('SOAP_MIME_Test')
->handle();
BEGIN {
package SOAP_MIME_Test;
use strict;
use vars qw(@ISA);
@ISA = qw(SOAP::Server: arameters);
sub echo {
my $self = shift;
my $envelope = pop;
foreach my $part (@{$envelope->parts}) {
print STDERR "Attachments.cgi: attachment found! (".ref($$part).")\n";
}
print STDERR "envelope is of type: " . ref($envelope) . "\n";
my $STRING = $envelope->dataof("//echo/whatToEcho")
or die SOAP::Fault->faultcode("Client")
->faultstring("You must specify a string to echo")
->faultactor('urn:SOAP_MIME_Test#echo');
my $ent = build MIME::Entity
'Id' => "<1234>",
'Type' => "text/xml",
'Path' => "examples/attachments/some2.xml",
'Filename' => "some2.xml",
'Disposition' => "attachment";
return SOAP: ata->name("whatToEcho" => $STRING),$ent;
}
}

Best,

Torsten
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Torsten Schindler:

(2) Is it possible to solve problem (1) with using MIME attachements?

(3) Given the generated Java client stubs, how to get the
MIME attachement?

(4) What is the intention of the method extractAttachements
in ModelSoapBindingStub and how does it work?
Torsten


6.6mb is really too big for a webservice engines IMHO.... it will really bug the performance.

MIME attachments: I guess you have to give it a try using only Axis server - Axis client then Perl Server - Axis Client.

Did you checked the attachment example under axis.??

Regarding question 4, you have to see the method description in your java files. Its a method.


Spritle Software Blogs
Torsten Schindler
Greenhorn

Joined: Aug 18, 2004
Posts: 13
> 6.6mb is really too big for a webservice engines IMHO.... it will really > bug the performance.
I agree, but what are the limits?

> MIME attachments: I guess you have to give it a try using only Axis
> server - Axis client then Perl Server - Axis Client.
Axis server <-> client with attachements works fine.
But how to do it with java2WSDL generated client stubs???

> Did you checked the attachment example under axis.??
Yes, this was my first step, but didn't really help me when I want
to do it with the generated client stubs.

> Regarding question 4, you have to see the method description in your java > files. Its a method.
The APIdocs from org.apache.axis.client.Stub:

extractAttachments
public void extractAttachments(Call call)Extract attachments

Parameters:
call -

This documentation is not very helpful in my opinion!

Best,

Torsten
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Torsten Schindler:
[QB> Regarding question 4, you have to see the method description in your java > files. Its a method.
The APIdocs from org.apache.axis.client.Stub:

extractAttachments
public void extractAttachments(Call call)Extract attachments

Parameters:
call -

This documentation is not very helpful in my opinion!

Best,

Torsten[/QB]


Looking at the source Stub.java, its basically retrieves the attachments from the reponse and stores in the attachments vector.

>Yes, this was my first step, but didn't really help me when I want
>to do it with the generated client stubs.

Well...sorry i dont understand clearly here. Do you mean to say
the axis attachments example works fine as it is BUT its not working if you use your client stubs generated using wsdl2java?
Torsten Schindler
Greenhorn

Joined: Aug 18, 2004
Posts: 13
Well...sorry i dont understand clearly here. Do you mean to say
the axis attachments example works fine as it is BUT its not working if you use your client stubs generated using wsdl2java?

The example works fine: Yes. (Sorry for the unclear formulation!)
BUT I couldn't figure out how to get access to the attachements
in the attachement vector. How do I get an stubs object to call
getAttachements?
Is this the right way?
...
ModelService service = new ModelServiceLocator();
Model port = service.getModel();
String[] result = port.getModelResult("input");
// Model is just the generated interface,
// so I think a downcast to ModelBindingStub should give
// me the access to the desired stub object
Objects[] obj = ((ModelBindingStub)port).getAttachments();
// After this operation the attachment array is cleared, so
// one has to load all attachments in one go???
// How do I get content & length information about the attachments now?
...

Thanks for the immediate help!!!

Torsten
Torsten Schindler
Greenhorn

Joined: Aug 18, 2004
Posts: 13
Hi,

I think I figured it out myself.
Could you please comment on the following code snippet!!!
Is this the right way to do it?

...<snip>...
import com.example.stubs.Model;
import com.example.stubs.ModelService;
import com.example.stubs.ModelServiceLocator;
import com.example.stubs.ModelSoapBindingStub
import java.io.File;
import java.io.FileOutputStream;
import java.rmi.RemoteException;
import javax.activation.DataHandler;
import javax.xml.rpc.ServiceException;
import org.apache.axis.AxisFault;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
...<snip>...
// Initialize connection to the web service
ModelService service = new ModelServiceLocator();
Model port = service.getModel();
// Call the web service function
String[] result = port.getModelResult("someInput");
// Store all attached files
if (log.isDebugEnabled()) {
log.debug("Store all attachment files");
}
ModelSoapBindingStub stub = (ModelSoapBindingStub) port;
Object[] attachments = stub.getAttachments();
if (attachments != null) {
if (attachments.length > 0) {
for (int i = 0; i < attachments.length; i++) {
AttachmentPart attachPart = (AttachmentPart) attachments[i];
if (log.isDebugEnabled()) {
log.debug("ContentId: "+ attachPart.getContentId());
log.debug("ContentIdRef: " + attachPart.getContentIdRef());
log.debug("ContentType: " + attachPart.getContentType());
log.debug("ContentLocation: " + attachPart.getContentLocation());
log.debug("Content: " + attachPart.getContent());
}
DataHandler handler = attachPart.getDataHandler();
String storeDir = "/tmp/attachments/";
File myFile = new File(storeDir + attachPart.getContentId() + ".gz");
FileOutputStream myFOS = new FileOutputStream(myFile);
handler.writeTo(myFOS);
}
}
}

Best,

Torsten
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving an SOAP Attachement with Axis
 
Similar Threads
org.apache.axis.client.Call 's invoke method
No Such Operation Exception
Axis 1.4 Error plz help Connect Exception
Axis 1.4 username/password auth with stubs
Axis1 (1.4) - Simple client proof of concept - SAXParserException: Content is not allowed in prolog