views:

155

answers:

3

I'm developing a test WS with JAX-WS and the demo works fine but if I try to move it in production there are a lot of occurences of the URL of my test enviroment on my code. For example:

com.mycompany.testserver.ws.writer.WriterInterface service = new com.mycompany.testserver.ws.writer.WriterInterface();

QName portQName = new QName("http://testserver.mycompany.com/ws/writer.php", "WriterInterfacePort");

String req = "SOME_XML_HERE";

try { // Call Web Service Operation

    Dispatch<Source> sourceDispatch = null;
    sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
    Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
} catch (Exception ex) [
//do stuff here
}

What is the best practice for moving such an app?

+2  A: 

Read the connection URL from a configuration file. You might also want to have a strongly-typed configuration object that will cache the value so that it only needs to be read once. Then when you move your app from test to production, you only need to update the configuration file.

tvanfosson
+1  A: 

The most common practice is to store the URL's in config files rather than hardcoded, and have separate configurations for test and production.

Introducing an integration broker or service registry tends to be overkill.

Pontus Gagge
A: 

You should really avoid hard coding URL's into code. There are a variety of ways this could be avoided. Even if you had no config file functionality available you should at the very least be storing this data in a string at the top of each class where its declared.

No need to tell you (But I guess I am) you are now encountering the reason as to why you never hard code URL's / configuration data.

steve