Java Applet SOAPMessage导致“SAAJ0540:保存多部分消息时出错”

时间:2011-09-14 18:46:42

标签: java soap applet

我有一个问题,我已经归结为这个简单的例子。

import java.applet.Applet;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;

public class SOAPTest2 extends Applet {
    private static final long serialVersionUID = -1;

    public void init(){
        try{
            MessageFactory mf = MessageFactory.newInstance();
            SOAPMessage sm = mf.createMessage();

            System.out.println("About to fail");
            sm.writeTo(System.out);
            System.out.println();

            System.out.println("If you see this, it didn't fail.");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

当我在eclipse中运行它时(JDK 1.6.0_27)它按预期工作,我得到以下输出:

About to fail
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body/></SOAP-ENV:Envelope>
If you see this, it didn't fail.

当我在浏览器中作为applet运行时,我在java控制台中收到以下错误。

About to fail
14-Sep-2011 1:20:51 PM com.sun.xml.internal.messaging.saaj.soap.MessageImpl saveChanges
SEVERE: SAAJ0540: Error during saving a multipart message
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.saveChanges(Unknown Source)
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.writeTo(Unknown Source)
    at SOAPTest2.init(SOAPTest2.java:16)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.sun.xml.internal.messaging.saaj.util.FastInfosetReflection.<clinit>(Unknown Source)
    at com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer.transform(Unknown Source)
    at com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl.output(Unknown Source)
    at com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl.output(Unknown Source)
    at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getContentAsStream(Unknown Source)
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.getHeaderBytes(Unknown Source)
    ... 5 more
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission com.sun.xml.internal.fastinfoset.parser.string-interning read)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    at java.lang.System.getProperty(Unknown Source)
    at com.sun.xml.internal.fastinfoset.Decoder.<clinit>(Unknown Source)
    ... 13 more

我不知道为什么会这样。我只是创建空的SOAPMessage并尝试将其写入System.out。我没有访问任何本地资源。我在MessageImpl.saveChanges和FastInfosetReflection上做了很多搜索但无济于事。请试试这个例子,如果您有任何想法,请告诉我。

恭敬地,我要求任何告诉我签署我的Jar的答案都附有合理的解释,因为上面的最小例子没有访问本地资源。

2 个答案:

答案 0 :(得分:1)

例外是自我解释:

  

引起:java.security.AccessControlException:访问被拒绝   (java.util.PropertyPermission   com.sun.xml.internal.fastinfoset.parser.string-interning read)

SAAJ强制实施安全限制,当您在Eclipse中运行时没有问题但是从Applet运行时,您在沙箱中运行并且安全管理器停止流程

答案 1 :(得分:0)

绝对是签名问题。 http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

您可以使用该链接中的确切值进行尝试(在此示例中,唯一不同的是jar被称为sample.jar):

  1. 构建一个名为sample.jar的jar
  2. 运行:keytool -genkey -alias signFiles -keystore compstore -keypass kpi135 -dname“cn = jones”-storepass ab987c
  3. 运行:jarsigner -keystore compstore -storepass ab987c -keypass kpi135 -signedjar Ssample.jar sample.jar signFiles
  4. 我应该补充说,我知道这是解决方案,因为我与FuryComputers合作......我不知道为什么它是解决方案 - 其他人有什么想法?