|
|
|
Migration from J2EE to .NETby vivek devarajan.
Overview
Hi all, here are some quick tips to get you started, in case you need to migrate a J2EE based application to a .NET based application.
We approach the migration tier wise. Firstly, a technology mapping between both the platforms :--
| Service or Feature |
.NET |
J2EE |
| GUI |
WinForms |
SWING & AWT |
| Web GUI |
ASP.NET |
JSP |
| Web Scripting |
ISAPI, HttpHandler, HttpModule |
Servlet, Filter |
| Server Side Business Logic Component |
Serviced Component (COM+) |
EJB Session Beans |
| Server side Data component |
Serviced Component (COM+) with DB Logic |
EJB BMP Entity Beans |
| Server Side Data Component |
Object Spaces |
EJB CMP Entity Beans |
| Naming |
ADSI |
JNDI |
| Remote Invocation |
.NET Remoting |
RMI or RMI-IIOP |
| Data Access |
ADO.NET |
JDBC |
| Messaging |
MSMQ |
JMS |
| Transactions |
COM+ or MTS |
JTA |
Highlights of the migration strategy
- Presentation Tier JSP -> ASP.NET
- Business Logic Tier EJB -> COM+ (.NET Enterprise Service)
- Data Access Tier JDO/JDBC -> ADO.NET
i. Presentation tier migration
- JSP -> ASP .NET (sample code snippets)
JSP scriptlet :--
<!--Scriptlet-->
<%
for(int i = 0; i < 3; i++) {
out.println(i + "<br>");
}
%>
ASP .NET scriptlet :--
<!--Scriptlet-->
<%
for(int i = 0; i < 3; i++) {
Response.Write(i + "<br>");
}
%>
JSP expression :--
<%= new java.math.BigDecimal(10.1).negate() %>
ASP .NET expression :--
<%= System.Decimal.Negate(new System.Decimal(10.1)) %>
JSP declaration :--
<%!
public String foo() {
return "foo";
}
%>
ASP .NET declaration :--
<script runat="server" language="c#">
public virtual string foo()
{
return "foo";
}
</script>
- Implicit objects :--
| JSP |
ASP .NET |
| application |
Application |
| session |
Session |
| request |
Request |
| response |
Response |
| out |
Response.Write |
- Cookies :--
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.HttpCookie("user", "uid123");
System.DateTime dateTime = System.DateTime.Now;
System.TimeSpan timeSpan =
new System.TimeSpan(0, 0, 60*60*24*365); // 1 year
cookie.Expires = dateTime.Add(timeSpan);
Response.Cookies.Add(userCookie);
%>
- Beans :--
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{
private string text = "Hello";
public Bean1() {}
public string Text
{
get { return text; }
set { text = value; }
}
}
- Converting Servlets to ASP .NET code behind :--
Servlet sample code :--
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SimpleServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html");
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 SimpleServlet : System.Web.UI.Page
{
private void Page_Load(object sender, EventArgs args)
{
Response.ContentType = "text/html";
Response.Write("<html><body>");
Response.Write("Simple Servlet Body");
Response.Write("</body></html>");
}
}
- Tag Library :--
| JSP |
ASP .NET |
Tag Handler Class
JSP Tag Library Descriptor
JSP Tag Library Directive |
ASP.NET Web User Controls
ASP.NET Web Custom Control |
JSP tag lib Sample code :--
<!– JSP -->
<!– the source file is specified in the TLD -->
<%@ taglib uri="taglib.tld" prefix="tags" %>
<tags:sample />
ASP .NET tag lib Sample code :--
<!– ASP.NET -->
<%@ Register TagPrefix="tags" TagName="sample"
Src="ExampleTag.ascx" %>
<tags:sample id="mySample" runat="server" />
- 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 HelloWorld : System.Windows.Forms.UserControl
{
string parameter1;
bool isActive;
public HelloWorld()
{
init();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawString(parameter1, Font,
new SolidBrush(ForeColor), 25, 25);
}
public void init()
{
this.GotFocus +=
new EventHandler(this.helloWorldControl1_Start);
this.LostFocus +=
new EventHandler(this.helloWorldControl1_Stop);
}
}
Overview
Hi all, here are some quick tips to get you started, in case you need to migrate a J2EE based application to a .NET based application.
We approach the migration tier wise. Firstly, a technology mapping between both the platforms :--
| Service or Feature |
.NET |
J2EE |
| GUI |
WinForms |
SWING & AWT |
| Web GUI |
ASP.NET |
JSP |
| Web Scripting |
ISAPI, HttpHandler, HttpModule |
Servlet, Filter |
| Server Side Business Logic Component |
Serviced Component (COM+) |
EJB Session Beans |
| Server side Data component |
Serviced Component (COM+) with DB Logic |
EJB BMP Entity Beans |
| Server Side Data Component |
Object Spaces |
EJB CMP Entity Beans |
| Naming |
ADSI |
JNDI |
| Remote Invocation |
.NET Remoting |
RMI or RMI-IIOP |
| Data Access |
ADO.NET |
JDBC |
| Messaging |
MSMQ |
JMS |
| Transactions |
COM+ or MTS |
JTA |
Highlights of the migration strategy
- Presentation Tier JSP -> ASP.NET
- Business Logic Tier EJB -> COM+ (.NET Enterprise Service)
- Data Access Tier JDO/JDBC -> ADO.NET
i. Presentation tier migration
- JSP -> ASP .NET (sample code snippets)
JSP scriptlet :--
<!--Scriptlet-->
<%
for(int i = 0; i < 3; i++) {
out.println(i + "<br>");
}
%>
ASP .NET scriptlet :--
<!--Scriptlet-->
<%
for(int i = 0; i < 3; i++) {
Response.Write(i + "<br>");
}
%>
JSP expression :--
<%= new java.math.BigDecimal(10.1).negate() %>
ASP .NET expression :--
<%= System.Decimal.Negate(new System.Decimal(10.1)) %>
JSP declaration :--
<%!
public String foo() {
return "foo";
}
%>
ASP .NET declaration :--
<script runat="server" language="c#">
public virtual string foo()
{
return "foo";
}
</script>
- Implicit objects :--
| JSP |
ASP .NET |
| application |
Application |
| session |
Session |
| request |
Request |
| response |
Response |
| out |
Response.Write |
- Cookies :--
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.HttpCookie("user", "uid123");
System.DateTime dateTime = System.DateTime.Now;
System.TimeSpan timeSpan =
new System.TimeSpan(0, 0, 60*60*24*365); // 1 year
cookie.Expires = dateTime.Add(timeSpan);
Response.Cookies.Add(userCookie);
%>
- Beans :--
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{
private string text = "Hello";
public Bean1() {}
public string Text
{
get { return text; }
set { text = value; }
}
}
- Converting Servlets to ASP .NET code behind :--
Servlet sample code :--
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SimpleServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html");
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 SimpleServlet : System.Web.UI.Page
{
private void Page_Load(object sender, EventArgs args)
{
Response.ContentType = "text/html";
Response.Write("<html><body>");
Response.Write("Simple Servlet Body");
Response.Write("</body></html>");
}
}
- Tag Library :--
| JSP |
ASP .NET |
Tag Handler Class
JSP Tag Library Descriptor
JSP Tag Library Directive |
ASP.NET Web User Controls
ASP.NET Web Custom Control |
JSP tag lib Sample code :--
<!– JSP -->
<!– the source file is specified in the TLD -->
<%@ taglib uri="taglib.tld" prefix="tags" %>
<tags:sample />
ASP .NET tag lib Sample code :--
<!– ASP.NET -->
<%@ Register TagPrefix="tags" TagName="sample"
Src="ExampleTag.ascx" %>
<tags:sample id="mySample" runat="server" />
- 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 HelloWorld : System.Windows.Forms.UserControl
{
string parameter1;
bool isActive;
public HelloWorld()
{
init();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawString(parameter1, Font,
new SolidBrush(ForeColor), 25, 25);
}
public void init()
{
this.GotFocus +=
new EventHandler(this.helloWorldControl1_Start);
this.LostFocus +=
new EventHandler(this.helloWorldControl1_Stop);
}
}
|
See all comments and questions (post-ad) posted for this tutorial.
|
In order to post questions/comments, you must be logged-in. If you are not a member
yet, then signup, otherwise login. Once you
login then come back to this page and you'll see a form right here which will allow you
to post comments/questions.
Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a
reply to the thread you have subscribed to.
|
|
|