cancel
Showing results for 
Search instead for 
Did you mean: 

XMLSignatureFactory fails in servlet, but works in a stand-alone program.

Former Member
0 Kudos

Hi all,

I am trying to write a servlet which will do XML signature et al. For the same, I am using JWSDP 2.0 (Java WebServices Developers Pack) on JRE 1.4.2_5. The servlet is hosted on SAP Netweaver 7 platform on Windows.

I am getting an exception:

javax.xml.crypto.NoSuchMechanismException: Cannot find DOM mechanism type

in the "XMLSignatureFactory.getInstance" line. I looked up in the documentation of XMLSignatureFactory and it says that the DOM mechanism should be provided by the provider argument - org.jcp.xml.dsig.internal.dom.XMLDSigRI in this case.

import javax.xml.crypto.dsig.XMLSignatureFactory; 

..
XMLSignatureFactory sigFactory = 
XMLSignatureFactory.getInstance("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI()); 
..

I tried the above 2 lines in a stand-alone Java client and they work without any issues.

I also used JWSDP 1.5 and the result was same.

This means that the servlet API or container for SAP is creating some issues to make this fail.

I tried to add the "org.jcp.xml.dsig.internal.dom.XMLDSigRI" in the jre/lib/security/java.security, but then the server0 does not start-up.

Any hints/pointers to resolve this issue?

Thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

This problem is solved. I am putting the reply here so that others who stumble upon this error can benefit.

Add the following line to explicitly include the provider before the getInstance

Security.addProvider(new org.jcp.xml.dsig.internal.dom.XMLDSigRI());

XMLSignatureFactory sigFactory = 
XMLSignatureFactory.getInstance("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());