|
Key
This line was removed.
This word was removed. This word was added.
This line was added.
|
Changes (1)
View Page History}
{code}
{code}
h1. Making the JSR-181 more configurable
Your JSR-181 implementation may need to access extra files you put in your service unit.
You may also want to add parameters or properties to your service unit.
Additional properties should be put in a distinct file, at the root of the service unit.
These resources can be accessed by using the class loader.
\\
Here is an example showing how to access a properties file located in the service unit.
{code}
package com.ebmwebsourcing;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
* Here is a sample JAX-WS implementation.
*/
@WebService( serviceName="Test2", targetNamespace="http://ebmwebsourcing.com", portName="TestPort2" )
public class Test2 {
/**
* @param key
* @return
*/
@WebMethod( operationName="getProperty" )
@WebResult( name="returnProperty" )
public String getProperty( @WebParam( name="key" ) String key ) {
String result = "Oops!";
URL url = getClass().getResource( "/my-properties.properties" );
Properties properties = new Properties();
try {
InputStream is = url.openStream();
properties.load( is );
result = properties.getProperty(key, "Invalid key");
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}
{code}
\\
Notice that in the studio, the resources must be added under the *src/main/jbi* directory.
This way, they will be put at the root of the service unit.