Created
March 21, 2013 02:25
-
-
Save dagvadorj/5210245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.ubdynamics.architect.web; | |
import java.util.Hashtable; | |
import javax.naming.CommunicationException; | |
import javax.naming.Context; | |
import javax.naming.InitialContext; | |
import javax.naming.NamingException; | |
/** | |
* @usage | |
* EntityService entityService = | |
* (EntityService)EJBUtils.lookup("t3://127.0.0.1:7101", "EntityService#com.eatnjoy.service.EntityService"); | |
*/ | |
public class EJBUtils { | |
public static Object lookup(String url, String name) { | |
try { | |
final Context context = getInitialContext(url); | |
return context.lookup(name); | |
} catch (CommunicationException e) { | |
System.out.println(e.getClass().getName()); | |
System.out.println(e.getRootCause().getLocalizedMessage()); | |
System.out.println("\n*** A CommunicationException was raised. This typically\n*** occurs when the target WebLogic server is not running.\n"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
private static Context getInitialContext(String url) throws NamingException { | |
Hashtable env = new Hashtable(); | |
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); | |
env.put(Context.PROVIDER_URL, url); | |
return new InitialContext(env); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment