Vous n'êtes pas connecté. Connexion
|
|
Weblogic / Java EE6De $1Table des matièresWeblogic / Java EE6IntroductionThis page is a good reminder for the Java EE6 developper that plan to use Eclipse indigo with weblogic 12c or greater for developping Servlets/JSPs/EJB/JMS applications. Installing a JMS queue on WebLogicGood guide on how to setup a JMS queue here : http://blog.touret.info/blog/index.php/post/2011/09/22/Mise-en-oeuvre-d-une-file-d-attente-JMS-sur-Weblogic-10.3 (in french) Writing a remote client standalone for an EJBYou must have at least one EJB that implements a remote interface. Example : package sessions;import javax.ejb.LocalBean;import javax.ejb.Stateless;/*** Session Bean implementation class Test*/@Stateless@LocalBeanpublic class DemoSessionEJBRemote implements TestRemote { public DemoSessionEJBRemote() { // TODO Auto-generated constructor stub } public String helloWorld() { return "hello world !"; }} And here is the remote interface (located in the Client project that is automatically created when we do an EAR project): package sessions;import javax.ejb.Remote;@Remotepublic interface TestRemote { public String helloWorld();} The client project is just a Java project, but you must add two things so that it compiles and run:
Then you should have such a source code for the standalone client: package sessions;import javax.ejb.Remote;@Remotepublic interface TestRemote { public String helloWorld();}package client;import java.util.Hashtable;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import sessions.DemoSessionEJB;import sessions.TestRemote;public class StandAloneClient { private static String INITIAL_CONTEXT_NAME = "weblogic.jndi.WLInitialContextFactory"; // CHANGE TO YOUR HOST PORTS. These values should be ok if weblogic is running on your own machine. private static String PROVIDER_URL = "t3://localhost:7001"; // CHECK THIS NAME IN WEBLOGIC ADMIN CONSOLE, JNDI Tree for your server ! private static String JNDI_NAME = "java:global.DemoEAR.DemoEJB.DemoSessionEJBRemote!sessions.TestRemote"; public static void main(String[] args) throws Exception { Context ctx = getInitialContext(); // USE INTERFACE HERE, Not the EJB class ! TestRemote helloEJB = (TestRemote) ctx.lookup(JNDI_NAME); System.out.println(helloEJB.helloWorld()); } private static Context getInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_NAME); env.put(Context.PROVIDER_URL, PROVIDER_URL); return new InitialContext(env); }} Writing a client for a weblogic queueHere is an example of a client that sends TextMessages to a MessageDriven bean. It is recommended to double check the JNDI names of the JMS connexion factory and of the JMS destination.
Example MDB:
|
Powered by MindTouch Deki Open Source Edition v.8.08 |