Jetty Web服务-不支持基于https协议的地址 [英] Jetty Webservice - https protocol based address is not supported

查看:223
本文介绍了Jetty Web服务-不支持基于https协议的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用7.5.1版本的码头.

I am using jetty version 7.5.1 .

我的Web服务可以在"http://..."端点上正常工作,但是当我将其更改为"http s ://..."时,出现了问题.

My webservice works fine with a "http://..." endpoint, but when I change it to "https://..." things go wrong.

Endpoint e = Endpoint.create(webservice);
e.publish("https://localhost:" +  serverPort + "/ws/mywebservice);

我收到以下错误消息: 不支持基于https协议的地址".

I get the following error message: "https protocol based address is not supported".

我尝试使用SslChannelConnectorSelectChannelConnector和两者的组合.

I've tried using an SslChannelConnector, a SelectChannelConnector and the combination of both.

  Connector connector = new SelectChannelConnector();
  connector.setPort(59180);

  SslContextFactory factory = new SslContextFactory();
  factory.setKeyStore("keystore");
  factory.setKeyStorePassword("password");
  factory.setKeyManagerPassword("password");
  factory.setTrustStore("keystore");
  factory.setTrustStorePassword("password");

  SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(factory);
  sslConnector.setPort(443);
  sslConnector.setMaxIdleTime(30000);

  server.setConnectors(new Connector[]{connector, sslConnector});

我还尝试了修改发布路径中的端口.但是没有成功.

I also tried modifying the port in the publish path. But without success.

可能是我的密钥库文件的创建出错了吗? 即使我输入了错误的密码,它也会显示不同的错误消息,说明我的密码是错误的.

Could it be that something went wrong with the creation of my keystore file? Even I put the wrong password though, it does show a different error message, explaining that my password is wrong.

我的选项用完了.有什么想法吗?

My options are running out. Any ideas?

Servlet现在可以在HTTPS上正常工作.但是 webservices不能.我可能会以错误的方式发布它吗?

Servlets work fine with HTTPS now. But the webservices are not. Am I maybe publishing it the wrong way ?

推荐答案

我在各种论坛上发现了具有类似问题的多个主题.但是从来没有找到解决方案.我想为未来的受害者写下我的解决方案:

I found several threads on various forums with similar problems. But never found a solution. I would like to write down my solution for future victims:

publish方法仅接受http协议.即使您发布的是https,它仍应为"http://...".另一方面,您应该使用SSL连接器的端口.

The publish method only accepts the http protocol. Even if you are publishing for https, this should still be "http://...". On the other hand, you should use the port of your SSL connector.

Endpoint e = Endpoint.create(webservice);
e.publish("http://localhost:443/ws/mywebservice);

使用任何其他协议,您将始终获得不支持基于xxx协议的地址" 异常.

Use any other protocol and you will always get the "xxx protocol based address is not supported" exception. See source code.

注释1:此时,Web服务已经可以正常使用了.但是,有一个讨论的重点:生成的wsdl文件(位于https://localhost:443/ws/mywebservice?wsdl)将引用http://...路径.您可能会争辩说wsdl文件是必需文件还是仅仅是文档.

Note 1: The webservice already works fine at this point. However there is a point of discussion: The generated wsdl file (at https://localhost:443/ws/mywebservice?wsdl) will reference the http://... path. You could argue if the wsdl file is a requirement or just documentation.

更正WSDL文件中的主机名并不难,但是替换协议则更难.最简单的解决方案可能是仅编辑wsdl文件并托管该文件,这当然不是很动态".

Correcting a hostname in a WSDL file is not that hard, but replacing the protocol is harder. The easiest solution is probably to just edit the wsdl file and host the file, which is not very "dynamic" of course.

或者,我通过创建一个替换地址的WsdlServlet 解决了该问题.另一方面,创建只修复一个字符的整个类确实很不好. :)

Alternatively, I solved it by creating a WsdlServlet which replaces the address. On the other hand, it does feel bad to create an entire class just to fix 1 character. :)

注释2:此码头版本中的另一个错误是身份验证.没有任何身份验证就无法提供Web服务.关闭所有可能的身份验证后,您将获得的最好的收获:您仍然必须使用抢先身份验证"并输入随机的用户名和密码.

Note 2: Another bug in this jetty release, is the authentication. It's impossible to offer the webservice without any authentication. The best thing you can get, after turning off all possible authentication: you will still have to use 'preemptive authentication' and enter a random username and password.

这篇关于Jetty Web服务-不支持基于https协议的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆