Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在CXF中,有没有一种方法可以通过编程方式对客户机的配置进行编程?_Java_Spring_Web Services_Cxf - Fatal编程技术网

Java 在CXF中,有没有一种方法可以通过编程方式对客户机的配置进行编程?

Java 在CXF中,有没有一种方法可以通过编程方式对客户机的配置进行编程?,java,spring,web-services,cxf,Java,Spring,Web Services,Cxf,我有一个包含web服务和web服务客户端的项目。我希望在不影响web服务的情况下配置web服务客户端。我该怎么做 我想配置这个客户机,以便它可以设置这些值:是的,spring配置完全是可选的,最终它主要被翻译成“java类和协同配置”。通常,它提供spring和编程配置,在您的情况下,有一个特别的段落应该给您一个起点: 请参阅有关如何使用HttpConductor TLS属性的条目 可以从代码中进行设置 由于通常不鼓励只使用URL的答案,我将“垃圾邮件”此答案副本,为可能需要它的人粘贴整个客户端

我有一个包含web服务和web服务客户端的项目。我希望在不影响web服务的情况下配置web服务客户端。我该怎么做


我想配置这个客户机,以便它可以设置这些值:

是的,spring配置完全是可选的,最终它主要被翻译成“java类和协同配置”。通常,它提供spring和编程配置,在您的情况下,有一个特别的段落应该给您一个起点:

请参阅有关如何使用HttpConductor TLS属性的条目 可以从代码中进行设置

由于通常不鼓励只使用URL的答案,我将“垃圾邮件”此答案副本,为可能需要它的人粘贴整个客户端代码:

  public class Client {
       private static void configureSSLOnTheClient(Object c) {
          org.apache.cxf.endpoint.Client client = ClientProxy.getClient(c);
          HTTPConduit httpConduit = (HTTPConduit) client.getConduit();

          try {
              TLSClientParameters tlsParams = new TLSClientParameters();
              tlsParams.setDisableCNCheck(true);

              KeyStore keyStore = KeyStore.getInstance("JKS");
              String trustpass = "password";

              File truststore = new File("certs\\truststore.jks");
              keyStore.load(new FileInputStream(truststore), trustpass.toCharArray());
              TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
              trustFactory.init(keyStore);
              TrustManager[] tm = trustFactory.getTrustManagers();
              tlsParams.setTrustManagers(tm);

              truststore = new File("certs\\wibble.jks");
              keyStore.load(new FileInputStream(truststore), trustpass.toCharArray());
              KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
              keyFactory.init(keyStore, trustpass.toCharArray());
              KeyManager[] km = keyFactory.getKeyManagers();
              tlsParams.setKeyManagers(km);

              FiltersType filter = new FiltersType();
              filter.getInclude().add(".*_EXPORT_.*");
              filter.getInclude().add(".*_EXPORT1024_.*");
              filter.getInclude().add(".*_WITH_DES_.*");
              filter.getInclude().add(".*_WITH_NULL_.*");
              filter.getExclude().add(".*_DH_anon_.*");
              tlsParams.setCipherSuitesFilter(filter);

              httpConduit.setTlsClientParameters(tlsParams);
          } catch (KeyStoreException kse) {
              System.out.println("Security configuration failed with the following: " + kse.getCause());
          } catch (NoSuchAlgorithmException nsa) {
              System.out.println("Security configuration failed with the following: " + nsa.getCause());
          } catch (FileNotFoundException fnfe) {
              System.out.println("Security configuration failed with the following: " + fnfe.getCause());
          } catch (UnrecoverableKeyException uke) {
              System.out.println("Security configuration failed with the following: " + uke.getCause());
          } catch (CertificateException ce) {
              System.out.println("Security configuration failed with the following: " + ce.getCause());
          } catch (GeneralSecurityException gse) {
              System.out.println("Security configuration failed with the following: " + gse.getCause());
          } catch (IOException ioe) {
              System.out.println("Security configuration failed with the following: " + ioe.getCause());
          }
      }

      public static void main(String args[]) {
          System.out.println("The client's security configuration will be done programatically.");
          System.out.println();
          String address = "https://localhost:9001/SoapContext/SoapPort";
          JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
          proxyFactory.setServiceClass(Greeter.class);
          proxyFactory.setAddress(address);

          Greeter client = (Greeter) proxyFactory.create();
          configureSSLOnTheClient(client);

          System.out.println("Invoking greetMe...");
          try {
              String resp = client.greetMe(System.getProperty("user.name"));
              System.out.println("Server responded with: " + resp);
              System.out.println();

          } catch (Exception e) {
              System.out.println("Invocation failed with the following: " + e.getCause());
              System.out.println();
          }

      }
  }

问题是我的代码处于战争状态,没有
main
。我的代码是一个
javax.xml.ws.Service
,客户端调用是通过从中获取端口来完成的。该端口是的一个实例。我真的不知道如何从中获取
客户端
,实际上我可以说
ClientProxy.getClient(port)
。我会让你知道这是怎么回事,伙计,很高兴我能帮上忙