Wednesday, May 26, 2010

Eclipse configuration issue with Java 3D

While working with Java 3D API, I found the latest version of Eclipse needs a change to the configuration regarding restricted API in order to avoid errors being reported by Eclipse.
The reported error would be
Access restriction: The type ** is not accessible due to restriction on required library j3dutils.jar

The configuration change is described in http://blog.js-development.com/2008/11/type-x-is-not-accessible-due-to.html .

Tuesday, May 18, 2010

Gathering environmental information

Linux OS:
uname -f
cat /etc/issue.net
cat /etc/*-release

Oracle version:
select * from v$version where banner like 'Oracle%';

Monday, April 12, 2010

customized web service invocation with one bpm tool

Lately, I've been working on a customized java service for one bpm tool (Cordys) to invoke platform web services. Here are the implementation details:
1. A method that takes xml message as a string:
public static String invoke(String endpoint, String userName, String password,
String requestMessage) {
SOAPMessage soapResponse = invoke(endpoint, userName, password,
convertStringToSoapMessage(requestMessage));

return convertSoapMessageToString(soapResponse);
}

2. A method that handles SoapMessage data type:
public static SOAPMessage invoke(String endpoint, String userName,
String password, SOAPMessage soapMsg) {
try {
// Create the connection
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory
.newInstance();
SOAPConnection conn = soapConnFactory.createConnection();

CordysAuthenticator credential = new CordysAuthenticator(userName, password);
// CordysAuthenticator is an "Authenticator" implementation
Authenticator.setDefault(credential);

SOAPMessage soapResponse = conn.call(soapMsg, endpoint);
conn.close();
return soapResponse;
} catch (SOAPException e) {
System.out.println("SOAPException : " + e);
return null;

}
}

3. A method to convert String to SoapMessage:
public static SOAPMessage convertStringToSoapMessage(String requestString) {

try {

// Use SAAJ to convert Document to SOAPElement
// Create SoapMessage
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart part=message.getSOAPPart();

byte[] soapBytes=requestString.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(soapBytes);
StreamSource source = new StreamSource(stream);
part.setContent(source);
message.saveChanges();

// This returns the SOAPBodyElement
// that contains ONLY the Payload
System.out.print("request message String:"+ requestString);
return message;

} catch (SOAPException e) {
System.out.println("SOAPException : " + e);
return null;

}

}

4. A method to convert SoapMessage to string
public static String convertSoapMessageToString(SOAPMessage soapMessage) {
try {
String result = "";

// Create transformer
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
// TransformerConfigurationException


// Get reply content
Source sourceMsg = soapMessage.getSOAPPart().getContent();
// SOAPException

// Set output transformation
StringWriter writer = new StringWriter();
StreamResult resultStream = new StreamResult(writer);
transformer.transform(sourceMsg, resultStream);
// TransformerException
result = writer.toString();
writer.close();
// IOException

return convertToXmlString(result);
} catch (...){}
}


There might be error message such as "invalid soap messages" when the message is sent to the web gateway. This might be caused by the doublequote used in the name space declaration of the xml message. In order to solve the problem, we can use the method String.replaceAll("\"","\\\""); to replace doublequotes with escaped doublequotes.

Thursday, March 25, 2010

Learning Scala

Some interesting read about scala, it could be a replacement for some J2EE implementations:
http://macstrac.blogspot.com/2009/04/scala-as-long-term-replacement-for.html
http://www.scala-lang.org/node/1305
http://programming-scala.labs.oreilly.com/

Monday, October 26, 2009

remove outdated files based on minor build number

I've created a script to remove old installation file based on the minor build number.
In one project I'm working on, we need to keep the file with the largest build number. Here's a sample to check which build number is the latest one.

for file in `find . -name \*$ESBPREFIX\*.isvp`
do
# echo $file
NAMELENGTH=`expr length $file`
POSITION=`expr $NAMELENGTH - 7`
ESBVERSION=`expr substr $file $POSITION 3`
if [ `expr index $ESBVERSION "."` -eq 1 ]; then
ESBVERSION=`expr substr $ESBVERSION 2 2`
fi
if [ `expr index $ESBVERSION "."` -eq 2 ]; then
ESBVERSION=`expr substr $ESBVERSION 3 1`
fi
# echo "[CO Build Number: $ESBVERSION]"
if [ $ESBVERSION -gt $MAXESBBDNR ]; then
MAXESBBDNR=$ESBVERSION
fi
done

Tuesday, October 06, 2009

Firing SOAP requests via Excel

Here's a tutorial about how to fire a soap request via Excel
http://www.brainbell.com/tutorials/ms-office/excel/Access_SOAP_Web_Services_From_Excel.htm .
The prerequisite is to get "Office Web Services Toolkit" from Microsoft website; then you can use it in VBA.
It'll be quite handy for those guys who work with SOA projects. A simple VBA can be built within excel worksheet to load soap request from OS and send it to the web service endpoint.