【问题标题】:How do I get the real Webservice response, instead of 403 error?如何获得真正的 Web 服务响应,而不是 403 错误?
【发布时间】:2012-12-21 10:40:46
【问题描述】:

我在从网络服务获取真实消息时遇到了一些麻烦。

该访问过去可以正常工作,但是当我在一段时间后再次尝试对其进行测试时,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 只打开一个文件并从它的内容生成一个字符串。

这里的任何指示都会有很大帮助。先谢谢大家了

【问题讨论】:

    标签: java jax-ws http-status-code-403


    【解决方案1】:

    查看收到的响应的一种方法是记录客户端发送和接收的soap请求和响应。

    如果您使用的是 JAX-WS,那么

    System.setProperty("Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", true);
    

    如果您使用的是 JAX-WS RI 客户端,那么

    System.setProperty("Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", true);
    

    JAX-WS RI 库作为标准包含在 JDK(Java 6 中),然后 Sun 不得不重命名属性名称以包含“内部”。因此,如果您使用 JDK 附带的 JAX-WS RI,那么您必须确保将 internal 添加到属性名称中。

    【讨论】:

      猜你喜欢
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 2021-03-25
      • 2019-10-07
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 2021-03-19
      相关资源
      最近更新 更多