on 06-16-2014 10:51 PM
What's the best way for me to make the Java Scheduler tell me what server it is running on? My application logic requires this information to create valid links in E-mail messages. The environment changes, of course, as my application navigates from development to test to production, so obviously hard coding is not an option. I don't like the way I am doing it now, passing it from NWA Java Scheduler as a text string job parameter. Requiring the portal system administrator in each environment to type the server path when they schedule the job doesn't seem like a very elegant solution.
Any better ideas?
hi jennifer,
maybe these two code snippets will help you:
this will return the sap systemname:
public static String getSAPSystem(){
String system = null;
try{
system = System.getProperty("SAPSYSTEMNAME");
}catch(Exception e){
//some exception handling code....
}
return system;
}
and this one the actual host:
public static String getHost(){
String host = null;
try{
host = InetAddress.getLocalHost().getHostName();
}catch(Exception e){
//some exception handling code....
}
return host;
}
regards,
christian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your reply, I wrote some test statements using the java.lang.System class and the java.net.InetAddress class, but I never got to the point where I could construct a solid <protocol>://<servername>.<domain>:<port> string with them.
I could come close by making some educated assumptions based on what I know about our environment, but I need something bullet-proof because the system/basis admins don't always remember to clue in the developers when something changes server-side.
I've been scouring JavaDocs, and I may have missed something obvious, if someone knows about a class I may have overlooked I'd really appreciate a clue.
Thanks again for your valuable time!
hi jennifer,
the km api offers an url-service: http://help.sap.com/javadocs/NW73/SPS05/KMC/com/sapportals/wcm/service/urlgenerator/IURLGeneratorSer...
i hope with this you will find a solution.
try
{
IURLGeneratorService ug = (IURLGeneratorService)ResourceFactory.getInstance().getServiceFactory().getService(IServiceTypesConst.URLGENERATOR_SERVICE);
IHierarchicalUri hierarchical_uri = ug.getAbsoluteUri(PathKey.CONTENT_ACCESS_PATH);
//externalForm contains <protocol>://<host>:<port>
String externalForm = hierarchical_uri.getRoot().toExternalForm();
URI uri = URI.create(externalForm);
String protocol = uri.getScheme();
String host = uri.getHost();
int port = uri.getPort();
} catch (ResourceException e) {
//some exception handling
} catch (WcmException e) {
//some exception handling
} catch (Exception e){
//some exception handling
}
regards,
christian
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.