cancel
Showing results for 
Search instead for 
Did you mean: 

Server awareness in Java Scheduler job - or - Where Am I?

Former Member
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

christian_santej
Active Participant
0 Kudos

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

Former Member
0 Kudos

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!

christian_santej
Active Participant
0 Kudos

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

Former Member
0 Kudos

This looks like exactly what I need, Christian! Thank you so much! Full points!

christian_santej
Active Participant
0 Kudos

that's good to hear - you're welcome.

Answers (0)