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 "Shrotriya, Sumit" <Su...@westgroup.com> on 2002/12/19 15:47:33 UTC
Passing a DataHandler as a Parameter and returning a DataHandler
Hi All,
I need to pass a DataHandler as a Parameter and return a DataHandler from a
service over Axis....any quick start pointers or ideas?
Thanks,
Sumit
Re: Passing a DataHandler as a Parameter and returning a
DataHandler
Posted by Heitzso <he...@bellsouth.net>.
This worked for me, but caveats:
haven't tested in awhile
there may be better ways to do this
====
/**
* @return DataHandler for converted file
*/
public DataHandler getConversionFromExtraction(String outputFormat,
String extractionUrlString, String fileName)
throws ServiceException {
int numColumns;
String[] columnNames;
String[] columnDataTypes;
String[] dataElements;
try {
URL url = new URL(extractionUrlString);
URLConnection urlConnection = url.openConnection();
// set up connection to request gzip compression
urlConnection.setRequestProperty("Accept-Encoding", "gzip");
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
if ("gzip".equals(urlConnection.getContentEncoding())) {
inputStream = new GZIPInputStream(inputStream);
}
ExtractionParser extractionParser = new
ExtractionParser(inputStream);
inputStream.close();
String errorMessage = extractionParser.getErrorMessage();
if (errorMessage != null) {
// byte data[] = errorMessage.getBytes();
// DataSource dataSource = new ByteArrayDataSource(data,
"text/plain");
// return new DataHandler(dataSource);
return new DataHandler(errorMessage, "text/plain");
}
numColumns = extractionParser.getNumColumns();
columnNames = extractionParser.getColumnNames();
columnDataTypes = extractionParser.getColumnDataTypes();
dataElements = extractionParser.getDataElements();
} catch(IOException ioe) {
// byte data[] = ioe.toString().getBytes();
// DataSource dataSource = new ByteArrayDataSource(data,
"text/plain");
// return new DataHandler(dataSource);
return new DataHandler(ioe.toString(), "text/plain");
}
DataHandler dataHandler = getConversion(outputFormat, numColumns,
columnNames, columnDataTypes, dataElements, fileName);
return dataHandler;
}
====
and the proxy ...
====
public DataHandler getConversionFromExtraction(String outputFormat,
String extractionUrlString, String fileName)
throws ServiceException, IOException {
DataHandler dataHandler;
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(serviceURL);
call.setOperationName(new QName("urn:conversion",
"getConversionFromExtraction"));
call.addParameter("outputFormat",
org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter("extractionUrlString",
org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter("fileName", org.apache.axis.Constants.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnClass(javax.activation.DataHandler.class);
dataHandler = (DataHandler) call.invoke(
new Object[] { outputFormat, extractionUrlString, fileName } );
} catch (Exception e) {
throw new ServiceException(e.toString());
}
return dataHandler;
}
On Thu, 2002-12-19 at 09:47, Shrotriya, Sumit wrote:
> Hi All,
>
> I need to pass a DataHandler as a Parameter and return a DataHandler
> from a service over Axis....any quick start pointers or ideas?
>
> Thanks,
> Sumit
>
--
Heitzso <he...@bellsouth.net>
MetaMedia, Inc.