Wednesday, November 30, 2011

Installing shared printer remotely using VB Script

Installing shared printer remotely using VB Script

The below HTML code snippet can be used to install the shared printer remotely .

<html>
<title> Add Printer </title>
<head>
<script language="vbscript">
function AddPrinter()
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "<<Printer Path>>"
WshNetwork.SetDefaultPrinter "<<Printer Path>>"
Document.Write "Printer Installed Successfully , Please Close the Web Page"
end function
</script>
</head>
<body Onload="AddPrinter()">
Installing Selected Printer
</body>
</html>


Removing empty nodes from XML using xslt


Removing empty nodes from XML using xslt

The below XSLT can be used to remove the empty nodes from the XML file.

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:template match="node()|SDLT">
<xsl:if test="count(descendant::text()[string-length(normalize-space(.))>0] | @*[string-length(.)>0])">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="@*">
<xsl:copy />
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)" />
</xsl:template>
</xsl:stylesheet>


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


Monday, November 28, 2011

Oracle SOA Suite – Local optimization for webservice calls

Oracle SOA Suite – Local optimization for webservice calls:

The property “oracle.webservices.local.optimization” instructs Composite to make the webservice calls via SOAP stack or not. This property will work both in Oracle SOA Suite 11g and Oracle SOA Suite 12c.
By default the value for the property “oracle.webservices.local.optimization” is true. If the value is true and composite invokes any other webservice on the same server/domain, it avoids soap overhead and calls natively.

There may be a situation that you want to invoke the services via Soap Stack and changing the value of “oracle.webservices.local.optimization” property to false will help us to do that.
We can set this property in Composite.xml for a specific partner link only that partner link invocation always happens via soap stack.
Open the Composite.xml in JDev and add the property - oracle.webservices.local.optimization to the corresponding partnerlink binding.



When the local optimization is true, the policies attached to the partnerlinks are also bypassed