开发者

Apache AXIS2 sending large DIME attachments

I am currently working on a webservice to send large pdf files to server from client using DIME. I am using apache axis2 implementation for webservice support. I have been to get the service to work but an issue arises when I attempt to send attachments that are larger than 1MB then I get an exception. My guess is I probably would have to chunksize my attachment before sending it but I have no idea for where i can control that and also I am thinking maybe it would be another. Below is the code for the client that is uploading the files

public class PdfDriver
{

/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException
{
    // TODO Auto-generated method stub
    testAddGroup();

}

public static void testAddGroup() throws IOException
{

    try
    {
        PdfMail_ServiceLocator locator = new PdfMail_ServiceLocator();
             locator.setPdfMailSOAPEndpointAddress("http://localhost:80/services/PdfMailSOAP");

        PdfMail_PortType stub = locator.getPdfMailSOAP();

        PdfMailSOAPStub server = null;
        server = (PdfMailSOAPStub) stub;

        //Test uploading pdf
        server._setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT,   Call.ATTACHMENT_ENCAPSULATION_FORMAT_MTOM);

        FileDataSource ds = new FileDataSource("/test.zip");
        DataHandler dh = new DataHandler(ds);

        server.addAttachment(dh);



        System.out.println(server.getTimeout());
        Calendar cal = Calendar.getInstance();
        long x = cal.getTimeInMillis();
        System.out.println("Server: Start receive@ "+  "\n" +   server.sendPdf("test.zip") + "\nServer: Finished receive ");



    }
    catch (ServiceException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


   }
} 

And this is the code I use to process the attachments on the server side

public java.lang.String sendPdf(java.lang.String pdfToSend) throws java.rmi.RemoteException
{
    String result = "";
    AttachmentPart[] attachments = null;
    try
    {
        attachments = getAttachments();
    }
    catch (Exception e1)
    {
        result = "null attachments getAttachments exception";
        e1.printStackTrace();
    }
    if (attachments != null)
    {
        for (int i = 0; i < attachments.length; i++)
        {
            AttachmentPart attachment = attachments[i];
            try
            {
                File file = new File(pdfToSend);
                InputStream in = attachment.getDataHandler().getInputStream();
                OutputStream out = new FileOutputStream(file);
                byte[] buffer = new byte[8192];
                int len;

                while ((len = in.read(buffer)) > 0)
                    out.write(buffer, 0, len);

                out.close();
                in.close();

                result += "File saved on the server\nFile Size : " + (file.length() / 1048576) + "MB \nSend Type : " + this.receivedType;

            }
            catch (IOException e)
            {
                result += "exception IO";
                e.printStackTrace();
            }
            catch (SOAPException e)
            {
                result += "SOAP exception";
                e.printStackTrace();
            }
        }
    }
    return result;
}

private AttachmentPart[] getAttachments() throws Exception
{
    MessageContext msgContext = MessageContext.getCurrentContext();
    Message message = msgContext.getRequestMessage();
    Attachments attachmentsimpl = message.getAttachmentsImpl();
    if (null == attachmentsimpl)
    {
        return new AttachmentPart[0];
    }
    int attachmenstCount = attachmentsimpl.getAttachmentCount();
    this.receivedType = attachmentsimpl.getSendType();
    AttachmentPart attachments[] = new AttachmentPart[attachmenstCount];

    Iterator<AttachmentPart> iter = attachmentsimpl.getAttachments().iterator();
    int count = 0;
    while (iter.hasNext())
    {
        AttachmentPart part = iter.next();
        attachments[count++] = part开发者_高级运维;
    }
    return attachments;

}

If anyone knows what the issue would be causing an AxisFault for files larger that 1MB I would appreciate it. Thanks.


Axis2 does not support DIME, see previous question: Java client calling WSE 2.0 with DIME attachment


Knowing exactly what the exception is would help, but to just blindly guess, your Apache config is probably limiting upload (http post) size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜