You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by hideki tihiri <hi...@gmail.com> on 2009/03/16 19:46:21 UTC

How to pass a byte array

Hi,

i have a POJO class with following method:

public String upload( byte[] document, String filename, String sender,
String validtill )

On the client side I'm unable to call this service:

DataSource dataSource = new ByteArrayDataSource( uploadedfile.toByteArray(),
"application/octet-stream");
DataHandler dataHandler = new DataHandler(dataSource);
WS_parameters.setdocument( dataHandler );
// Exectue the service
UploadResponse resp = stub.upload(WS_parameters);

I always get following AxisFault:

the service is unknown (or similar).

Is it not possible to have a byte[] array as a parameter ?

If so, what I 'm doing wrong ?

REgards,

H.

Re: How to pass a byte array

Posted by Sagara Gunathunga <sa...@gmail.com>.
Hi hideki,

 link [1] may be help to you , also please see my inline comments .

> public String upload( byte[] document, String filename, String sender,
> DataSource dataSource = new ByteArrayDataSource( uploadedfile.toByteArray(),
> "application/octet-stream");
> DataHandler dataHandler = new DataHandler(dataSource);

If it is a file on your local file system ,it would be better to
create  DataHandler as  follows using FileDataSource without
specifying MIME  type yourself.

DataHandler dh = new DataHandler(new FileDataSource("path to file"));

> I always get following AxisFault:
>
> the service is unknown (or similar).
>
> Is it not possible to have a byte[] array as a parameter ?

No , it is possible to have a byte[] array  as a parameter for Axis2
service , but better to use DataHandler as a parameter  instead of
byte[] array , because in byte[] array it is required to  load
complete file into the memory at once.

[1] - http://wso2.org/library/3860


Thanks ,

-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://sagaras.awardspace.com/