Configure a web service URL for a client from a properties file using Netbeans 7 and Axis2

I am new to webservice development. I am using Netbeans 7.0 with the Axis2 plugin and Tomcat 7.

I created one project for server components, where I define web methods, and then created another project for client components. The client was created in Netbeans by selecting New โ†’ Webservice Client.

When you select New -> Webservice Client in Netbeans, it immediately requests the WSDL URL. So of course, I gave the WSDL URL from my local Tomcat installation. But what about when I distribute this as a real application? Users will not point their clients to http: // localhost: 8080 / axis2 / services / ? Wsdl. I mean that when a client starts from the IDE, everything works fine, but when I distribute it (this application for managing labor by the way you start / run one or more clients and a time card is written to the central database), each the client should be able to point to the web service URL of any production server to which it should connect.

I would like to save the webservice URL in the properties file, but I donโ€™t know what to do everything programmatically on the client in order to call the URL loaded from the properties file.

In my client dist dist folder, if I open the JAR that the netbeans created using WinZip, I see the name of the file is jax-ws-catalog.xml, which has a URL (which is localhost). I assume this is a URL that is used at runtime.

So what is the correct way to do this? I searched around, but what I found in a Google search usually shows that webservice calls run in a completely different way than the automatically generated code that Netbeans combines, and I would like some information regarding how Netbeans creates the webservice client, so I donโ€™t make changes to overwrite them in the IDE.

Thanks! Sorry for the long explanation.

-Jeet

+4
source share
3 answers

The answer was: How do I change the endpoint of a web service URL?

NetBeans uses simple JAX-WS to generate client code, so the answer above should work for you. You just need to add the code to get the endpoint URL from the properties file.

+2
source

I actually understood it differently, and this is probably characteristic of how Netbeans does something. Shott85's answer is also good, but I think it is more specific to the way Netbeans code is generated.

So, I have a project in which all web methods are under the name SimplyLaborServer, and a project in which there is a webservice client named SimplyLaborClient.

In Netbeans, in the SimplyLaborClient project in the โ€œGenerated Sources (jax-ws)โ€ node, they have a SimplyLaborServer.java file that has a class that extends Service. It has a private URL that is hardcoded to my local server address as follows:

url = new URL("http://localhost:8080/axis2/services/SimplyLaborServer?wsdl"); 

And in the default constructor, it uses this URL. But it also provides a constructor as follows, where I can specify a url ...

 public SimplyLaborServer(URL wsdlLocation) { super(wsdlLocation, SIMPLYLABORSERVER_QNAME); } 

So, when I have an auto-generated method that looks like this in my client ...

 private static String testConnection() { simplylaborclient.SimplyLaborServer service = new simplylaborclient.SimplyLaborServer(); simplylaborclient.SimplyLaborServerPortType port = service.getSimplyLaborServerHttpSoap12Endpoint(); return port.testConnection(); } 

I can simply load the Properties object that has the endpoint URL and change one line to something like below, where the props is the Properties object that has the Url endpoint defined with the correct URL.

 simplylaborclient.SimplyLaborServer service = new simplylaborclient.SimplyLaborServer(new URL(props.getProperty("endpointUrl"))); 

My only concern is that these methods seem to be generated automatically when you drag them from the "web service links" node. I do not want them to be overwritten if I make additional changes on the server side.

So, I'm still open to feedback if this is the right thing here or not.

thanks

+4
source

You use the local ( http://localhost:8080/axis2/services ) WSDL only to create the required web service classes.

After completing your development, you can place your web service application anywhere on the Internet or on a local network.

After completing the development of the web service, you can deploy it locally and use the service to create the required client classes. When creating a client, you just need to create a URL object and pass the web service URL (hosted on it), as shown below.

 PropertyResourceBundle resoureceBundle = (PropertyResourceBundle) PropertyResourceBundle.getBundle('Property file name and path'); URL serviceURL = resoureceBundle. getString("Hosted_URL_Name"); ServiceClass service = new ServiceClass(serviceURL); ServicePort servicePort = new ServicePort(service); servicePort.getItems(); 

The NetBeans IDE will create many classes when creating a web service client automatically.

In the above code example, ServiceClass is the main class of the web service that is created initially using the local URL. The name and constructor options will vary depending on your web service, but you must pass the web service URL (recently hosted URL) as a string.

Then, with the service class, you can create a port object and access all the available web methods that you need.

+1
source

Source: https://habr.com/ru/post/1400096/


All Articles