How to change webservice url endpoint?
IMO, the provider is telling you to change the service endpoint (i.e. where to reach the web service), not the client endpoint (I don't understand what this could be). To change the service endpoint, you basically have two options.
Use the Binding Provider to set the endpoint URL
The first option is to change the BindingProvider.ENDPOINT_ADDRESS_PROPERTY
property value of the BindingProvider
(every proxy implements javax.xml.ws.BindingProvider
interface):
...
EchoService service = new EchoService();
Echo port = service.getEchoPort();
/* Set NEW Endpoint Location */
String endpointURL = "http://NEW_ENDPOINT_URL";
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
System.out.println("Server said: " + echo.echo(args[0]));
...
The drawback is that this only works when the original WSDL is still accessible. Not recommended.
Use the WSDL to get the endpoint URL
The second option is to get the endpoint URL from the WSDL.
...
URL newEndpoint = new URL("NEW_ENDPOINT_URL");
QName qname = new QName("http://ws.mycompany.tld","EchoService");
EchoService service = new EchoService(newEndpoint, qname);
Echo port = service.getEchoPort();
System.out.println("Server said: " + echo.echo(args[0]));
...
JAXWS — how to change the endpoint address
Solved the problem using Apache CXF.
With just two lines of code! Here is the snippet:
URL url_wsdl = new URL("http://myserver/myservice?wsdl");
Service service = Service.create(url_wsdl, new QName("http://myaddress...", "ServiceName"));
return service.getPort(MyJAXWSPortClass.class);
Change WebService endpoint address at run time
You can do it two ways:
1) Cast port
to BindingProvider
and specify BindingProvider.ENDPOINT_ADDRESS_PROPERTY
property
MyService service = new MyService();
MyPort port = service....
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://New.Endpoint/service");
2) You can call the generated service constructor which takes WSDL URL as parameter.
QName qname = new QName("http://serviceuri/", "service");
String wsdl = "http://New.Endpoint/service?wsdl";
MyServiec service = new MyServiec(new URL(wsdl), qname);
MyPort port = check...;
overriding or setting web service endpoint at runtime for code generated with wsimport
Your client can set the end-point in the service "port" at runtime via the BindingProvider interface.
Consider the JAX-WS client in this JAX-WS tutorial. Another way to write this code would be:
HelloService service = new HelloService();
Hello port = service.getHelloPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://foo:8086/HelloWhatever");
String response = port.sayHello(name);
Caveat: I haven't downloaded the tutorial code and tested this code against it.
Change exposed WebService URL in Wildfly
I would also look at defining the context-root in a jboss-webservices.xml file. This way you can avoid modifying your web.xml which will break your deployment in GlassFish.
<webservices>
<context-root>ws</context-root>
</webservices>
Jax-ws with https url ends up as http
One cause could be if the WSDL referenced an http
URL.
new MyServiceInterface(new
URL("https://acme.com/services/MyService.svc?wsdl"))
.getMyPort().test();
I'd suggest downloading https://acme.com/services/MyService.svc?wsdl
and looking at the <address>
or endpoint within the <service>
. If it looks like this:
<soap:address location="http://acme.com/services/MyService.svc"/>
That could account for what you are seeing in the javax.xml.ws.service.endpoint.address
.
If that's the case and you cannot control/fix the remote WSDL, you may need to programmatically override the endpoint:
MyServicePort myPort = new MyServiceInterface(new URL("https://acme.com/services/MyService.svc?wsdl")).getMyPort();
// set endpoint to use https
String endpointURL = "https://acme.com/services/MyService.svc";
BindingProvider bp = (BindingProvider) myPort;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
myPort.test();
Related Topics
Sort Arrays of Primitive Types in Descending Order
Displaying a Histogram of Image Data
Jackson Enum Serializing and Deserializer
Different War Files, Shared Resources
Best Way to Implement View.Onclicklistener in Android
How to Specify the Jdk Version in Android Studio
How to Connect Android with MySQL Using MySQL Jdbc Driver
Android Change Material Elevation Shadow Color
Is Default No-Args Constructor Mandatory for Gson
Java: Why Do You Need to Specify an 'F' in a Float Literal
Selenium Webdriver - Getcssvalue() Method
Java.Lang.Illegalmonitorstateexception: Object Not Locked by Thread Before Wait()
Google Firebase Check If Child Exists
Java - Convert String to Valid Uri Object
What Is the Easiest Way to Get the Current Day of the Week in Android