Apache AXIS2 发送大型 DIME 附件

发布于 2024-10-08 17:21:40 字数 3788 浏览 0 评论 0原文

我目前正在开发一个网络服务,使用 DIME 将大型 pdf 文件从客户端发送到服务器。我正在使用 apache axis2 实现来支持 Web 服务。我一直想让该服务正常工作,但当我尝试发送大于 1MB 的附件时出现问题,然后出现异常。我的猜测是,我可能必须在发送附件之前将其分块,但我不知道在哪里可以控制它,而且我想也许这会是另一个。下面是上传文件的客户端代码

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();
    }


   }
} 

这是我用来在服务器端处理附件的代码

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;

}

如果有人知道问题会导致大于 1MB 的文件出现 AxisFault,我将不胜感激。谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吾性傲以野 2024-10-15 17:21:40

Axis2不支持DIME,请参阅上一个问题:
Java 客户端使用 DIME 附件调用 WSE 2.0

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

云巢 2024-10-15 17:21:40

确切地知道异常是什么会有所帮助,但如果只是盲目猜测,您的 Apache 配置可能会限制上传(http post)大小。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文