{"id":585,"date":"2009-02-19T23:13:25","date_gmt":"2009-02-20T04:13:25","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=585"},"modified":"2013-03-26T14:40:09","modified_gmt":"2013-03-26T19:40:09","slug":"set-endpoint-address-in-jax-ws-client","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=585","title":{"rendered":"Set Endpoint Address in JAX-WS Client"},"content":{"rendered":"<pre lang=\"java\">\r\ntry {\r\n  HelloService service = new HelloService (\r\n      new URL(\"http:\/\/new\/endpointaddress?wsdl\"), \r\n      new QName(\"http:\/\/example.org\/hello\", \"HelloService \"));\r\n} catch (MalformedURLException e) {\r\n  log.fatal(e);\r\n}\r\n\r\nHelloPort proxy = service.getHelloPort();\r\nproxy.sayHello(\"Hello World!\");\r\n<\/pre>\n<p>You can also use BindingProvider.ENDPOINT_ADDRESS_PROPERTY to override endpoint address. One caveat is the original endpoint used to generated the client proxy need to be up, otherwise you&#8217;ll get a nasty &#8220;java.net.ConnectException: Connection refused&#8221; exception when instantiating the Service at the first place.<\/p>\n<pre lang=\"java\">\r\n\/\/Create service and proxy from the generated Service class.\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, \"http:\/\/new\/endpointaddress\");\r\n\r\nproxy.sayHello(\"Hello World!\");\r\n<\/pre>\n<p>Use a local wsdl placed in classpath to create service and port, then set new end point address. This solves the issue that the original wsdl can NOT be be obtained from a live server and the live wsdl has a different service name, for example as a result of service virtualization.<\/p>\n<pre lang=\"java\">\r\nHelloService service = new HelloService (\r\n      this.getClass().getResource(\"originalHello.wsdl\"), \r\n      new QName(\"http:\/\/example.org\/hello\", \"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, \"http:\/\/new\/endpointaddress\");\r\n\r\nproxy.sayHello(\"Hello World!\");\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>try { HelloService service = new HelloService ( new URL(&#8220;http:\/\/new\/endpointaddress?wsdl&#8221;), new QName(&#8220;http:\/\/example.org\/hello&#8221;, &#8220;HelloService &#8220;)); } catch (MalformedURLException e) { log.fatal(e); } HelloPort proxy = service.getHelloPort(); proxy.sayHello(&#8220;Hello World!&#8221;); You can also use BindingProvider.ENDPOINT_ADDRESS_PROPERTY to override endpoint address. One caveat is the &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=585\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","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],"tags":[],"class_list":["post-585","post","type-post","status-publish","format-standard","hentry","category-jax-ws"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-9r","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/585","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=585"}],"version-history":[{"count":12,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions"}],"predecessor-version":[{"id":7587,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions\/7587"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}