开发者

Java Applet SOAPMessage causes "SAAJ0540: Error during saving a multipart message"

开发者 https://www.devze.com 2023-04-05 09:58 出处:网络
I have a problem which I have boiled down to this simple example. import java.applet.Applet; import javax.xml.soap.MessageFactory;

I have a problem which I have boiled down to this simple example.

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

    }
}

When I run this in eclipse (JDK 1.6.0_27) It works as I would expect, and I get the following output:

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.

When I run this in a browser as an applet I get the following error in the java console.

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

I am at a loss as to why this is occurring. I am simply creating en empty SOAPMessage and trying to write it to System.out. I am not accessing any local resources. I have done much searching on MessageImpl.saveChanges and FastInfosetReflection to no avail. Please give the example a try, and let me know if you have any ideas.

Respectfully, I ask that any answers that tell me to sign my Jar be accompanied by a reasonable explanation given the minimal example above that does not access local resources.


The exception is self explanatory:

Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission com.sun.xml.internal.fastinfoset.parser.string-interning read)

SAAJ imposes security restrictions and you have no problem when you run in Eclipse but when running from Applet, you run inside a sandbox and security manager stops the flow


Definitely a signing issue. http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

You can try it out with the exact values from that link (in this sample the only thing that is different is that the jar is called sample.jar):

  1. Build a jar called sample.jar
  2. Run: keytool -genkey -alias signFiles -keystore compstore -keypass kpi135 -dname "cn=jones" -storepass ab987c
  3. Run: jarsigner -keystore compstore -storepass ab987c -keypass kpi135 -signedjar Ssample.jar sample.jar signFiles

I should add that I know this is the solution since I work with FuryComputers ... I have no idea why it is the solution though - anyone else have any ideas?

0

精彩评论

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