Posts

Showing posts from September, 2008

Invoking EJB deployed on a remote machine

Invoking EJB deployed on a remote machine In case we are calling remote ejb( ejb deployed on remote machines), The JNDI lookup might lookup like, Properties env = new Properties();   env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");   env.put(Context.PROVIDER_URL, " 10.227.16.72:1099 ");     env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");    Context ctx = new InitialContext(env); If we are calling local ejb then we can simply create InitialContext without any parameters. Like, Context ctx = new InitialContext(); Using ENC JNDI to access EJBs  IF we want to use ENC JNDI then the , in the lookup method the name of the JNDI passed is prefixed with java:comp/env/ so, if we wish to use ENC JNDI and access ejb Sidd The JNDI name will look like java:comp/env/ejb/Fibo. It is a good practice to use ENC JNDI, since it seperates configuration from

External EJB reference

External EJB reference An EJB reference is called external when the bean B comes from another application unit, which may even be deployed on another server.In this case, you cannot rely on the standard <ejb-link> tag in web.xml since there the beans are not covered in the same file. Instead, you must provide the full JNDI name of the bean B in jboss-web.xml. A full name is of the form:  Note:: if we are calling remote ejb methods from servlets that we can Omit to specify any thing regarding ejb's in web.xml and jboss-web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app>   <servlet>   <servlet-name>AServlet</servlet-name>   <servlet-class>AServlet</servlet-class>   </servlet>   <ejb-ref>   <ejb-ref-name>ejb/BHome</ejb-ref-name>   <ejb-ref-type>Session</ejb-ref-type>   <home>BHome</home>   <remote>B</remote>  

Internal EJB reference

EJB Hand's On to Clear Concepts Internal EJB reference What is ejb-ref:: ejb-link?? The ejb-link element is used in the ejb-ref or ejb-local-ref elements to specify that an EJB reference is linked to an enterprise bean. The path name is relative to the war file containing the web application that is referencing the enterprise bean. This allows multiple enterprise beans with the same ejb-name to be uniquely identified. <ejb-link> is used so that servlets from the same application unit can refer ejb. If we specify <ejb-link> then we don't need to specify any thing in application server specific web.xml file(incase of jboss jboss-web.xml file) The following example demonstrate the same. <web-app>   ……… <ejb-ref >   <description><![CDATA[Reference to the Sidd EJB]]></description>   <ejb-ref-name>ejb/Sidd</ejb-ref-name>   <ejb-ref-type>Session</ejb-ref-type>   <home>tutorial.interfaces.SiddHo

Jakarta Commons HttpClient API Example

The Jakarta Commons HttpClient component provides API's for accessing HTTP Resources. We can download HttpClient from Apache and use it. The general process for using HttpClient consists of a number of steps: Create an instance of HttpClient . Create an instance of one of the methods (GetMethod in this case). The URL to connect to is passed in to the the method constructor. Tell HttpClient to execute the method. Read the response. Release the connection. Deal with the response. The following example shows, how we can use HttpClient for Submiting a form data to a URL. import java.io.IOException; import java.util.MissingResourceException; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; public class FundaHttpClient { public static boolean httpPost(HttpServletRequest request) { //UR

JSP Tag Library , TLD Example

A tag library allows a developer to group together tags with related functionality. A tag library uses a tag library descriptor (tld) file that describes the tag extensions and relates them to their Java classes. JSP's offer a unique feature of "Tag Libraries". Simply put, these are custom defined JSP tags. They are basically meant for componentizing presentation level logic. They are very similar to beans except the fact that Beans are used to separate Business logic. Every tag is mapped to a particular class file which is executed whenever the tag is encountered in an JSP file. The general syntax : Follows the general syntax for including a particular tag library from a jsp. <%@ taglib uri=" - - - - - " prefix = " - - - " %> Follows a example tld, PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> 1.0 1.1 Nefunda Nefunda Contact feature