Is there any function to get the hostname of a OSB server at runtime?

1.8k Views Asked by At

I need to fetch the OSB server hostname and use it as a qualifier to fecth the value from DVM, as we fetch the BPEL instance URL using ora:getProcessURL() .

example :

If i am able to get the server url as : http://dev-osb-clientname.com

I will extract the "dev" from there and i will send "dev" to DVM as a qualifier.

4

There are 4 best solutions below

0
On

Two obvious ways come to mind:

  1. customise a variable at deploy time
  2. call out to Java
0
On

You can make an Assign using this XQuery:

let $hostVar := fn-bea:execute-sql(
"jdbc/MetroIntegrationDS", 
"host", 
"select decode (sys_context('USERENV','SERVER_HOST'),'DB-SERVER-PROD' ,'PROD', 
  'DB-SERVER-DEV', 'DEV' ) myhost from dual")
return $hostVar//*:MYHOST/text()

in you targer Variable you'll get "PROD" or "DEV" according to the Machine name of OSB's DB.

0
On

In an assign activity in the pipeline you could just get the variable:

$inbound/ctx:transport/ctx:uri

this would surely tell you the calling URL?

0
On

We also faced this issue and sorted using java code and using java callout for the same.

You can consider below dummy fragment and take idea:

    package OsbServerName;

import java.io.Serializable;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.Set;

import javax.naming.Context;
import javax.security.auth.Subject;

import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.runtime.ServerRuntimeMBean;

/*
* Get OSB Server or Host Name

 */
public final class OsbServerName implements Serializable {

                private static final long serialVersionUID = 4055048819845029320L;

                private final static String serverName = findServerNameURL();


                public static final void main(String[] arg) {

                }

                /**
                * Return the server name
                * 
                 * @return
                */
                public static final String getServerNameURL() {
                                return serverName;
                }

                /**
                * find OSB/WLS server name
                * 
                 * @return
                */
                private final static String findServerNameURL() {
                                try {
                                                return findServerRuntimeMBean().getDefaultURL();
                                } catch (Exception e) {
                                                e.printStackTrace();
                                }
                                return "";
                }

                /**
                * lookup {@link ServerRuntimeMBean}
                * 
                 * @return
                * @throws Exception
                */
                @SuppressWarnings("deprecation")
                private static final ServerRuntimeMBean findServerRuntimeMBean() throws Exception {

                                // get username and password from service account
                                Subject subject = weblogic.security.Security.getCurrentSubject();

                                ServerRuntimeMBean serverRuntimeMBean = (ServerRuntimeMBean) weblogic.security.Security.runAs(subject, new PrivilegedAction<ServerRuntimeMBean>() {

                                                @Override
                                                public ServerRuntimeMBean run() {
                                                                try {
                                                                                weblogic.jndi.Environment env = new Environment();
                                                                                Context ctx = env.getInitialContext();
                                                                                // Get the Local MBeanHome
                                                                                MBeanHome home = (MBeanHome) ctx.lookup("weblogic.management.home.localhome");

                                                                                Set<?> s = home.getMBeansByType("ServerRuntime");
                                                                                Iterator<?> i = s.iterator();
                                                                                return (ServerRuntimeMBean) i.next();

                                                                } catch (Exception e) {
                                                                                e.printStackTrace();
                                                                }

                                                                return null;
                                                }
                                });

                                return serverRuntimeMBean;
                }
}