gpt4 book ai didi

java - 异常初始化器

转载 作者:行者123 更新时间:2023-11-28 23:57:42 27 4
gpt4 key购买 nike

我用 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

最佳答案

Can't find bundle for base name org.apache.ws.security.errors, locale en_US 您的记录器说您在 ResourceBundle 中遇到了区域设置问题使用

Locale locale = new Locale("en_US");

关于java - 异常初始化器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27767497/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com