Thanks, Ruchith. That solves my problem. I simply copied the code from the test 
program. But now I got the following fault:

Exception in thread "main" AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: org.xml.sax.SAXException: SimpleDeserializer encountered a child 
element, which is NOT expected, in something it was trying to deserialize.
 faultActor: 
 faultNode: 
 faultDetail: 
        {http://xml.apache.org/axis/}hostname:wcars2g7.ca.nortel.com

org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which 
is NOT expected, in something it was trying to deserialize.
        at 
org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
        at 
org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
        at 
org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown 
Source)
        at 
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
        at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
 Source)
        at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
        at 
org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
        at 
org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:1870)

After I encrypted the document and converted it into SOAP message, I passed the 
SOAP message to the org.apache.axis.client.Call.invoke, then I got the above 
soap fault. 

I am wondering after I encrypted the document, if I need to register the 
related serializer/deserializer?

Lule
-----Original Message-----
From: Ruchith Fernando [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 23, 2007 10:53 PM
To: Chen, Lule (CAR:2Y83)
Cc: [EMAIL PROTECTED]; José Ferreiro; [email protected]
Subject: Re: Null pointer exception when calling WSSecEncrypt.prepare()


Hi,

The problem is in this line : 
encrypt.setSymmetricEncAlgorithm("WSConstants.TRIPLE_DES");

Please change it to : 
encrypt.setSymmetricEncAlgorithm(org.apache.ws.security.WSConstants.TRIPLE_DES);

Also you can change :
encrypt.setUserInfo("wss4jcert", "security");
to
encrypt.setUserInfo("wss4jcert");
since for encryption you just need to have the public key. We do not require 
the key password to retrieve the public key.

Thanks,
Ruchith

On 2/24/07, Lule Chen <[EMAIL PROTECTED]> wrote:
>
>
>
> Hi, dims:
>
> I adopted the code in TestWSSecurityNew15.java that encrypts the soap 
> body, but I got the null pointer exception as the following:
>
> Exception in thread "main" java.lang.NullPointerException
>         at
> org.apache.ws.security.message.WSSecEncrypt.prepare(WSSecEncrypt.java:197)
>         at
> com.nortel.cdma.axis.Client.NEServiceClient.main(NEServiceClient.java:
> 240)
>
> I looked at the line of code in WSSecEncrypt.java, it seems failed at
>
>                 this.symmetricKey = keyGen.generateKey();
>
> I suspect that keyGen is null. My code snips are as the following:
>
>     static final WSSecurityEngine secEngine = new WSSecurityEngine();
>     static final Crypto crypto = 
> CryptoFactory.getInstance("cryptoSKI.properties");
>
> ...
>
>         SOAPEnvelope env = new SOAPEnvelope(new 
> ByteArrayInputStream(byteBuf));
>
>         WSSecEncrypt encrypt = new WSSecEncrypt();
>         encrypt.setUserInfo("wss4jcert", "security");
>
> encrypt.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
>
> encrypt.setSymmetricEncAlgorithm("WSConstants.TRIPLE_DES");
>
>         Document doc = env.getAsDocument();
>
>         WSSecHeader secHeader = new WSSecHeader();
>         secHeader.insertSecurityHeader(doc);
>         encrypt.prepare(doc, crypto);
>
> ...
>
> Do you have any idea whats wrong of my code?
>
> Thanks,
>
>
> Lule
>
>


-- 
www.ruchith.org
www.wso2.org

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to