Posted by Albin Joseph | Posted in RSA | Posted on 03-11-2008
Reverse Engineering Java classes in RSA
How do we create UML diagrams from Java classes using RSA? Or how do we reverse engineer a java class or project using Rational Software Architect? This was a question came to my mind when I wanted to generate some UML diagrams from Java classes. To generate UML diagrams from Java classes, I tried RAD first as I was working on RAD. I managed to generate class diagrams for individual classes using RAD. But to generate the UML diagrams at Project Level there was no option I could find in RAD. So I moved to RSA for reverse engineering my java classes.
To reverse engineer or create UML class diagrams from Java classes using Rational Software Architect follow the below steps.
1. Create a UML Project. This project is used for creating
To create a new UML project goes to File -> New Project -> Modeling -> UML Project.
2. Right click on the project that you want to reverse engineer and click on New -> Other. Select Transformation Configuration from Transformations folder.

3. Enter a name for the Transformation configuration and select ‘Java to UML’ as the transformation. Click on Next.

4. From the source and target window select your java/web project as the source and UML project as the target.

5. Click on Finish.
6. Now your transformation configuration page will be opened. You can run your configuration either by clicking on Run button of your transformation configuration or by right click on the project and select Transform -> transformation name -> Java to UML option.

Posted by Albin Joseph | Posted in Java | Posted on 02-11-2008
Tagged Under : Java
Recursively delete a directory
Here is a very simple code for recursively delete directories using java.
/**
* Recursively deletes a directory and all its
* sub directories.
*/
public static void deleteDir(File dir){
// If it is a directory get the child
if(dir.isDirectory()) {
// List all the contents of the directory
File fileList[] = dir.listFiles();
// Loop through the list of files/directories
for(int index = 0; index < fileList.length; index++) {
// Get the current file object.
File file = fileList[index];
// Call deleteDir function once again for deleting all the directory contents or
// sub directories if any present.
deleteDir(file);
}
}
// Delete the current directory or file.
dir.delete();
} |
To delete a directory using this method pass the directory name as a File object to deleteDir method. This code is very useful if the directory name is too long. Windows has a restriction in how long a Filename can be. So if you file path is too long, you wouldn’t be able to delete a directory.
Posted by Albin Joseph | Posted in WebSphere | Posted on 27-10-2008
Sending an e-mail using WebSphere Mail session settings.
Yesterday I had posted about configuring a Mail Session in WebSphere Application Server admin console. Today I will be talking about sending an email from your JSP using the configured mail session.
To access the Mail session for sending your email you need to do a JNDI lookup from your JSP file. The complete code for sending email using the Mail Session settings is given below.
// Look up mail session
javax.naming.Context context = new javax.naming.InitialContext();
javax.mail.Session mailSession = (javax.mail.Session) context.lookup("mail/localmail");
javax.mail.Message msg = new javax.mail.internet.MimeMessage(mailSession);
msg.setFrom(new javax.mail.internet.InternetAddress(fromEmail));
msg.setRecipients(javax.mail.Message.RecipientType.TO, javax.mail.internet.InternetAddress.parse(toEmail));
msg.setSubject(mailSubject);
msg.setText(mailBody);
javax.mail.Transport.send(msg);
System.out.println("Message Sent"); |
I have used the JNDI name directly for accessing the mail session settings. A better alternative is to use the resource reference in your JSP/Servlet code. The advantage of this approach is that we don’t need to alter the code even if our configuration name changes.
To add a resource reference opens your web.xml. Go to References Tab. Click on Add and select Resource Reference as the reference type and enter the details. For type select javax.mail.Session from the drop down box. If you are using resource reference, your lookup code will change to
javax.mail.Session mailSession = (javax.mail.Session) context.lookup("java:comp/mail/localmail"); |
Posted by Albin Joseph | Posted in WebSphere | Posted on 25-10-2008
Sending emails is necessary in almost every web application. If your Web application is hosted in WebSphere Application Server you can lookup a Mail session from your servlet or JSP using JNDI. Today I will be explaining how to configure Mail Sessions in WebSphere Application Server? To configure your mail session settings follow the steps.
1. Login to admin console. The admin console url will be http://localhost:9060/admin if you are using the default port and your server is localhost. Else change the port and server name.
2. Click on Resources -> Mail providers.

3. From the page opened click on Built-in Mail Provider.
4. From Built-in Mail Provider page click on ‘Mail Sessions’ link.

5. The Mail Sessions page will be opened. Now click on New.
6. Mail session configuration page appears. Enter the details. Here Name is the administrative name of the JavaMail session object, JNDI name is the name of the resource. If your mail server needs a username and password for sending emails, enter Mail transport user ID and Mail transport password too.

7. Apply and Save the changes to master configuration.
You are done with the configuring your mail session settings. Now you can use the configured the mail session for sending mail from your web application using a JNDI lookup.
Yesterday I came across a new exception while invoking my web service using WebSphere Process Server. I was trying to invoke an external web service from WID. The exception or web service fault message I was getting was
CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "transactionNotSupportedActivitySessionNotSupported" on bean "BeanId(CustomerProfileApp#CustomerProfileEJB.jar#Module, null)". Exception data: com.ibm.websphere.sca.ServiceRuntimeException: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Fault><faultcode>soapenv:Server.generalException</faultcode><faultstring>org.xml.sax.SAXException: WSWS3047E: Error: Cannot deserialize element elementName of bean beanName. To see the message containing the parsing error in the log, either enable web service engine tracing or set MessageContext.setHighFidelity(true).</faultstring></soapenv:Fault></soapenv:Body>
at com.ibm.wsspi.sca.webservice.jaxrpc.ServiceImportHandler.handleFault(ServiceImportHandler.java:313)
at com.ibm.ws.webservices.engine.handlers.jaxrpc.HandlerProxy.handleFault(HandlerProxy.java:159)
at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandlerChain.oneHandleFault(JAXRPCHandlerChain.java:869)
at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandlerChain.handleFault(JAXRPCHandlerChain.java:846)
at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandlerChain.handleFault(JAXRPCHandlerChain.java:839)
at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandler.invokeClientFaultHandler(JAXRPCHandler.java:535)
at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandler$3.onFault(JAXRPCHandler.java:453)
at com.ibm.ws.webservices.engine.PivotHandlerWrapper.onFault(PivotHandlerWrapper.java:516)
at com.ibm.ws.webservices.engine.PivotHandlerWrapper.invoke(PivotHandlerWrapper.java:317)
at com.ibm.ws.webservices.engine.WebServicesEngine.invoke(WebServicesEngine.java:336)
at com.ibm.ws.webservices.engine.client.Connection.invokeEngine(Connection.java:929)
at com.ibm.ws.webservices.engine.client.Connection.invoke(Connection.java:722) |
This usually happens when you have an array of complex types. There is a technote available from IBM and they are providing three different solution. I just followed one of the solutions given by that technote. So to resolve this issue follow the below steps.
1. Open your WSDL file
2. Search for the elementName that cannot be serialized.
3. If you found an entry like
<element name="elementName" nillable="true" type="someComplexType" /> |
4. Add ‘ xmlns=”"‘ to that element.
5. Now your element definition will look like
<element name="elementName" nillable="true" type="someComplexType" xmlns="" /> |
This will resolve the issue. At least it solved my problem. However the IBM recommended solution is to use the proper namespace.