{"id":661,"date":"2009-03-02T20:45:24","date_gmt":"2009-03-03T01:45:24","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=661"},"modified":"2011-09-15T13:25:22","modified_gmt":"2011-09-15T18:25:22","slug":"jax-ws-https-hostname-wrong-should-be-exception","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=661","title":{"rendered":"JAX-WS &#8220;HTTPS hostname wrong: should be &lt;mysite.com&gt;&#8221; Exception"},"content":{"rendered":"<p>If the &#8220;cn&#8221; of the web services server certificate does not match its host name, you&#8217;ll get:<br \/>\n<strong>com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.io.IOException: HTTPS hostname wrong:  should be &lt;mysite.com&gt;<\/strong><\/p>\n<p>You can implement your own javax.net.ssl.HostnameVerifier to suppress it. Important, remember to remove the codes for production!<\/p>\n<pre lang=\"java\">\r\nimport javax.net.ssl.HostnameVerifier;\r\nimport javax.net.ssl.SSLSession;\r\n\r\npublic class TestHostnameVerifier implements HostnameVerifier {\r\n\tpublic boolean verify(String arg0, SSLSession arg1) {\r\n\t\treturn true;\r\n\t}\r\n}<\/pre>\n<p>In client code:<\/p>\n<pre lang=\"java\">\r\n\/\/ Make sure java.protocol.handler.pkgs is set to \"javax.net.ssl\"\r\n\/\/System.setProperty( \"java.protocol.handler.pkgs\", \"com.sun.net.ssl.internal.www.protocol\" );\r\nSystem.setProperty( \"java.protocol.handler.pkgs\", \"javax.net.ssl\" );\r\nSecurity.addProvider( new com.sun.net.ssl.internal.ssl.Provider() );\r\n\r\nHelloService service = new HelloService();\r\nHelloPort proxy = service.getHelloPort();\r\n \r\nMap<String, Object> ctxt = ((BindingProvider)proxy ).getRequestContext();\r\nctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);\r\nctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, \"https:\/\/new\/endpointaddress\");\r\nctxt.put(JAXWSProperties.HOSTNAME_VERIFIER, new TestHostnameVerifier());\r\n\r\nproxy.sayHello(\"Hello World!\");\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If the &#8220;cn&#8221; of the web services server certificate does not match its host name, you&#8217;ll get: com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.io.IOException: HTTPS hostname wrong: should be &lt;mysite.com&gt; You can implement your own javax.net.ssl.HostnameVerifier to suppress it. Important, remember to &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=661\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[41,55],"tags":[],"class_list":["post-661","post","type-post","status-publish","format-standard","hentry","category-jax-ws","category-ssl"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-aF","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=661"}],"version-history":[{"count":8,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/661\/revisions"}],"predecessor-version":[{"id":3406,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/661\/revisions\/3406"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}