A Java Learner's Notes

About Me

Madhu
A software engineer currently working at Pramati Technologies Ltd. www.pramati.com
View my complete profile

Monday, February 02, 2009

Checkout the Awards coming out of Regent EC2 deployment




Friday, January 04, 2008

Deloyment on JBoss






Application deployment or migration is a bit concerned for all of us, as every appserver has its own configuration and deployment policies. JBoss is no different here.
Even though JBoss embeds Tomcat, the deployment is a bit different.

The auto deploy folder is - JBOSS_HOME/server/default/deploy. Not only applications, even data sources configurations are dropped here.

Application deployment
  1. Drop .war, .ear files here to get auto-deploy. Removing them will un-deploy them.
  2. You can also deploy explode the archive into a folder and copy them here. For web application, hai.war, the folder name should also be "hai.war"
  3. Every time server starts, the .war, .ear files get extracted into a temporary folder - JBOSS_HOME/server/default/tmp/deploy/tmpXXXX.
  4. Replacing the file while server is running, will extract to a different temp folder.
  5. While undeploying, redeploying and server shutdown, these tmp folders also get deleted.
  6. Like in Tomcat, you can find generated JSP servlet java code here - JBOSS_HOME/server/default/work/jboss.web/localhost//

Web application exploded deployment
  1. Inside auto deploy folder - create a folder with same name as archive and extract all the contents - exp1.war, exp2.jar etc.,
  2. Declaring <context> for web application. Tomcat is embedded, for JBoss 4.2, the folder is JBOSS_HOME/serverdefault/deploy/jboss-web.deployer/server.xml as described tomcat manual here

  3. Deploying from existing web application folder (say our eclipse project development setup) - then you should have a folder as said above, and then declare that folder in the discover list - jboss-service.xml



<attribute name="URLs">
deploy/, file:/E:/workspace/madhu-deploy/<br />
</attribute>

I will keep my applications exploded under as E:/workspace/madhu-deploy/hai.war/, E:/workspace/madhu-deploy/exp2.jar/ etc.,

Data sources
Create data sources by placing separate files - XXX-ds.xml in auto deploy folder (specified above)
  • There exists a default datasource for HSQL database here - hsqldb-ds.xml
  • Copy the content to different file with same suffix.
  • Edit the below driver properties


<connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB</connection-url>
<driver-class>org.hsqldb.jdbcDriver</driver-class>
<user-name>sa</user-name>
<password></password>

  • Specify the mapping - depending the database vendor and version. JBOSS_HOME/server/default/conf/standardjbosscmp-jdbc.xml



<metadata>
<type-mapping>Hypersonic SQL</type-mapping>
</metadata>

  • For MYSQL - mySQL, ORACLE it is Oracle7, Oracle8, Oracle9i etc.,
  • Specify unique JNDI name

    
<jndi-name>jdbc/mysql_MyApp_DS</jndi-name>

Mail resource
Edit mail-service.xml already present in auto deploy folder
  • JNDI name specified there is "java:/Mail"
  • If you have access to SMTP server,

        
<property name="mail.smtp.host" value="mail.mycompany.com">
<property name="mail.smtp.port" value="25">
<property name="mail.from" value="welcome@studynetwork.com">
</property></property></property>

  • Using GMail, you need to specify login and password.

Changing web port and port access

The default web port is 8080, which conflicts with tomcat.
You may also want to change this in production machine.
JBOSS_HOME/serverdefault/deploy/jboss-web.deployer/server.xml

  • Change <connector> port value to desired port.


<connector port="8282" address="${jboss.bind.address}" maxthreads="250"
maxhttpheadersize="8192" emptysessionpath="true" protocol="HTTP/1.1"
enablelookups="false" redirectport="8443" acceptcount="100"
connectiontimeout="20000" disableuploadtimeout="true">
</connector>

  • In JBoss 4.2, we observed the applications are not get served to different machines other than the one where it is deployed. That is because of address attribute specified.
  • ${jboss.bind.address} stands for local machine. So the web applications are only accessible locally.
  • You can specify to your subnet by giving regex - 192.168.*
  • This is a cool feature for secured applications to be accessible for known people.
  • Remove this attribute to all machines to access your deployed applications. (especially on production machine)





Friday, May 25, 2007

Introducing Python for Java developers


Java
Python
Source files are called Java classes stored with extension - .java
Source files are called modules stored with extension - .py
.java compiled to .class and interpreted by JVM
interpreted .py file
CLASSPATH env variable & jre/lib/ext with .class or .jar/.zip files
PYTHONPATH env variable & <python-install>/Lib folder containing all .py files.
compile with optimization and execution:
javac -g:none HelloWorld.java (creates .class file)
java HelloWorld

Execute directly.
python -O HelloWorld.py
(may create .pyo or .pyc files)

// this is a comment
/* bulk comment */
#this is a comment. Don't indent me in case of if etc.,

Packaging: Java source should have package specified as the first statement -
package com.pramati.samples
Those directories having the __init__.py file (can be empty) are treated as packages -
Inside <install>/Lib/com/pramati/samples/__init__.py
Importing classes from other packages and using.
import [package-name].[class-name] as present in jar or class folder -
import com.pramati.util.List;
import com.pramati.io.*;
import java.util.*;
import java.sql.*;

Need not refer to full name of the class EXCEPT for conflicting ones (here Date is present in util and sql packages)
void method1() {
java.util.Date utilDate = new java.util.Date();
Connection con = null;
java.io.BufferedReader br = new java.io.BufferedReader(System.in)
}

Need not declare when fully qualified path is specified where used (here java.io.BufferedReader is not imported)
WITHOUT IMPORT statement, you can't use the module

The style of importing defines how you use them
Method 1:
import com.pramati.util.List
def m1():
com.pramati.util.List.removeDuplicates(li)

Method 2A:
from com.pramati.util import List
def m1():
List.removeDuplicates(li)

Method 2B: Importing multiple modules: __init__.py should define variable __all__ with modules to load -
__init__.py inside folder com/pramati/util
__all__ = ["List", "Set", "Collection"]
def m1():
List.removeDuplicates(li)

; and { } are statement separators and blocks
statement per line and indentation (usually followed by colon)used for blocks like if, for etc
method declaration : <return type> <name>(<args>){ <BODY>}
def <name>(<args with default values like in C++>) : <INDENTED BODY>
if(<boolean expression>) { <BODY>}
if <C style non-zero arithmetic expression>: <INDENTED BODY>
for each loop -- for(int y : arr) {system.out.println(y)}
for y in arr:
print(y)
While loop.

while(b<10) {
b++;
if (b ==9) {
break;
} else {
continue;
}

}
1.No increment or decrement operators.
2. comparing with "==" as in Java/C
3. break, continue as it is in C.
while b<10:
b = b + 1
if b==9:
break
else
continue
System.out.println()
print
Arrays : int a[] = new int[10]
Lists :
List li = new ArrayList()
li.add("hari");
li.add(2, "sri");
li.addAll(new ArrayList());
li.remove("sri");
li.size();
li.indexOf("sri");
Collections.sort(li);
Collections.reverse(li);
Has only Lists. The syntax of using lists is more like arrays in java.
li = ['spam', 'eggs', 100, 1234]
li.append(10)
li.insert(6, 'sri')
li.extend([10, 20, 30])
li.remove('sri')
li[0]='rama'
len(li)
li.index("sri")
li.sort()
li.reverse()

Read input - int x = System.in.read()
x = int(raw_input("Please enter an integer: "))
Empty statement
if (x > 10)
; // do nothing.

if x > 10:
pass #do nothing
Null value - Object x = null;
x = None
Converting (numbers) to String:
int age = 19; List wealth = new ArrayList();
- concating primitives and objects (with overridden toString())
String x = "At age " + 19 + " acquired below property - n" +wealth
- String.valueOf()
String x = String.valueOf(age)

any variable with in reverse quotes (``)
myage = 19, dadage=40
iam = 'I am ' + `dadage` + '-' + `myage` + '= ' + `(dadage-myage)` + ' yrs older'
print iam
OUTPUT: I am 40-19= 21 yrs older
Converting String to number:
int x = Integer.parseInt("43434");
double y = Double.parseDouble("343.999");
string module defines many useful methods other than these
import string
x = string.atoi("4343")
y = string.atof("3434.4343")
Exception handling
try {
int y = 0;
int x = 10 /y;
} catch(Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
} finally {
System.out.println("done..");
}

A try statement must have one or more catch clauses and may or may not have one finally clause.

try:
x = 1/0
except (ZeroDivisionError, ValueError, NameError):
print sys.exc_info()[0]
else : #called when
print "no problem!"

try :
x = 1/0
finally :
print "In finally"

A try statement must either have one or more except clauses or one finally clause, but not both
throw new Exception("Invalid value");
raise NameError, "Invalid value"



Note :
  • A program doesn't run any faster when it is read from a .pyc or .pyo file than when it is read from a .py file; the only thing that's faster about .pyc or .pyo files is the speed with which they are loaded

Tuesday, July 12, 2005

Corba Vs WSDL

Interesting comparison : Tools that can generate from IDL to CORBA code in C etc and as well as WSDL.


IDL, WSDL file Differences :

  1. IDL type (struct or valuetype or exception) corresponds to WSDL type(defined in <type> tag)
  2. IDL method signature (return-type + name + paramtypes) corresponds to WSDL operation (operation tag with nested tags : input, output and fault tags).
  3. IDL Interface (encapsulating all its members) corresponds to WSDL port (Using port tag).
  4. A Corba Object corresponds to a WebService.
  5. WSDL-SOAP message can be on wide transports : http, smtp etc. where as Corba objects communicate over IIOP protocol only. However a particual SOAP Binding is tied to a particular transport in the WSDL file itself [In soap:binding tag with transport attribute].



A service (wsdl) is like a contract of loosely-coupled messages exchangeable where as interface (idl) allows binding with an object (thru a stub/proxy).