Saturday, May 19, 2012

Advantages of EJB 3.0

Advantages of EJB 3.0:

The below are the some of the advantages of using EJB 3.0


  1. More work is done by container,less by developer
  2. Everything is a POJO(Plain old java object)
  3. Simplify programming model
  4. Hibernate like ORM(Object Relational Mapping)
  5. Dependency injection
  6. Annotations(Requires Java 5)
  7. Bean specifies what it needs through metadata
  8. No longer written to unneeded container interfaces
  9. Deployment descriptor no longer required


FTP Upload/Download with Java

The below java code will help us to Download/Upload files from/To FTP server.

import java.io.*;
import java.net.*;

public class FTPClient {
    public final String host;
    public final String user;
    protected final String password;
    protected URLConnection ftpurl;

    public FTPClient(String host, String user, String password) {
        this.host = host;
        this.user = user;
        this.password = password;
        this.ftpurl = null;
    }

    private URL createURL(String destfile) throws MalformedURLException {
        if (user == null)
            return new URL("ftp://" + host + "/" + destfile + ";type=i");
        else
            return new URL("ftp://" + user + ":" + password + "@" + host +"/" + destfile + ";type=i");
    }

    protected InputStream openDownloadStream(String destfile) throws Exception {
        URL url = createURL(destfile);
        ftpurl = url.openConnection();
        InputStream is = ftpurl.getInputStream();
        return is;
    }

    protected OutputStream openUploadStream(String targetfile) throws Exception {
        URL url = createURL(targetfile);
        ftpurl = url.openConnection();
        OutputStream os = ftpurl.getOutputStream();
        return os;
    }

    protected void close() {
        ftpurl = null;
    }

    public void Upload(String sourcefile, String destfile) {
        try {
            OutputStream os = openUploadStream(destfile);
            FileInputStream is = new FileInputStream(sourcefile);
            byte[] buf = new byte[33554432];
            int c;
            while (true) {
                c = is.read(buf);
                if (c <= 0)
                    break;
                os.write(buf, 0, c);
            }
            os.close();
            is.close();
            close();
        } catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }

    public void Download(String sourcefile, String destfile) {
        try {
            InputStream is = openDownloadStream(destfile);
            FileOutputStream os = new FileOutputStream(sourcefile);
            byte[] buf = new byte[41943040];//Buffer size set to 40 MB ,change based on the file size
            int c;
            while (true) {
                c = is.read(buf);
                if (c <= 0)
                    break;
                os.write(buf, 0, c);
            }
            is.close();
            os.close();
            close();
        } catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }
}



Monday, May 7, 2012

Java code to Decrypt the weblogic server passwords

The below Java code will help us to decrypt the weblogic server password

import weblogic.security.internal.SerializedSystemIni;
    import weblogic.security.internal.encryption.ClearOrEncryptedService;
    import weblogic.security.internal.encryption.EncryptionService;
   
    public class Decrypt {
        public static void main(String[] args) {
            String string = args[0];
            EncryptionService encryptionService = SerializedSystemIni.getEncryptionService();
            ClearOrEncryptedService clearOrEncryptedService = new ClearOrEncryptedService(encryptionService);
            System.out.println("Clear text password: " + clearOrEncryptedService.decrypt(string));
        }
    }


Sunday, May 6, 2012

Java code to Marshal/Unmarshal XML using JAXB

Java code to Marshal/Unmarshal XML using JAXB:

Unmarshalling:

JAXBContext jc =JAXBContext.newInstance("com.java.test");//add multiple packages seperated by ":" eg.com.java.test1:com.java.test2
Unmarshaller u = jc.createUnmarshaller();
JAXBElement obj =(JAXBElement)u.unmarshal(new File(inputXMLPath)); // ok

Marshalling

Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
String outXML = "Response.xml";
marshaller.marshal(obj,new FileOutputStream(outXML));


Tuesday, March 20, 2012

Creating PDF document in JAVA using itext library

The java code to create a sample pdf document using itext.

Jar file required: itextpdf.jar

package itext;

import java.io.FileOutputStream;
import java.util.Date;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;

public class SamplePDF {
private static String FILE = "c:/temp/SamplePdf.pdf";
private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18,
Font.BOLD);
private static Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12,
Font.NORMAL, BaseColor.RED);
private static Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16,
Font.BOLD);
private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12,
Font.BOLD);

public static void main(String[] args) {
try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(FILE));
document.open();
addTitlePage(document);
addContent(document);
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}



private static void addTitlePage(Document document)
throws DocumentException {
Paragraph preface = new Paragraph();
addEmptyLine(preface, 1);
preface.add(new Paragraph("Sample Document", catFont));
addEmptyLine(preface, 1);
// File properties
preface.add(new Paragraph(
"Report generated by: " + System.getProperty("user.name") + ", " + new Date(), smallBold));
addEmptyLine(preface, 3);
preface.add(new Paragraph(
"This is a sample document ceated by itext ",
smallBold));

addEmptyLine(preface, 8);


document.add(preface);
// Start a new page
document.newPage();
}

private static void addContent(Document document) throws DocumentException {
Anchor anchor = new Anchor("First Chapter", catFont);
anchor.setName("First Chapter");

// Second parameter is the number of the chapter
Chapter catPart = new Chapter(new Paragraph(anchor), 1);

Paragraph subPara = new Paragraph("Subcategory 1", subFont);
Section subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Hello"));

subPara = new Paragraph("Subcategory 2", subFont);
subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Paragraph 1"));
subCatPart.add(new Paragraph("Paragraph 2"));
subCatPart.add(new Paragraph("Paragraph 3"));

// Add a list
createList(subCatPart);
Paragraph paragraph = new Paragraph();
addEmptyLine(paragraph, 5);
subCatPart.add(paragraph);

// Add a table
createTable(subCatPart);

// Now add all this to the document
document.add(catPart);

// Next section
anchor = new Anchor("Second Chapter", catFont);
anchor.setName("Second Chapter");

// Second parameter is the number of the chapter
catPart = new Chapter(new Paragraph(anchor), 1);

subPara = new Paragraph("Subcategory", subFont);
subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("This is a very important message"));

// Now add all this to the document
document.add(catPart);

}

private static void createTable(Section subCatPart)
throws BadElementException {
PdfPTable table = new PdfPTable(3);


PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);

c1 = new PdfPCell(new Phrase("Table Header 2"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);

c1 = new PdfPCell(new Phrase("Table Header 3"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
table.setHeaderRows(1);

table.addCell("1.0");
table.addCell("1.1");
table.addCell("1.2");
table.addCell("2.1");
table.addCell("2.2");
table.addCell("2.3");

subCatPart.add(table);

}

private static void createList(Section subCatPart) {
List list = new List(true, false, 10);
list.add(new ListItem("First point"));
list.add(new ListItem("Second point"));
list.add(new ListItem("Third point"));
subCatPart.add(list);
}

private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i < number; i++) {
paragraph.add(new Paragraph(" "));
}
}
}


Wednesday, March 14, 2012

how to add namespace Prefix to all the elements of JAX-WS webservice output

how to add namespace Prefix to all the elements of JAX-WS webservice output

This post will explain, how to add namespace Prefix to all the elements of JAX-WS webservice output

Sometimes we may required to have the namespace prefix (ex.ns1) defined for all the elments of the JAX-WS webservice output.

The default annotation of the package-info.java class looks like below

@javax.xml.bind.annotation.XmlSchema(namespace = "PPDS:OPIRequest", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.reuters.eai.types;

This case only the parent element will be have the namespace prefix but not the child elements.

eg.

<ns1:Employee ns1="PPDS:OPIRequest">
<name></name>
<number></number>
</ns1:Employee>

To have the namespace prefix in all the output elements,modify the above annotaion in the package-info.java class as mentioned below.

@XmlSchema( namespace = "PPDS:OPIRequest", elementFormDefault = XmlNsForm.QUALIFIED, xmlns={@XmlNs(prefix="ns3", namespaceURI="PPDS:OPIRequest")})
package com.reuters.eai.types;
import javax.xml.bind.annotation.*;

e.g

<ns1:Employee ns1="PPDS:OPIRequest">
<ns1:name></ns1:name>
<ns1:number></ns1:number>
</ns1:Employee>


Thursday, March 8, 2012

Dispalying the XML node as formatted string

Displaying the XML node as formatted string:

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Node;

public class TransformUtil {

public static String nodeToString(Node node) throws Exception{
StringWriter sw = new StringWriter();
try {
Transformer t = new org.apache.xalan.processor.TransformerFactoryImpl().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.transform(new DOMSource(node), new StreamResult(sw));
} catch (TransformerException te) {
System.out.println("nodeToString Transformer Exception");
throw te;
}
return sw.toString();
}

}


Wednesday, November 30, 2011

Adding main class and jar files to Class-Path in manifest through ANT script

Adding main class and jar files to Class-Path in manifest through ANT script

The below ANT script will help us to add main class and jar files to Class-Path in manifest of the JAR file.

<?xml version="1.0" encoding="iso-8859-1"?>
<project name="jar with libs" default="compile and build" basedir=".">

<target name="compile and build">
<delete dir="bin" />
<mkdir dir="bin"/>

<!-- copy the JARs that should be added to MANIFEST class-path to "bin" directory -->
<copy todir="bin">
<fileset dir="." includes="**/lib/*.jar" />
</copy>

<!-- creates your jar with the contents inside "bin" (now with your .class and .jar dependencies) -->
<jar destfile="SampleJar.jar" basedir="bin" duplicate="preserve">
<manifest>
<!-- Who is building this jar? -->
<attribute name="Built-By" value="Albin I" />
<!-- Information about the program itself -->
<attribute name="Implementation-Vendor" value="Company" />
<attribute name="Implementation-Title" value="Albin" />
<attribute name="Implementation-Version" value="1.0.0beta1" />
<attribute name="Class-Path" value="lib/bpm-services.jar lib/ldapjclnt11.jar lib/ojdbc14.jar lib/xmlparserv2.jar"/>

<!-- this tells which class should run when executing your jar -->
<attribute name="Main-class" value="com.import.ImportUtility" />
</manifest>
</jar>
</target>

</project>


JAVA utility class to encrypt/decrypt data using password based encryption(PBEWithMD5AndDES)

JAVA utility class to encrypt/decrypt data using password based encryption(PBEWithMD5AndDES)

The below code snippet will help us to encrypt/decrypt data using password based encryption(PBEWithMD5AndDES).

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEParameterSpec;


public class RdsCryptoLibrary {

private static final String PBE_KEY = "gZWKbHnijPAxrH+Sxw4fqp0FoVj6Ia2zA==qlPsn33wsz"
+ "ExumaDburVAw==PiU+p0wzGH2IbpQrpR6C7g==ld1"
+ "XwIUXYbSIBlPjTUYotg==CYm5rNsRA5KrGdPTvsrWuQ==";

private static final String PBE_ALGORITHM = "PBEWithMD5AndDES";

private static final String PBE_PROVIDER = "PBEWithMD5AndDES/CBC/PKCS5Padding";

private Cipher encryptCipher;

private Cipher decryptCipher;

private sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();

private sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();

public RdsCryptoLibrary( ) throws SecurityException {
//java.security.Security.addProvider(new com.sun.crypto.provider.SunJCE());
java.security.Security.addProvider(new com.ibm.crypto.provider.IBMJCE());
char[] pass = PBE_KEY.toCharArray();
byte[] salt = { (byte) 0xa3 , (byte) 0x21 , (byte) 0x24 , (byte) 0x2c ,
(byte) 0xf2 , (byte) 0xd2 , (byte) 0x3e , (byte) 0x19 };
int iterations = 3;
init(pass, salt, iterations);
}

public void init(char[] pass, byte[] salt, int iterations)
throws SecurityException {
try {
PBEParameterSpec ps = new javax.crypto.spec.PBEParameterSpec(salt,
20);

SecretKeyFactory kf = SecretKeyFactory.getInstance(PBE_ALGORITHM);
SecretKey k = kf.generateSecret(new javax.crypto.spec.PBEKeySpec(
pass));

encryptCipher = Cipher.getInstance(PBE_PROVIDER);
encryptCipher.init(Cipher.ENCRYPT_MODE, k, ps);

decryptCipher = Cipher.getInstance(PBE_PROVIDER);
decryptCipher.init(Cipher.DECRYPT_MODE, k, ps);
}
catch (Exception e) {
throw new SecurityException("Could not initialize CryptoLibrary: "
+ e.getMessage());
}
}

public synchronized String encrypt(String str) throws SecurityException {
try {
byte[] utf8 = str.getBytes("UTF8");
byte[] enc = encryptCipher.doFinal(utf8);
return encoder.encode(enc);
}
catch (Exception e) {
throw new SecurityException("Could not encrypt: " + e.getMessage());
}
}

public synchronized String decrypt(String str) throws SecurityException {
try {
byte[] dec = decoder.decodeBuffer(str);
byte[] utf8 = decryptCipher.doFinal(dec);
return new String(utf8, "UTF8");
}
catch (Exception e) {
throw new SecurityException("Could not decrypt: " + e.getMessage());
}
}
}


JAVA client to search and publish documents to Orace Service Registery

JAVA client to search and publish documents to Orace Service Registery

The below JAVA code snippet will help us to perform search and publish operations on OSR.

import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;
import java.net.*;
import java.security.*;
import java.util.*;

public class OSRClient {
Connection connection = null;

public OSRClient() {
}

public static void main(String[] args) {


OSRClient jq = new OSRClient();

jq.makeConnection("http://<<OSR Host>>:<<OSR Port>>/registry/uddi/inquiry", "http://<<OSR Host>>:<<OSR Port>>/registry/uddi/publishing");

jq.executePublish("admin","Password123");

//jq.executeQuery("admin","Password123");
}

/**
* Establishes a connection to a registry.
*
* @param queryUrl the URnL of the query registry
* @param publishUrl the URL of the publish registry
*/
public void makeConnection(
String queryUrl,
String publishUrl) {
/*
* Specify proxy information in case you
* are going beyond your firewall.
*/


/*
* Define connection configuration properties.
* For simple queries, you need the query URL.
*/
Properties props = new Properties();
props.setProperty("javax.xml.registry.queryManagerURL", queryUrl);
props.setProperty("javax.xml.registry.lifeCycleManagerURL", publishUrl);

try {
// Create the connection, passing it the
// configuration properties
ConnectionFactory factory = ConnectionFactory.newInstance();
factory.setProperties(props);
connection = factory.createConnection();
System.out.println("Created connection to registry");
} catch (Exception e) {
e.printStackTrace();

if (connection != null) {
try {
connection.close();
} catch (JAXRException je) {
}
}
}
}

/**
* Searches for objects owned by the user and
* displays data about them.
*
* @param username the username for the registry
* @param password the password for the registry
*/
public void executeQuery(
String username,
String password) {
RegistryService rs = null;
BusinessQueryManager bqm = null;

try {
// Get registry service and query manager
rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
System.out.println("Got registry service and " + "query manager");

// Get authorization from the registry
PasswordAuthentication passwdAuth = new PasswordAuthentication(
username,
password.toCharArray());

HashSet<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
creds.add(passwdAuth);
connection.setCredentials(creds);
System.out.println("Established security credentials");

// Get all objects owned by me
BulkResponse response = bqm.getRegistryObjects();

Collection objects = response.getCollection();

// Display information on the objects found
if (objects.isEmpty()) {
System.out.println("No objects found");
} else {
for (Object o : objects) {
RegistryObject obj = (RegistryObject) o;
System.out.println("Object key id: " + getKey(obj));
System.out.println("Object name is: " + getName(obj));
System.out.println(
"Object description is: " + getDescription(obj));

// Print spacer between objects
System.out.println(" --- ");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// At end, close connection to registry
if (connection != null) {
try {
connection.close();
} catch (JAXRException je) {
}
}
}
}

/**
* Returns the name value for a registry object.
*
* @param ro a RegistryObject
* @return the String value
*/
private String getName(RegistryObject ro) throws JAXRException {
try {
return ro.getName()
.getValue();
} catch (NullPointerException npe) {
return "No Name";
}
}

/**
* Returns the description value for a registry object.
*
* @param ro a RegistryObject
* @return the String value
*/
private String getDescription(RegistryObject ro) throws JAXRException {
try {
return ro.getDescription()
.getValue();
} catch (NullPointerException npe) {
return "No Description";
}
}

/**
* Returns the key id value for a registry object.
*
* @param ro a RegistryObject
* @return the String value
*/
private String getKey(RegistryObject ro) throws JAXRException {
try {
return ro.getKey()
.getId();
} catch (NullPointerException npe) {
return "No Key";
}
}

public void executePublish(String username, String password) {
RegistryService rs;
BusinessLifeCycleManager blcm;
BusinessQueryManager bqm;

try {
rs = connection.getRegistryService();
blcm = rs.getBusinessLifeCycleManager();
bqm = rs.getBusinessQueryManager();
System.out.println("Got registry service,query manager, and life cycle manager");

// Get authorization from the registry
PasswordAuthentication passwdAuth = new
PasswordAuthentication(username, password.toCharArray());
Set credits = new HashSet();
credits.add(passwdAuth);
connection.setCredentials(credits);
System.out.println("Established security credentials");

// Create organization name and description
// Replace this information with your organization information
Organization org = blcm.createOrganization("javacourses.com");
InternationalString s =
blcm.createInternationalString("Java training and consulting services");
org.setDescription(s);

// Create primary contact, set name
User primaryContact = blcm.createUser();
PersonName pName = blcm.createPersonName("Qusay H. Mahmoud");
primaryContact.setPersonName(pName);

// Set primary contact phone number
TelephoneNumber phoneNum = blcm.createTelephoneNumber();
phoneNum.setNumber("(604) 285-2000");
Collection phoneNums = new ArrayList();
phoneNums.add(phoneNum);
primaryContact.setTelephoneNumbers(phoneNums);

// Set primary contact email address
EmailAddress emailAddress =
blcm.createEmailAddress("[email protected]");
Collection emailAddresses = new ArrayList();
emailAddresses.add(emailAddress);
primaryContact.setEmailAddresses(emailAddresses);

// Set primary contact for organization
org.setPrimaryContact(primaryContact);

// Set classification scheme to NAICS
ClassificationScheme cScheme =
bqm.findClassificationSchemeByName(null,"ntis-gov:naics:1997");

// Create and add classification
Classification classification = (Classification)
blcm.createClassification(cScheme,
"Computer Training", "61142");
Collection classifications = new ArrayList();
classifications.add(classification);
org.addClassifications(classifications);

// Create services and service
Collection services = new ArrayList();
Service service =
blcm.createService("Buy a Java Course");
InternationalString is =
blcm.createInternationalString("This service allows you to register for a Java course and download its manuals.");
service.setDescription(is);

// Create service bindings
Collection serviceBindings = new ArrayList();
ServiceBinding binding = blcm.createServiceBinding();
is = blcm.createInternationalString("Service Binding "
+ "Access this services using the given URL.");
binding.setDescription(is);
binding.setAccessURI("http://javacourses.com/register");
serviceBindings.add(binding);

// Add service bindings to service
service.addServiceBindings(serviceBindings);

// Add service to services, then add services to organization
services.add(service);
org.addServices(services);

// Add organization and submit to registry
// Retrieve key if successful
Collection orgs = new ArrayList();
orgs.add(org);
BulkResponse response = blcm.saveOrganizations(orgs);
Collection exceptions = response.getExceptions();
if (exceptions == null) {
System.out.println("Organization saved");
Collection keys = response.getCollection();
Iterator keyIter = keys.iterator();
if (keyIter.hasNext()) {
javax.xml.registry.infomodel.Key orgKey =
(javax.xml.registry.infomodel.Key) keyIter.next();
String id = orgKey.getId();
System.out.println("Organization key is " + id);
org.setKey(orgKey);
}
} else {
Iterator excIter = exceptions.iterator();
Exception exception = null;
while (excIter.hasNext()) {
exception = (Exception) excIter.next();
System.err.println("Exception on save: " +
exception.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
if (connection != null) {
try {
connection.close();
} catch (JAXRException je) {
System.err.println("Connection close failed");
}
}
}
}

}


Tuesday, November 29, 2011

Java client to post/consume message from Weblogic JMS Queue

Java client to post/consume message from Weblogic JMS Queue

Sample Java client to post the message and consume the message from the Weblogic JMS queue.

package com.jms.test.wl;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.TextMessage;
import javax.naming.NamingException;

public class TestJMSQueue {

public static void main(String[] args) {
TestJMSQueue testApp = new TestJMSQueue();
testApp.post2Queue();
testApp.receiveFromQueue();
}

public void post2Queue() {
long l1 = System.currentTimeMillis();
javax.naming.Context jndiContext = null;
javax.jms.QueueConnectionFactory queueConnectionFactory = null;
javax.jms.QueueConnection queueConnection = null;
javax.jms.QueueSession queueSession = null;
javax.jms.Queue queue = null;
javax.jms.QueueSender queueSender = null;

javax.jms.TextMessage message = null;

java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(javax.naming.Context.PROVIDER_URL, "t3://localhost:7001");
env.put("weblogic.jndi.createIntermediateContexts", "true");

try {
jndiContext = new javax.naming.InitialContext(env);
} catch (NamingException e) {
System.out.println("Unable to create JNDI context "+e.toString());
e.printStackTrace();
}

try {
//queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("javax.jms.QueueConnectionFactory");
queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("jms/CustomerApplicationJMSConnectionFactory");
queue = (Queue) jndiContext.lookup("jms/CustomerApplicationRequestQueue");
} catch (NamingException e) {
System.out.println("JNDI lookup failed: " + e.toString());
e.printStackTrace();
}

try {
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
long l2 = System.currentTimeMillis();
//for(int i=0; i<1000; i++) {
message = queueSession.createTextMessage("Hello There 1");
queueSender.send(message);
//}
long l3 = System.currentTimeMillis();

System.out.println("Time Taken for setup and due diligence: "+(l2 - l1));
System.out.println("Time taken to send 1 million messages: "+(l3 -l2));
System.out.println("Overall Time taken: "+(l3 - l1));

} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
e.printStackTrace();
} finally {
if(queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
}

}



Common JAVA framework to invoke the Oracle SOA Suite Composite services

Common JAVA framework to invoke the Oracle SOA Suite Composite services:

There are different approaches to invoke the SOA Composites through java like DirectConnection, ADFBinding etc. But in both the approaches we have to add the additional configurations in the Composite.xml file.
Instead of using this approach, we can use the Apache Axis framework to invoke all the composites as a webservice.
We have implemented a Service Invocation Framework to invoke the composites through JAVA.
We have to set the endpoint and the operation name correspondingly to invoke the service.
I thought of sharing the framework as this may help somebody looking for same kind of framework.
Sample Client to Invoke the service(download the framework attached):
String endpoint="http://soahost:soaport/soa-infra/services/default/HelloWorld/helloworld_client_ep";

String xmlInput="<ns1:process xmlns:ns1=\"http://xmlns.oracle.com/EAIRules/HelloWorld/HelloWorld\">\n" +
" <ns1:input>Albin Issac</ns1:input>\n" +
" </ns1:process>";

InputObject inputParamObj = new InputObject();
System.out.println("End pint URL " +endpoint );
inputParamObj.setSServiceEndPoint(endpoint);
inputParamObj.setSOprName("sayHello");
inputParamObj.setInputPayload(xmlInput);
// Getting service invoker class to invoke service.
ServiceInvoker serviceInvoker =ServiceInvoker.getInstance();
try {
serviceInvoker.invokeService(inputParamObj, null);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Process Successfully Invoked!<br>");

DOWNLOAD WebServiceInvocationFramework.zip