axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexandre Touret <atouret.nos...@free.fr>
Subject Re: Attachment upload Client to Server
Date Thu, 08 Sep 2005 07:32:13 GMT
Stefan Schuster wrote:

> Hi everybody,
>
> how can I send an attachment from the client to an server without
> using the DataHandler in the method signature? I tried
> to get the MessageContext (getCurrentMessageContext()), but it
> returns null.
>
> How can I obtain an messageContext to set the attachment to an
> message in the client?
>
> Thanks in advance,
>
> Stefan
>
>
>
Hello,
I have an example where the server sends an attachment


 public SOAPEnvelope extractReport(String _reportName, String _path, 
HashMap _parameters, String _format)
            throws RemoteException {
        trace.info("Extracting report...");

        try {
            MessageContext msgContext = MessageContext.getCurrentContext();
            Message response = msgContext.getResponseMessage();
            Iterator attachmentsIterator = response.getAttachments();

            if (attachmentsIterator == null) {
                trace.fatal("No Support for attachments !");
                throw new SOAPException("No Support for attachments");
            }
            //Crystal Reports Extraction
            ReportBuilder builder = ReportFactory.getFactory().getBuilder();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ReportFormat format = ReportFormat.getReportFormat(_format);
            final String host = 
ConfigSingleton.getInstance().getConfiguration().getString(Conf.CRYSTAL_HOST);
            Exportable export = new ExportableImpl(out, format, host, 
_parameters, _path);
            builder.getReport(export).export();
            ByteArrayInputStream input = new 
ByteArrayInputStream(out.toByteArray());
            AttachmentPart current = response.createAttachmentPart();
            current.setContent(input, format.getContentType());
            
current.setContentId(_reportName!=null?_reportName:REPORT_CONTENT_ID);
            response.addAttachmentPart(current);
            response.saveChanges();
            return response.getSOAPEnvelope();
        } catch (ReportException e) {
            trace.error(getClass().getName() + ".extractReport():" + 
e.getMessage(), e);
            throw new RemoteException(e.getMessage(), e);
        } catch (SOAPException e) {
            trace.error(getClass().getName() + ".extractReport():" + 
e.getMessage(), e);
            throw new RemoteException(e.getMessage(), e);
        } catch (ConfigurationException e) {
            trace.error(getClass().getName() + ".extractReport():" + 
e.getMessage(), e);
            throw new RemoteException(e.getMessage(), e);
        } finally {
            trace.info("Report extracted");
        }
    }


Hope this helps

Alexandre

Mime
View raw message