有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javacom。太阳xml。ws。过错ServerSOAPFaultException:客户端从服务器接收到SOAP错误:未找到WSSecurity标头

我研究了在remote server over SSL上使用web服务的web服务客户机。 首先,我是web服务新手,之前我创建了基本web服务,它可以在localhost上运行。这么复杂的事情,我需要帮助

WSDL file,KeyStore fileTrustStore file都给了我。我使用一台可以访问web服务端点的计算机 我为这个web服务创建所做的

  • 我从wsdl file生成了带有wsimport tool的java类
  • 然后我创建了一个Dynamic Web Project in Eclipse并导入这些java类
  • 我将keystore,truststore and wsdl files复制到项目目录中
  • 在类的main方法中,我编写以下代码

    我在运行时调用web服务方法的代码行中遇到以下异常

    com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: No WS-     Security header found exception
    

    我尝试访问以下web服务的代码:

代码

        My_Service service=new My_Service();
        MyServicePort servicePort=service.getServicePort();

        BindingProvider bp = (BindingProvider)servicePort;

        // In case of 1-Way SSL, only the Truststore is necessary
        TrustManagerFactory tmf= TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init((KeyStore)null);
        TrustManager[] trustMgr= tmf.getTrustManagers();
        KeyStore trustStore = KeyStore.getInstance("JKS");
        FileInputStream truststoreFile = new FileInputStream("truststore.jks");
        trustStore.load(truststoreFile, "truststore_password".toCharArray());
        truststoreFile.close();
        tmf.init(trustStore);

        // In case of 2-Way SSL, keystore and  truststore are necessary
        KeyManagerFactory kmf= KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init((KeyStore)null,null);
        KeyManager[] keyMgr = kmf.getKeyManagers();
        KeyStore keyStore = KeyStore.getInstance("JKS");
        FileInputStream keystoreFile = new FileInputStream("keystore.jks");
        keyStore.load(keystoreFile, "keystore_password".toCharArray()); 
                keystoreFile.close();
        kmf.init(keyStore, "keystore_password".toCharArray());

        SSLContext context = SSLContext.getInstance("SSL");//"SSLv3"
        context.init(keyMgr, trustMgr, null);
        //context.getSocketFactory();
        bp.getRequestContext().put(JAXWSProperties.SSL_SOCKET_FACTORY, context.getSocketFactory());
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,"username");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,"password");
                bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://xxxxxxx....");

**ERROR IN THIS LINE** //List<MyEntity> list= servicePort.getEntityList();
        for(MyEntity e:list){
            System.out.println(e.getName());
        }

如何解决这个问题?此外,任何关于创建这样一个web服务客户端的建议都将不胜感激。 提前谢谢


共 (0) 个答案