我在从 Web 服务获取真实消息时遇到了一些麻烦。
该访问过去可以正常工作,但是当我在一段时间后再次尝试对其进行测试时,AXIS 2 向我返回了 403 HTTP 错误。
org.apache.axis2.AxisFault: Transport error: 403 Error: Forbidden
我开始思考它可能是什么,所以我尝试通过 SOAP UI 访问它,它显示我的证书已过期。
这是我使用 SoapUI 收到的信息
The page requires a valid SSL client certificate
Your client certificate has expired or is not yet valid. A Secure Sockets Layer (SSL) client certificate is used for identifying you as a valid user of the resource.
消息还有更多内容,我只是将其缩短以使帖子尽可能小。
好的,还没有问题,我只需要找到一种方法来通知用户他的证书可能已经过期(或发生了任何其他错误),而不是只向他显示 403 错误。
我尝试使用 JAX-WS 访问它,我得到了相同的消息,我得到的只是,我尝试查看异常,看看那里是否有任何隐藏信息,但没有运气。我得到的是:
com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 403: Forbidden
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(Unknown Source)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(Unknown Source)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(Unknown Source)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
at com.sun.xml.internal.ws.client.Stub.process(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
谁能给我一些关于我可以做些什么来获得真实信息的指示?这是我用来访问它的代码
public static void main(String[] args){
try{
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.clearProperty("javax.net.ssl.keyStore");
System.clearProperty("javax.net.ssl.keyStorePassword");
System.clearProperty("javax.net.ssl.trustStore");
System.setProperty("javax.net.ssl.keyStore", "myCertificatePath");
System.setProperty("javax.net.ssl.keyStorePassword", "myCertificatePassword");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "cacertsFilePath");
NfeRecepcao2 nfe = new NfeRecepcao2();
NfeDadosMsg dados = new NfeDadosMsg();
dados.getContent().add(getFileContent("C:\\teste.xml"));
NfeCabecMsg cabec = new NfeCabecMsg();
cabec.setCUF("35");
cabec.setVersaoDados("2.00");
Holder<NfeCabecMsg> header = new Holder<NfeCabecMsg>(cabec);
NfeRecepcao2Soap12 proxy = nfe.getNfeRecepcao2Soap12();
NfeRecepcaoLote2Result result = proxy.nfeRecepcaoLote2(dados, header);
for (Object o : result.getContent()){
System.out.println(o);
}
} catch (Exception e){
e.printStackTrace();
}
getFileContent只打开一个文件并从它的内容生成一个字符串。
这里的任何指示都会有很大帮助。谢谢大家