【问题标题】:Apache AXIS2 sending large DIME attachmentsApache AXIS2 发送大型 DIME 附件
【发布时间】:2010-12-20 23:32:23
【问题描述】:

我目前正在开发一个网络服务,以使用 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,我将不胜感激。谢谢。

【问题讨论】:

  • 显示的代码不是使用 Axis2,而是使用 Axis 1.x。

标签: java web-services axis2 webservice-client attachment


【解决方案1】:

Axis2 不支持 DIME,请参阅上一个问题: Java client calling WSE 2.0 with DIME attachment

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多