/** Get the web service address for a given path
*/
public static String getServiceEndpointAddress(String uriScheme, String servicePath)
{
if (servicePath == null || servicePath.length() == 0)
throw new WSException("Service path cannot be null");
if (servicePath.endsWith("/*"))
servicePath = servicePath.substring(0, servicePath.length() - 2);
if (uriScheme == null)
uriScheme = "http";
SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
ServerConfig config = spiProvider.getSPI(ServerConfigFactory.class).getServerConfig();
String host = config.getWebServiceHost();
int port;
if ("https".equals(uriScheme))
{
port = config.getWebServiceSecurePort();
}
else
{
port = config.getWebServicePort();
}
// Reset port if using the default for the scheme.
if (("http".equals(uriScheme) && port == 80) || ("https".equals(uriScheme) && port == 443))
{
port = -1;
}
URL url = null;
try
{
if (port > -1)
{
url = new URL(uriScheme, host, port, servicePath);
}
else
{
url = new URL(uriScheme, host, servicePath);
}
return url.toExternalForm();
}
catch (MalformedURLException e)
{
throw new WSException("Malformed URL: uriScheme={" + uriScheme + "} host={" + host + "} port={" + port + "} servicePath={" + servicePath + "}", e);
}
}