Tag Archives: JNDI

How to Install Jetty Application Server


via How to Install Jetty Application Server | Examples Java Code Geeks.

Jetty is an open-source Servlet container and Application Server which is known to be lightweight, portable, robust, flexible, extensible and providing support for various technologies like SPDY, WebSocket, OSGi, JMX, JNDI, and JAAS. Jetty is very convenient for development and also widely used in production environments.

In this post, we are going to detail how to install and configure a Jetty Server. We are first going to describe how to setup and run a standalone Jetty. Thereafter we will mention some configuration options and skim through the modular architecture of Jetty.

Jetty presents Standalone, Embedded and Jetty Maven Plugin modes of operation. In this post we are going to use standalone Jetty.

Jetty JNDI Example


via Jetty JNDI Example | Examples Java Code Geeks.

The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via name. Data sources, Mail Servers or Messaging queues are among the common objects that can be discovered through JNDI. JNDI lookup strategy abstracts applications from the external resources and makes them more configurable.

In this example, we are going to enable Jetty for JNDI lookups. As in the previous examples, we will start with embedded Jetty and programmatically enable JNDI lookups. We will register a JDBC datasource and demonstrate how we can lookup and access this datasource through JNDI. Thereafter we will see how JNDI resources can be configured in a Standalone Jetty.

JBoss EAP / Wildfly – Three ways to invoke remote EJBs


The JBoss EAP / Wildfly application server provides as primary API the EJB client library to invoke remote EJB components. This client library is the implementation of the WildFly application server to invoke EJB components. The lookup of an object, such as a JMS connection factory, from the naming service is with the EJB client […]

http://blog.akquinet.de/2014/09/26/jboss-eap-wildfly-three-ways-to-invoke-remote-ejbs/

Tomcat connection pool configuration example


via Tomcat connection pool configuration example | Examples Java Code Geeks.

In this example we will discuss Apache Tomcat Servlet/JSP container’s connection pull configuration via JNDI (Java Naming and Directory Interface ) resources. The connection pool we will look at is javax.sql.DataSource, which is a JDBC API for getting a connection instance to a database. In this example we will discuss setting a global DataSource for MySQL database.

javax.sql.DataSource is a factory for getting connections to different physical data sources. javax.sql.DataSource interface is registered with the naming service based on JNDI API. A data source driver allows accessed to the database via DataSource interface. A DataSource object is looked up in the context based on registered through JNDI Resource. The connection to the data source, such as database is attempted when javax.sql.DataSource‘s getConnection() method is called. Connection pooling has many benefits and is part of the Java EE standard implemented by Tomcat. It has many benefits one of which is increased performance and reduced connection creation and removal overhead due to connection reuse by the connection pool.

Use of JDBC API allows for flexibility of changing data source implementation driver form MySQL to Oracle for example, and allows using improved data source specific connection pool implementations. It also abstracts away database connection related plumbing, and allows developers to focus on business logic. Using configurations for setting connection pool also allows for server or web application specific connection pool tuning to meet demands of the application(s) on that particular server.

Read more about JNDI here. The Tomcat version used for this example is 8, the Windows version is 7 Professional SP1, and the data source discussed is MySQL server version 5.1.

Note that you can set up database connection in Java code as well. Read more from Apache’s website, or this stackoverflow question.

Note that in this example we will focus on server wide connection pull configuration, yet similar steps may be performed to do a web application specific connection pool configuration. Configuring the connection pool as a global resource results in the connection pool that is shared by all web applications deployed in the container.

In this example we will create a test web application called “testwebapp”, and a test database called “JCGExampleDB”.

Maven Jetty Plugin Example


via Maven Jetty Plugin Example | Examples Java Code Geeks.

In this example, we shall show you how to integrate Apache Maven with Jetty. Apache Maven is a software project management and comprehension tool. It provides powerful features like superior dependency management including automatic updating and transitive dependencies.

It follows the principle of convention over configuration, due to which one can start with a minimal configuration and sensible defaults will be provided for all the missing configuration. Maven uses central repositories where various artifacts like JAR files can be hosted. It comes with a mechanism that resolves all project dependencies from these central repositories. So effectively you are resolved from keeping and providing JAR files on your project’s classpath.

Maven needs a file called ‘pom.xml’ where one can define dependencies as we will be seeing in the example below. Once you choose to build the project, these dependencies will be automatically fetched from central repository and put on your application’s classpath. Jetty is a web server and a servlet container. It also provides support for SPDY, WebSocket, OSGi, JMX, JNDI, JAAS etc. So it is quite similar to the likes of other application containers. However if differs from them by providing a really tiny memory footprint and being Embeddable.

This means we do not need to install Jetty and then deploy our application. We just need to start our application from command line and Jetty will be started as an embedded container inside our application.This makes Jetty quite handy for tasks like Micro Services implementation and integration tests writing.

For this example we will be using Apache Maven 3.2.5 and Jetty Version 9.2.6. The example is compilable on Java 5 and above.