2015-01-04 206 views
-1

我用Java編寫了一個動態Web項目。我部署到tomcat。 當我第一次打電話時沒有問題,它運行正常。 第二次調用時,發生下面的錯誤。 重新啓動tomcat後,它再次正常運行。異常初始化程序

我希望每個調用都能正常運行。 我該如何解決這個問題。

此致敬禮。

import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.InputStream; 
import java.io.StringReader; 
import java.io.StringWriter; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Properties; 

import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.soap.MessageFactory; 
import javax.xml.soap.SOAPConnection; 
import javax.xml.soap.SOAPConnectionFactory; 
import javax.xml.soap.SOAPMessage; 
import javax.xml.transform.Transformer; 
import javax.xml.transform.TransformerFactory; 
import javax.xml.transform.dom.DOMSource; 
import javax.xml.transform.stream.StreamResult; 

import org.apache.ws.security.WSConstants; 
import org.apache.ws.security.WSEncryptionPart; 
import org.apache.ws.security.components.crypto.Crypto; 
import org.apache.ws.security.components.crypto.PKCS11Device; 
import org.apache.ws.security.message.WSSecHeader; 
import org.apache.ws.security.message.WSSecSignature; 
import org.apache.ws.security.message.WSSecTimestamp; 
import org.w3c.dom.Document; 
import org.xml.sax.InputSource; 

public class ESign { 

    String pin; 
    String alias; 
    Crypto crypto; 
    Document signedDoc; 

    public String getBatchStatus(String par1, String par2, String par3) { 
     String sonuc = ""; 

     String soapReq = "<?xml version='1.0' encoding='UTF-8'?><soap:Envelope>" 
       + .................. 
       + "</soap:Envelope>"; 


     sign(soapReq, par1);  
    } 

    public void sign(String XML, String par1) { 
     try { 

      PKCS11Device dv = new PKCS11Device(); 
      dv.slot = Integer.toString(slot); 
      dv.drive = drive 


      ClassLoader classLoader = EnvImz_BeratIsl.class.getClassLoader(); 
      dv.loadProperties(getCryptoProperties(), classLoader); 

      crypto = dv; 

      signDocument(xmlToDoc(XML));  
      } 
     } catch (Exception e) { 

     } 
    } 
    public Document xmlToDoc(String XML) { 
     try { 
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
      dbf.setNamespaceAware(true); 
      DocumentBuilder db; 
      db = dbf.newDocumentBuilder(); 
      InputSource is = new InputSource(); 
      is.setCharacterStream(new StringReader(XML)); 
      Document doc = db.parse(is); 
      return doc; 
     } catch (Exception e) { 

     } 
    } 

    public void signDocument(Document doc) { 
     try { 
      WSSecSignature sig = new WSSecSignature(); 

      WSSecTimestamp time = new WSSecTimestamp(); 
      WSSecHeader header = new WSSecHeader(); 
      signedDoc = null; 

      header.setMustUnderstand(true); 
      sig.setSigCanonicalization("http://www.w3.org/2001/10/xml-exc-c14n#"); 
      sig.setDigestAlgo("http://www.w3.org/2001/04/xmlenc#sha256"); 
      sig.setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); 
      sig.setUserInfo(alias, pin); 
      sig.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); 
      header.insertSecurityHeader(doc); 

      doc = time.build(doc, header);      

      List<WSEncryptionPart> parts = new ArrayList<WSEncryptionPart>(); 
      WSEncryptionPart timestampPart = new WSEncryptionPart("Timestamp", 
        WSConstants.WSU_NS, ""); 
      WSEncryptionPart bodyPart = new WSEncryptionPart(
        WSConstants.ELEM_BODY, WSConstants.URI_SOAP11_ENV, ""); 
      parts.add(timestampPart); 
      parts.add(bodyPart); 
      sig.setParts(parts);   

      sig.build(doc, crypto, header); 
      signedDoc = doc; 

     } catch (Exception e) { 

     } 
    }   
} 

錯誤:

[ERROR] javax.xml.crypto.dsig.XMLSignatureException: java.security.InvalidKeyException: No installed provider supports this key: sun.security.pkcs11.P11Key$P11PrivateKey 
    [ERROR] Exception occurred while trying to invoke service method getBatchStatus 
    java.lang.reflect.InvocationTargetException 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
     at java.lang.reflect.Method.invoke(Unknown Source) 
     at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212) 
     at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117) 
     at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40) 
     at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114) 
     at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181) 
     at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172) 
     at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 
     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) 
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 
     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) 
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) 
     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) 
     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 
    Caused by: java.lang.ExceptionInInitializerError 
     at org.apache.ws.security.message.WSSecSignature.computeSignature(WSSecSignature.java:561) 
     at org.apache.ws.security.message.WSSecSignature.computeSignature(WSSecSignature.java:481) 
     at org.apache.ws.security.message.WSSecSignature.build(WSSecSignature.java:386) 
     at acron.EnvImz_BeratIsl.signDocument(EnvImz_BeratIsl.java:246) 
     at acron.EnvImz_BeratIsl.soap_imzala(EnvImz_BeratIsl.java:178) 
     at acron.EnvImz_BeratIsl.getBatchStatus(EnvImz_BeratIsl.java:288) 
     ... 29 more 
    Caused by: java.lang.RuntimeException: Can't find bundle for base name org.apache.ws.security.errors, locale en_US 
     at org.apache.ws.security.WSSecurityException.<clinit>(WSSecurityException.java:64) 
     ... 35 more 
    Caused by: java.util.MissingResourceException: Can't find bundle for base name org.apache.ws.security.errors, locale en_US 
     at java.util.ResourceBundle.throwMissingResourceException(Unknown Source) 
     at java.util.ResourceBundle.getBundleImpl(Unknown Source) 
     at java.util.ResourceBundle.getBundle(Unknown Source) 
     at org.apache.ws.security.WSSecurityException.<clinit>(WSSecurityException.java:62) 
     ... 35 more 
+0

你能分享一些代碼嗎?從'getBatchStatus'方法開始 – benji

回答

1

Can't find bundle for base name org.apache.ws.security.errors, locale en_US您的記錄上說你有問題,與語言環境ResourceBundle你必須使用

Locale locale = new Locale("en_US"); 
0

one似乎爲解決你的問題,來自Oracle支持論壇。