Thursday, December 6, 2007
From .Net to Java
mso-border-alt:outset gray .75pt'>
Service/Feature style='font-size:8.0pt;font-family:Verdana'>
.NET
J2EE
GUI
style='font-size:10.0pt;font-family:Verdana'>WinForms style='font-size:8.0pt;font-family:Verdana'>
SWING / AWT
Web GUI
ASP/ASP.NET
JSP
Web Scripting
ISAPI, HttpHandler style='font-size:8.0pt;font-family:Verdana'>
style='font-size:10.0pt;font-family:Verdana'>Servlet style='font-size:10.0pt;font-family:Verdana'>, Filter, HttpModule style='font-size:8.0pt;font-family:Verdana'>
Server Side Business Logic Component style='font-size:8.0pt;font-family:Verdana'>
Serviced Component (COM+)
EJB Session Beans
Server Side Data Component
Server components with DB logic style='font-size:8.0pt;font-family:Verdana'>
EJB BMP Entity Beans with DB Logic style='font-size:8.0pt;font-family:Verdana'>
Naming
ADSI
JNDI
Remote Invocation
.NET Remoting style='font-size:8.0pt;font-family:Verdana'>
RMI / RMI-IIOP
Data Access
ADO.NET
JDBC, SQL/J
Messaging
MSMQ
JMS
Transactions
COM+ / MTS
JTA
Highlights
of the migration strategy
- style='font-size:10.0pt;font-family:Verdana'>Presentation Tier JSP ->
ASP.NET - style='font-size:10.0pt;font-family:Verdana'>Business Logic Tier EJB ->
COM+ (.NET Enterprise Service) - style='font-size:10.0pt;font-family:Verdana'>Data Access Tier JDO/JDBC
-> ADO.NET
1.
Presentation tier migration
a) JSP -> ASP.NET (sample code snippets) :-style='font-size:10.0pt;font-family:Verdana'>
JSP
Scriptlet
:-
<!--class=SpellE>Scriptlet-->
<%for (int i=0class=GramE>;i<3;i++){
out .println(i+"<class=SpellE>br>" );
}
%>
ASP
.NET scriptletclass=GramE> :-
<!--Scriptlet--style='font-size:10.0pt;font-family:Verdana;color:blue'>>style='font-size:10.0pt;font-family:Verdana'> <%
for(class=SpellE>int i=0;
i<3; i++){
Response.Write(i
+"<br>"); }
%>
JSP
Expression :-
<%=new
java.math.BigDecimalclass=GramE>(10.1).negate()%>
ASP
.NET Expression :-
<%=class=SpellE>System.Decimal.Negateclass=GramE>(new System.Decimal(10.1))style='background:yellow'>%>
JSP
Declaration :-
<%!
public String foo(){
return "foo";
}
%>
ASP
.NET Declaration :-
<script runat="server"style='font-size:10.0pt;font-family:Verdana;color:fuchsia'> style='font-size:10.0pt;font-family:Verdana;color:red'>languagestyle='font-size:10.0pt;font-family:Verdana;color:blue'>="c#">style='font-size:10.0pt;font-family:Verdana'>
public virtual System.String class=GramE>foo()
{
return "foo";
}
</scriptstyle='color:blue'>>
b) Implicit objects :-style='font-size:10.0pt;font-family:Verdana'>
mso-border-alt:outset gray .75pt'>
JSP
ASP .NET
application
Application
session
Session
request
Request
response
Response
out
style='font-size:10.0pt;font-family:Verdana'>Response.Write style='font-size:8.0pt;font-family:Verdana'>
c) Cookies :-style='font-size:10.0pt;font-family:Verdana'>
Creating
a cookie and setting its expiry time.
Code
in J2EE :-
<%
Cookie userCookie = new Cookie("user",
"uid123");
userCookie.setMaxAge(60*60*24*365); // 1 year
response.addCookie(userCookie);
%>
Code
in .NET :-
<%
System.Web.HttpCookie userCookie
= new System.Web.HttpCookieclass=GramE>("user",�"uid123");
System.DateTime dateTime = class=SpellE>System.DateTime.Now;
System.TimeSpan timeSpan = style='color:blue'>new System.TimeSpan(0, 0,
60*60*24*365); // 1 year
cookie.Expires = dateTime.Add(class=SpellE>timeSpan);
Response.Cookies.Add(userCookie);
%>
d) Beans :-style='font-size:10.0pt;font-family:Verdana'>
Java
code :-
public class bean1 {
private String text = "Hello";
public bean1 (){
}
public String getText() {
return this.text;
}
public String setText(String text) {
this.text = text;
}
}
C#
Code :-
using
System;
public class
bean1
{
virtual public class=SpellE>System.String Text
{
get
{
return style='color:blue'>this.text;
}
set
{
this.text = style='color:blue'>value;
}
}
private System.String
text = "Hello";
public bean1()
{
}
}
e) converting Servlets
to ASP .NET code behind :-
Servlet sample code :-
import
javax.servlet.*;
import javax.servlet.http.*;
public class SimpleServlet extends class=SpellE>HttpServlet {
public void doGet(HttpServletRequest
request,
HttpServletResponse response)
throws ServletException,
java.io.IOException {
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("Simple Servlet
Body");
out.println("</body></html>");
out.close();
}
}
ASP
.NET Code Behind sample :-
using
System;
using System.Web;
using System.Web.UI;
public class class=SpellE>SimpleServlet : System.Web.UI.Page
{
private void class=SpellE>Page_Load(object sender,
System.EventArgs
{
Response.ContentType="text/html";
Response.Write("<html><body>");
Response.Write("Simple Servlet
Body");
Response.Write("</body></html>");
}
}
f) Tag Library :-style='font-size:10.0pt;font-family:Verdana'>
mso-border-alt:outset gray .75pt'>
JSP
ASP .NET
Tag Handler Class
ASP.NET Web User Controls
JSP Tag Library Descriptor
ASP.NET Web Custom Control
JSP taglib style='font-size:8.0pt;font-family:Verdana'>
Directive
JSP
tag lib Sample code :-
<!- JSP -->
<!- the source file is specified in the TLD-->
<%@ taglib uri="class=SpellE>taglib.tld" prefix="tags" %>
<tags:sample />
ASP
.NET tag lib Sample code :-
<!- ASP .Net -->
<%@ Register TagPrefix="tags"
TagName="sample" src="class=SpellE>ExampleTag.ascx" %>
<tags:Samplestyle='color:fuchsia'> idstyle='color:blue'>="mySample"style='color:fuchsia'> runatstyle='color:blue'>="server"> </class=SpellE>tags:Samplestyle='color:blue'>>
g) Converting Java Applets to .NET Winforms
control
Applet
code :-
package HelloWorldPackage;
public class HelloWorld extends Applet
{
public void paint(Graphics g) {
g.drawString(getParameter("parameter1"),
25, 25);
}
public void init() {}
public void start() {}
public void stop() {}
}
.NET
Winforms code :-
namespace
HelloWorldPackage
{
public class class=SpellE>HelloWorld :System.Windows.Forms.UserControl
{
String parameter1;
bool class=SpellE>isActive;
public HelloWorld()
{
init();
}
protected override
void OnPaint(class=SpellE>PaintEventArgs e)
{
e.Graphics.DrawString(parameter1,Font, style='color:blue'>new SolidBrush(class=SpellE>ForeColor),25,25);
}
public void
init()
{
this.GotFocus += style='color:blue'>new System.EventHandler(style='color:blue'>this.helloWorldControl1_Start);
this.LostFocus += style='color:blue'>new System.EventHandler(style='color:blue'>this.helloWorldControl1_Stop);
}
}
2.
Business tier migration
Migrating
EJB to .NET Serviced Component
a) EJB code :- (Session bean)
public class TellerBean implements class=SpellE>SessionBean {
public void ejbCreate() {}
public void ejbRemove() throws
RemoteException {}
public void ejbActivate() throws RemoteException
{}
public void ejbPassivate() throws RemoteException
{}
public String getData()
}
.NET
code :- (serviced component corresponding to the java session bean)
[Transaction(class=SpellE>TransactionOption.Required)]
public class class=SpellE>TellerBean : System.EnterpriseServices.ServicedComponent
{
public void
Create() {}
virtual public class=SpellE>System.String Data
{ get{...} }
protected override
void Activate(){}
protected override
void Deactivate(){ }
protected void
Remove
{
this.Deactivate();
this.Dispose();
}
}
b) EJB Code :- (Entity Bean)
public
class AccountEntity implements EntityBean
{
private string accountID;
private int balance;
public get_accountID() { ... };
public get_balance() { ... };
public set_balance(int
amount) { ... };
}
public class AccountProcess implements class=SpellE>EntityBean {
public AccountEntity[] Inquiry() { ... };
public void Insert(AccountEntity account) {
string strQuery = "SELECT * FROM class=SpellE>tb_account";
...
};
public void Update(AccountEntity account) { ...
};
public void Delete(string accountID) { ... };
}
.NET
Code :- (serviced component corresponding to the java entity bean)
[class=GramE>Transaction(TransactionOption.Required)]
public class=SpellE>struct AccountEntity
{
private string class=SpellE>accountID;
private style='color:blue'>int balance;
public AccountID { style='color:blue'>get{...}; }
public Balance { get{...};
set {...}; }
}
// dsAccount.xsd
public class
dsAccount : System.Data.DataSet
{
...
}
public class class=SpellE>AccountProcess : System.EnterpriseServices.ServicedComponent
{
public dsAccount
Inquiry() { ... };
public void
Insert(AccountEntity account)
{
DBAgent.ExecuteNonQuery("sp_getAccount",
paramArray, ...);
...
};
public void
Insert(string accountID,
int balance, ...
){ ... }; // Alternative
}
Create Procedure sp_getAccount ( @accountID
char(8), @balance style='color:blue'>int , ... )
c) Business Client Tier
Java
Code :-
<%
try{
Context ctx = new InitialContext();
Object ref = ctx.lookup("TellerHome");
tellerHome = (TellerHome)
PortableRemoteObject.narrow(ref,
TellerHome.class);
teller = tellerHome.create();
out.println(teller.getData());
}
catch(Exception ex) {
out.println(ex.getMessage());
}
%>
.NET
Code :-
<%
myPackage.TellerBean teller = new myPackage.TellerBeanclass=GramE>();
Response.Write(teller.Data);
%>
3) Data
tier migration :-style='font-size:10.0pt;font-family:Verdana'>
a) Database connection :-style='font-size:10.0pt;font-family:Verdana'>
Java
:- (JDBC)
style='font-size:10.0pt;font-family:Verdana'>Class.forNameclass=GramE>(style='font-size:10.0pt;font-family:Verdana'>"com.ms.jdbc.odbc.JdbcOdbcDriver");
dbUrl = "jdbc:odbc:ADOTEST";
conn = DriverManager.getConnection(class=SpellE>dbUrl,"sa","");
.NET
(
style='font-size:10.0pt;font-family:Verdana'>dbUrlstyle='font-size:10.0pt;font-family:Verdana'> = "Provider=class=SpellE>SQLOLEDB;Data Source=dbserver;Initial
Catalog=Master;"
System.Data.OleDb.OleDbConnection temp_Connection;
temp_Connection = new
System.Data.OleDb.OleDbConnection(dbUrl);
temp_Connection.Open();
conn = temp_Connection;
b) Statement object :-
Java
:- (JDBC)
Statement
s = conn.createStatementclass=GramE>();
createTableBooks = "SELECT count(class=SpellE>au_lname) as nrows FROM
authors";
ResultSet rs = class=SpellE>s.executeQuery(createTableBooks);
.NET
(
System.Data.OleDb.OleDbCommandstyle='font-size:10.0pt;font-family:Verdana'> s = class=GramE>SupportClass.TransactionManager.manager.CreateStatementclass=GramE>(conn);
createTableBooks = "SELECT count(class=SpellE>au_lname) as nrows FROM
authors";
ls.CommandText = createTableBooks;
System.Data.OleDb.OleDbDataReader rs
= s.ExecuteReader();
Web Services and J2EE
If you would like to learn how to use SOAP, WSDL, and the Web services stack
with J2EE, this article gets you off to a good start. It is excerpted from
chapter 7 of the book Building Web Services with Java: Making sense of XML,
SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams;
ISBN: 0672326418).
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Continuing our
example scenario, the SkatesTown technical team has
been working in Java for a while and recently has been looking at moving some
of the Java applications that run on their server into the J2EE platform.
They've heard that it's secure, transactional, managed, scalable, and
robust—all the things they want for their business applications. But they're
also interested in Web services, and they want to be able to create services
easily. So, they've decided to build a sample application called class=SpellE>SkatesEJB, which will be a pilot project to determine the
value in using J2EE to implement their Web services.
J2EE Overviewstyle='font-size:9.0pt;font-family:Verdana;color:#333333'>
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Java 2 Enterprise
Edition (J2EE) is the platform for building enterprise applications in Java.
J2EE standardizes the services, programming model, and deployment for
applications so that developers can build solutions that can be used on a
variety of application servers. J2EE has a number of application models:
- Thin-client/browser-based applications use class=SpellE>servlets and JavaServer
Pages (JSPs). - Thick/managed application clients use RMI-IIOP
to communicate with server-based Enterprise JavaBeans (EJB) components. - Messaging applications use the Java Message
Service to act on messages in queues or from subscriptions.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>To this list we can
now add service-based applications, which offer services over SOAP/HTTP to
clients.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>J2EE provides a
framework that supports high quality of service (QoS).
In other words, J2EE lets you build transactional, secure, reliable
applications that are available across a cluster of highly available servers. A
J2EE application server provides a wide variety of capabilities including the
following:
- style='font-size:9.0pt;font-family:Verdana'>Workload and performance
management—Thread
management, pooling, caching, and cluster support - style='font-size:9.0pt;font-family:Verdana'>Security management style='font-size:9.0pt;font-family:Verdana'>—Password and certificate
management and validation, authentication, and access control - style='font-size:9.0pt;font-family:Verdana'>Resource management style='font-size:9.0pt;font-family:Verdana'>—Access to relational
databases, transactional management systems, connectors to Enterprise
Resource Planning (ERP) systems, and messaging systems - style='font-size:9.0pt;font-family:Verdana'>Transaction management style='font-size:9.0pt;font-family:Verdana'>—Two-phase commit support,
transactional access to databases, and distributed transactions - style='font-size:9.0pt;font-family:Verdana'>Management, configuration, and
administration—Deployment,
configuration, and administration tools
style='font-size:9.0pt;font-family:Verdana;color:#333333'>These services are
provided through the concept of a container.
Containers
style='font-size:9.0pt;font-family:Verdana;color:#333333'>A container is a
logical entity in a J2EE server. Containers are entities that have contracts
with the components that are deployed into a server—but they also help you
understand the way a J2EE system works. Components are deployed to a container,
and the container manages the execution of those components as needed. The
container provides isolation by intercepting calls to the class=SpellE>EJBs, allowing the container to manage aspects such as
threads, security, and transactions between components. The container also
provides a useful abstraction between components and the resources they use.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>For example, when one
component uses a database, the programmer uses a resource reference
(resource ref) to link to the database. Then the deployment engineer can
configure the actual database that maps to the reference. So, the code that is
written and compiled isn't hard-coded to a specific database.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>This approach is also
used for JMS destinations, URLs and URIs, and other
EJB components in the same or different applications. Later in the chapter,
you'll see an example of an ejb-ref that virtualizes
access to another EJB.
Web Services and
J2EE -
JavaBeans
(Page 2 of 4 )
style='font-size:9.0pt;font-family:Verdana;color:#333333'>The core of J2EE is
the EJB component. This is the programming model for writing and deploying
business logic into an application server. EJBs
provide a component model for creating business applications. EJB components
are mainly focused on aspects such business logic, as well as database and
legacy server access, transactions, security, and threading—in other words, how
you build core business services in a Java environment.
class=SpellE>EJBsstyle='font-size:9.0pt;font-family:Verdana;color:#333333'> initially look
complex because they were designed to layer over ordinary Java. For each
component, there are multiple .javastyle='font-size:9.0pt;font-family:Verdana;color:#333333'> files. Ideally, the
user has an Integrated Development Environment (IDE) that shows each component
as a whole as well as the individual class files for that component. However,
in the examples later in this book, we simply use a text editor and basic tools
for portability.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>The EJB component
model allows you to structure the business logic into discrete connected
components. EJB applications are loosely coupled, with well-defined interfaces.
class=SpellE>EJBsstyle='font-size:9.0pt;font-family:Verdana;color:#333333'> come in a variety of
styles:
- style='font-size:9.0pt;font-family:Verdana'>Session beans style='font-size:9.0pt;font-family:Verdana'> are business logic components
that are instantiated on behalf of a user and last no longer than the time
the client program remains active and running (a session). - style='font-size:9.0pt;font-family:Verdana'>Entity beans style='font-size:9.0pt;font-family:Verdana'> are components that are
mapped into an underlying database or persistent store (for
example, a bank account, purchase order, telephone number, or email
address). Each instance must have a unique key under which it is stored
and retrieved. - style='font-size:9.0pt;font-family:Verdana'>Message-driven beans ( class=SpellE>MDBs) are executed in response to a message at the server,
usually a one-way, asynchronous JMS message, but also including
messages from other systems such as SAP R/3 or PeopleSoft coming through a
connector.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>There is another
distinction: between local and remote EJBs. Local class=SpellE>EJBs can only be called from within the same container,
whereas remote EJBs are callable across a network
over distributed networking protocols (such as RMI-IIOP).
style='font-size:9.0pt;font-family:Verdana;color:#333333'>An application can be
thought of as having distinct parts—for example:
- The part that deals with the long-term storage
of data in a database or other persistent backend (local entity beans) - The part that provides business logic
(stateless local session beans) - The part that provides the interface with thick
clients or a graphical interface layer (stateless or stateful
remote session beans) - The graphical Web interface ( class=SpellE>servlets and JSPs)
- The part that deals with messaging—sending and
receiving messages from other systems (message-driven beans)
style='font-size:9.0pt;font-family:Verdana;color:#333333'>As you can see, the
J2EE application model is a component model that provides the right component
types to support solid business applications.
EJB Lifecyclestyle='font-size:9.0pt;font-family:Verdana;color:#333333'>
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Another aspect of
J2EE that's very important to Web services is the lifecycle of an EJB.
Components have well-defined lifecycles—they're instantiated, persisted, and
destroyed. EJBs define a "home" factory for
creating and managing the lifecycle of components. EJBs
can be divided into those with no real lifecycle and those with a lifecycle.
Note - The Open Grid Services Infrastructure (OGSI) offers a model of
services that have lifecycles. This is a point of debate around
Service-Oriented Architecture—whether services have lifecycles like objects or
whether they're stateless.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Stateless session
beans
are session beans with no real lifecycle—the container instantiates a pool of
these as needed. Although there are multiple instances of the component, each
instance is interchangeable with any other, because they have no state that
differs from method call to method call.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Message-driven beans
(MDBs) have no lifecycle either. They are
instantiated and pooled by the container—so they are always available.
class=SpellE>Statefulstyle='font-size:9.0pt;font-family:Verdana;color:#333333'> session beans (class=SpellE>SFSBs) are explicitly created by an application, with
parameters in the create(style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:"Courier New";
color:#333333'>) method (part of the home interface). The instance of an SFSB
contains state information specific to that client, and therefore it must
either be explicitly destroyed or timed out by the container (otherwise the
number would grow until the system's capacity was used up).
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Entity beans are class=SpellE>stateful and have attributes that are stored in a database,
file system, or other persistent storage. They must be either created or found
using a key. Because they're kept in a persistent datastore,
the objects have a very extended lifetime—unlike class=SpellE>SFSBs, which last as long as the client code is running,
these object instances remain available until they're explicitly deleted,
surviving reboots, crashes, system migrations, and so on. Another difference
with SFSBs is that many clients can talk to one
entity bean instance.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>The lifecycle-free
model of services matches the model of stateless session beans and class=SpellE>MDBs. In fact, a common design pattern in EJB programming
involves all distributed interaction with the EJB application taking place
through a façade of stateless session beans and MDBs.
This model most closely fits today's services infrastructure.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Initiatives such as
WS-Addressing (http://www-106.ibm.com/developerworks/library/ specification/class=SpellE>ws-add/) and the WS-Resource Framework (WSRF; style='font-size:9.0pt;font-family:Courier;color:#333333'>http://www.globus.org/wsrf/default.aspstyle='font-size:9.0pt;font-family:Verdana;color:#333333'>) allow class=SpellE>stateful components to be addressed as services. There are
ways of doing it without these technologies (such as adding a key to the end of
the address URL), but they aren't standardized. Apache Axis has recently added
support for WS-Addressing, but it isn't supported in Apache Axis or in the J2EE
specification at the time of this writing.
Note - Apache SOAP supports this approach. See
httpstyle='font-size:9.0pt;font-family:Courier;color:#333333'>://ws.apache.org/soap/style='font-size:9.0pt;font-family:Verdana;color:#333333'>.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>As you'll see when we
dive deeper into J2EE support for Web services, the only supported components
that can be accessed as Web services are servlets,
stateless session beans, and MDBs. For more information
about stateful services, see Chapter 8, "Web
Services and Stateful Resources."
Web Services and
J2EE - Roles: Development, Assembly, and Deploymentstyle='font-size:9.0pt;font-family:Verdana;color:#333333'>
(Page 3 of 4 )
style='font-size:9.0pt;font-family:Verdana;color:#333333'>One of the most
useful aspects of J2EE is the way the architecture was designed from the start
with ordinary people in mind. Early Web systems were often created from many
different technologies, so the developer had to be good at programming in
multiple languages and systems as well as understand the network, the database
connections, system administration, and so on. For example, many of the early
dynamic Web technologies mixed HTML with the programming language in a single
file. This meant that a graphic designer couldn't modify the look and feel
without risking breaking the logic—with the result the programmer frequently
did the layout and HTML/Web design, or spent valuable time cutting and pasting
HTML into their code.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>The J2EE model
clearly separates roles such as Web programmer, business logic
programmer, deployment engineer, and administrator. To achieve this separation,
there are clear contracts between the components and the infrastructure. For
example, JSPs allow the HTML and page design to be
separate from the business logic.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>There are two
important roles: the assembler and the deployment engineer. Both are like
systems integrators. Like a brick layer, the assembler pulls together a set of
components to create an application. Then the deployment engineer comes and
wires and connects everything, like an electrician and plumber rolled into one.
The mortar, solder, and cabling that keep it all together are called deployment
descriptors.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Deployment
descriptors (DDs) are XML files that capture
information about components and applications. They help resolve aspects left
undefined by the programmer, such as resolving references, setting policies,
and linking to other components.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>The following snippet
shows a sample DD for an EJB:
class=GramE><?xmlstyle='font-size:10.0pt;font-family:"Courier New";color:#333333'>
version="1.0"?>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><class=SpellE>ejb-jar>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><class=GramE>description>Simple Application</description>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><display-name>Simple</display-name>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><class=GramE>enterprise-beans>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><class=GramE>session>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><class=SpellE>ejb-name>StockQuote</class=SpellE>ejb-name>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><home>class=SpellE>com.skatestown.StockQHome</home>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><remote>class=SpellE>com.skatestown.StockQ</remote>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><class=SpellE>ejb-class>
class=SpellE>com.skatestown.StockQHome
style='font-size:10.0pt;font-family:"Courier New";color:#333333'></class=SpellE>ejb-class>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><session-type>Stateless</session-type>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'><transaction-type>Bean</transaction-type>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'></session>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'></enterprise-beans>
style='font-size:10.0pt;font-family:"Courier New";color:#333333'></class=SpellE>ejb-jar>
style='font-size:9.0pt;font-family:Verdana;color:#333333'>As you'll see later,
the same approach has been applied to the Web services support in J2EE 1.4,
where a new DD—webservices.xmlstyle='font-size:9.0pt;font-family:Verdana;color:#333333'>—has been added. This
file is effectively the Java Standards version of the Axis WSDD file.
Web Services and
J2EE - Benefits of Using Web Services with J2EEstyle='font-size:9.0pt;font-family:Verdana;color:#333333'>
(Page 4 of 4 )
style='font-size:9.0pt;font-family:Verdana;color:#333333'>J2EE is a
high-quality, reliable, secure infrastructure for building complex Web and
business applications. Web services started more simply with no inherent
security, reliability, or transactions, but these are now being added using the
open and flexible model that SOAP and Web services offer.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Many businesses are
using Web services with J2EE to provide simple interoperable access to existing
J2EE applications—for example, creating a C/C++/C# or VB.NET client to an EJB
application. Before SOAP and Web services, this was possible but very complex.
J2EE uses a distributed object model called RMI-IIOP, which bridges the Java
object model and the CORBA (IIOP) protocol. Accessing J2EE components from
outside Java used to require either bridge technology or complicated logic to
access the components using IIOP from C or C++. This was typically a painful
process. SOAP and Web services make this scenario much more appealing, and a
number of companies are using the SOAP approach in their systems today.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Why use J2EE with Web
services? In other words, why would you write a J2EE application and class=SpellE>EJBs if you could simply deploy Java classes into an Axis
server to create Web services? The answer, as usual, depends on the individual
circumstances. Many small applications will work fine with the Java Axis
approach. As the complexity and requirements on the application scale up,
having a managed J2EE environment in which to run components becomes more
appropriate. In particular, the benefits increase as you start to connect to
databases, messaging systems, and other enterprise systems.
Security
style='font-size:9.0pt;font-family:Verdana;color:#333333'>The first benefit
that a J2EE application server brings is security. Because the individual
methods (operations) of an EJB can be secured, and because J2EE has end-to-end
security, you can use either HTTPS or WS-Security to authenticate users and
then offer them services and/or operations with
fine-grained access control. For example, a single service may have bid
and cancel operations, and a J2EE application server can be configured
with one group of ordinary users who can bid, and then another group of class=SpellE>superusers who can cancel. Because security in J2EE is
tightly integrated into the Java runtime, these security models extend to the
Web services space, and so the access controls are applied to incoming SOAP
requests as well, based on the configuration and administration of the class=SpellE>EJBs. (For more details, see Chapter 9, "Securing Web
Services.")
Transaction Control Across
Distributed Resources
style='font-size:9.0pt;font-family:Verdana;color:#333333'>The second benefit a
J2EE application server offers is transaction control across distributed
resources. Even if you aren't using WS-AtomicTransaction
and WS-Coordination (see Chapter 11, "Web Services Transactions"),
you may wish to ensure that the backend resources you're communicating with are
kept in sync with each other and are transactional. For example, you may wish
to have a database log of Web service transactions held in an Oracle or DB2 RDB
and then use a JMS system to send messages internally to a legacy system. The
J2EE server can make the database log entry and send the message in the same
unit of work. That way, even if the HTTP connection fails and the SOAP response
message sent to the client fails, your server has a log of what happened.
Although it doesn't offer full end-to-end transactionality,
this type of architecture has been used extensively in Web-based systems to
provide a higher level of robustness at the application level.
Container Managed Persistencestyle='font-size:9.0pt;font-family:Verdana;color:#333333'>
style='font-size:9.0pt;font-family:Verdana;color:#333333'>J2EE offers both a
programming model for building business applications—including the tools and
technology to map your objects into databases (entity beans)—and a reliable,
scalable infrastructure for running those applications. As soon as the
application moves beyond the simplicity of a sample or first proof of concept,
users find that the learning curve and extra complexity of a J2EE solution is
repaid in the savings in time and effort that the model offers.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>For example, in our
sample application, the J2EE application server will automatically save the
state of the objects we create using a feature called Container Managed
Persistence (CMP). This means that instead of having to write database
logic and SQL statements, we can write fairly straightforward Java objects and
have the container generate the SQL and take care of all the database reads,
writes, and updates. This approach makes it quick and easy to build a Web
service application with a database at its heart. And, this support is
independent of which database server is used.
style='font-size:9.0pt;font-family:Verdana;color:#333333'>Please check back
next week for the continuation of this article.
Subscribe to Posts [Atom]