在CXF中,是否可以通过编程方式对客户端的配置进行编程?

丹尼尔·卡普兰

我有一个包含Web服务和Web服务客户端的项目。我想配置Web服务客户端而不影响Web服务。我怎样才能做到这一点?

我想配置此客户端,以便它可以设置以下值:https : //cwiki.apache.org/confluence/display/CXF20DOC/TLS+Configuration

摩菲克

是的,spring config纯粹是可选的,最后它主要被翻译成“ java类和配置”。通常,CXF文档同时提供Spring和Programmatic配置,在您的情况下,有一段特殊的段落应该为您提供一个起点:

请参阅此博客条目,了解如何通过代码设置HTTPConduit 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();
          }

      }
  }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Couchbase以编程方式配置客户端

来自分类Dev

CXF以编程方式从wsdl创建Web服务客户端

来自分类Dev

以编程方式创建WCF客户端

来自分类Dev

以编程方式创建WCF客户端

来自分类Dev

与许多客户端进行套接字编程中的客户端到客户端通信

来自分类Dev

是否可以通过编程方式在登录时设置显示配置?

来自分类Dev

是否可以通过编程方式对很多动画进行重新着色?

来自分类Dev

是否可以在Spark sql中以编程方式对列进行别名?

来自分类Dev

从客户端 JS 脚本以编程方式控制 Outlook

来自分类Dev

在Magento中通过编程方式删除客户

来自分类Dev

是否可以通过编程方式控制SVG

来自分类Dev

是否可以通过编程方式更改PieRenderer?

来自分类Dev

是否可以通过编程方式控制SVG

来自分类Dev

如何以编程方式在google Api客户端中打开/关闭活动识别

来自分类Dev

如何以编程方式在客户端中添加ssh主机密钥?

来自分类Dev

如何以编程方式在netTcpBindings中设置客户端回调地址

来自分类Dev

如何在WSO2 IS 5.10.0中为服务提供商以编程方式配置“允许在没有客户端机密的情况下进行身份验证”?

来自分类Dev

如何在python中运行多线程以进行多客户端套接字编程?

来自分类Dev

在Web编程Java中访问客户端的COM端口

来自分类Dev

Android中仅客户端编程的套接字

来自分类Dev

更改OpenVPN客户端,是否可以通过scp使用相同的服务器配置?

来自分类Dev

在Android中以编程方式启动电子邮件客户端并将电子邮件地址传递给客户端

来自分类Dev

是否可以通过编程方式进行“年度SharePoint计时器”作业?

来自分类Dev

客户端/服务器编程

来自分类Dev

即通过CXF推出编程配置码头

来自分类Dev

是否可以在gRPC中进行客户端到客户端的通信?

来自分类Dev

是否可以在NLog 4.6中以编程方式配置目标规则过滤器?

来自分类Dev

是否可以通过编程方式创建数据库视图?

来自分类Dev

是否可以通过编程方式连接到chromecast路由?

Related 相关文章

  1. 1

    Couchbase以编程方式配置客户端

  2. 2

    CXF以编程方式从wsdl创建Web服务客户端

  3. 3

    以编程方式创建WCF客户端

  4. 4

    以编程方式创建WCF客户端

  5. 5

    与许多客户端进行套接字编程中的客户端到客户端通信

  6. 6

    是否可以通过编程方式在登录时设置显示配置?

  7. 7

    是否可以通过编程方式对很多动画进行重新着色?

  8. 8

    是否可以在Spark sql中以编程方式对列进行别名?

  9. 9

    从客户端 JS 脚本以编程方式控制 Outlook

  10. 10

    在Magento中通过编程方式删除客户

  11. 11

    是否可以通过编程方式控制SVG

  12. 12

    是否可以通过编程方式更改PieRenderer?

  13. 13

    是否可以通过编程方式控制SVG

  14. 14

    如何以编程方式在google Api客户端中打开/关闭活动识别

  15. 15

    如何以编程方式在客户端中添加ssh主机密钥?

  16. 16

    如何以编程方式在netTcpBindings中设置客户端回调地址

  17. 17

    如何在WSO2 IS 5.10.0中为服务提供商以编程方式配置“允许在没有客户端机密的情况下进行身份验证”?

  18. 18

    如何在python中运行多线程以进行多客户端套接字编程?

  19. 19

    在Web编程Java中访问客户端的COM端口

  20. 20

    Android中仅客户端编程的套接字

  21. 21

    更改OpenVPN客户端,是否可以通过scp使用相同的服务器配置?

  22. 22

    在Android中以编程方式启动电子邮件客户端并将电子邮件地址传递给客户端

  23. 23

    是否可以通过编程方式进行“年度SharePoint计时器”作业?

  24. 24

    客户端/服务器编程

  25. 25

    即通过CXF推出编程配置码头

  26. 26

    是否可以在gRPC中进行客户端到客户端的通信?

  27. 27

    是否可以在NLog 4.6中以编程方式配置目标规则过滤器?

  28. 28

    是否可以通过编程方式创建数据库视图?

  29. 29

    是否可以通过编程方式连接到chromecast路由?

热门标签

归档