Wednesday 27 August 2008

Software engineering principals

Read write file stored in class folder of webapp

Read data from classes folder in WEB-INF.


Insure that text/xml file is packaged into the classes folder


Create a utility class to do file reading. This was tested in weblogic and tomcat


See code below:


package com.mp.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class FileReader {


public String readTextFile(final String name) throws Exception {
StringBuffer xmlFromFile = new StringBuffer();
InputStream instr = null;
instr = getFilePath2(name);

if (instr == null)
throw new FileNotFoundException();
InputStreamReader streamreader= null;

try {

streamreader= new InputStreamReader(instr);
int x = 0;
x = streamreader.read();
char c;
while (x != -1) {
c= (char) x;
xmlFromFile.append(c);
x = streamreader.read();

}

} catch (Exception e) {

System.out.println("Exception " + e.getMessage());
throw e;

} finally {
streamreader.close();

}

return xmlFromFile.toString();

}




public byte[] readBinFileFromClassPath(final String name) throws Exception {

byte bytearray[]= null;
FileInputStream fileinputstream=null;
try {

fileinputstream = new FileInputStream(getFilePath(name));
int numberBytes = fileinputstream.available();
bytearray = new byte[numberBytes];
fileinputstream.read(bytearray);

} catch (Exception e) {
System.out.println("Exception " + e.getMessage());
throw e;

} finally {
if(fileinputstream!=null)
fileinputstream.close();
}

return bytearray;
}




public byte[] readBinFilePath(final String name) throws Exception {

byte bytearray[]= null;
FileInputStream fileinputstream=null;
try {

fileinputstream = new FileInputStream(name);
int numberBytes = fileinputstream.available();
bytearray = new byte[numberBytes];
fileinputstream.read(bytearray);

} catch (Exception e) {
System.out.println("Exception " + e.getMessage());
throw e;

} finally {
if(fileinputstream!=null)
fileinputstream.close();
}

return bytearray;
}




public void writeBinFileToPath(String name, byte data[]) throws IOException{


FileOutputStream fileoutputstream =new FileOutputStream(name);

try {
fileoutputstream.write(data );


} catch (IOException e) {
System.out.println(e.getMessage());

}finally{
if(fileoutputstream!=null)
fileoutputstream.close();
data=null;
}

}





private InputStream getFilePath2(String filename) {
return this.getClass().getClassLoader().getResourceAsStream(filename);

}


private String getFilePath(String filename) throws FileNotFoundException {
String path=this.getClass().getClassLoader().getResource(filename).getPath();
if ("".equals(path))
throw new FileNotFoundException();
return path;

}






}


Tuesday 26 August 2008

Web Service calls in BEA Aqualogic BPM 6


 

I spend quite a bit of time searching how to make web service calls in Aqualogic BPM. There is virtually no document, except for Expense report tutorial which still does not answer the question.


 


 

The solution


 

Below is an example code you could place in interactive process to


 


 

service2 as Webservice.HelloWsdl.HelloService = Webservice.HelloWsdl.HelloService ();

sayHello
service2

using string1.string1

returning result4 = @out

string1.string2=result4


 

Another interesting point to note is that Aqualogic supports XPDL


 

One XPDL tutorial that I found to be useful

http://www.together.at/together/zzznocms/twe/twedoc/twe.html#d0e1719


 



UI prototyping

Just came across this plugin for UI prototyping. No separate application is require and it has quite a bit of features


 

https://addons.mozilla.org/en-US/firefox/addon/8487



Faster Java development


 

JavaRebel is a JVM plugin (-javaagent) that enables to reload changes made to Java class files on-the-fly, saving developers the time that it takes to redeploy an application or perform a container restart. It is a generic solution that works for Java EE and Java standalone applications

http://www.zeroturnaround.com/javarebel/


 

http://www.zeroturnaround.com/docs/javarebel-jpetstore-screencast Shows how it works

Thursday 21 August 2008

UI mock up in browser


 

Create UI mock ups in web browser

http://blogs.atlassian.com/developer/2008/07/balsamiq_mockups_brings_paper.html

Project templates, archetypes

Often it is found at project inception stage people ponder over project structure and then manually create them.

Instead one could use standard templates or archtypes in Maven world.

Below are some ready to use templates for projects

http://docs.codehaus.org/display/MAVENUSER/Archetypes+List


 

ach archetype page should enforce the following pattern :

* Archetype name

* Command line to call the archetype

* If the archetype can be used in an existing projects directory

* A tree view of the resulting files

* Some additional information like the additional properties used by the plugin


To use an archetype:


mvn archetype:generate


Generate gives you a wizard that will walk you through the various choices.


or


mvn
org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create
-DgroupId= -DartifactId= -DarchetypeArtifactId= -DarchetypeGroupId=

Find Jar files

I have found this website and it's quite useful when it comes to finding a jar file or when you are trying to find which jar a class belongs to.

http://findjar.com



Wednesday 20 August 2008

Generate Logging code using eclipse plug-in LOG 4 E


 

A neat plug-in for logging in java code, this could be useful in case one has code base without proper logging, other usage scenarios include, if one has to change logging API, or just a handy code generation utility.


 

http://log4e.jayefem.de/content/view/10/6/


 

Taran

Tuesday 19 August 2008

BEA XA Driver

Configuring Enterprise version of Aqualogic BPM on weblogic


 


 


 

Configuration wizard throws error, view the logs and you will find it is due to XS transactions


 

http://technet.microsoft.com/en-us/library/aa342335.aspx

Enable TCIP protocol from SQL server configuration manager


 

Copy the DLL for the environment (Linux, windows 32, 64)

Run the script included with the driver

Then run the script in link below this will install jxta sp required:


 

http://e-docs.bea.com/wls/docs81/jdbc_drivers/mssqlserver.html#1075232

Test from office 2007

I think this will help me finally start blogging J