Friday, March 4, 2016

Produce JMS Message to weblogic console using java code

Use the below code to produce a Message in JMS queue using Java code. You can alter the code for lot of automations.

import java.util.Hashtable;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class QueueProducer
{
 // JNDI context factory.- its default
 public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";

 // JMS context factory- JNDI Name.
 public final static String JMS_FACTORY="jms/aia/TestResourceCF";

 // Queue JNDI.
 public final static String QUEUE="jms/aia/AIA_TEST_REQ_IN_JMSQ";

 private QueueConnectionFactory qconFactory;
 private QueueConnection qcon;
 private QueueSession qsession;
 private static QueueSender qsender;
 private Queue queue;
 private static Queue replytoqueue;
 private static TextMessage msg;

 public void init(Context ctx, String queueName)
    throws NamingException, JMSException
 {
    qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
    qcon = qconFactory.createQueueConnection();
    qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queue = (Queue) ctx.lookup(queueName);
qsender = qsession.createSender(queue);
    msg = qsession.createTextMessage();
    qcon.start();
 }


 public static void send(String message) throws Exception {
    msg.setText(message);
// Replytoname rn=new Replytoname(); //Optional
// Queue replyToQueue = rn.getreplyto(); //Optional
// msg.setJMSReplyTo(replytoqueue); //Optional
// msg.setStringProperty("_wls_mimehdrContent_Type","text/xml; charset=UTF-8"); You can set any JMS Properties Here
// msg.setJMSCorrelationID("testConnectivity");
    qsender.send(msg);
 }

 public void close() throws JMSException {
    qsender.close();
    qsession.close();
    qcon.close();
 }

 public static void main(String[] args) throws Exception {
  InitialContext ic = getInitialContext();
    QueueProducer qs = new QueueProducer();
    String test="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/> <soapenv:Body/></soapenv:Envelope>"; //XML Message
    qs.init(ic, QUEUE); // Open the Queue Session
    send(test); // Produce the message
    qs.close(); // Close the session
 }

 private static InitialContext getInitialContext()
    throws NamingException
 {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
    env.put(Context.PROVIDER_URL, "t3://Host:port"); // Your server credentials
    env.put(Context.SECURITY_PRINCIPAL, "weblogic");
    env.put(Context.SECURITY_CREDENTIALS, "password");
    return new InitialContext(env);
 }
}

Abort instances in EM Console using Java code soa 11g

Basically whatever we see in EM console and whatever do in EM console can be achieved via JAVA code too(using the facade API's). Below is the sample code to abort the instance for any composite in EM console by passing the instance id.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
import javax.naming.Context;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeInstanceFilter;
import oracle.soa.management.facade.CompositeInstance;
import java.util.List;

public class abortInstance
{
public static void main(String arg[]) throws Exception
{
Hashtable jndi = new Hashtable();
jndi.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndi.put(Context.PROVIDER_URL, "t3://Host:port");
jndi.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndi.put(Context.SECURITY_CREDENTIALS, "password");

jndi.put("dedicated.connection","true");
Locator locator = null;
String instanceID="4432123"; /// pass the composite Instance Id you want to Abort
try
{
locator =LocatorFactory.createLocator(jndi);
CompositeInstanceFilter filter =new CompositeInstanceFilter();
filter.setId(instanceID);
List<CompositeInstance> compositeInstances = locator.getCompositeInstances(filter);
((CompositeInstance)compositeInstances.get(0)).abort();
System.out.print("Instance aborted Successfully: "+instanceID);
locator.close();
}catch(Exception e)
{
locator.close();
e.printStackTrace();
}
finally {
        try {
            if (locator != null){                
            locator.close();            
            }
             } catch (Exception e) { }
    }
}

}

The same code can altered with other functions like delete the instance as well.

Thursday, March 3, 2016

BEA-380000 "Request Entity Too large" Error In OSB

While invoking external systems with help of  Business service, sometimes we might get error like below in the logs,
BEA-380000: Request Entity Too large or
BEA-381304:  <Exception in HttpTransportServlet.service: java.io.IOException: java.net.SocketException: Broken pipe

Even though the size of the XML is too small we might get this error because of Chunked streaming mode.

To eliminate these error,
Go to the configuration of the business service
Go to the HTTP Transport tab
Disable “Use Chunked Streaming Mode"

EBF and EBS in SOA 11g

In AIA, we have lot of terms like EBO,EBM,EBS,EBF,ABCS,etc.. Lets look at the difference between EBF and EBS, when do we need EBF?EBS?

Before that, we need to have a basic understanding on EBO and EBM.

EBO and EBM:
An EBO is the definition for a standard business data object and is composed of reusable data components. It supports the loose coupling of systems in Oracle AIA and eliminates the need for one-to-one mappings of the disparate data schemas between each set of systems. An EBO represents business concepts such as a customer, a sales order, a payment, and so forth. EBOs can be considered as application-independent representations of key business entities.

In simple Words, An EBM is the message format that is specific to the input or output of an EBS operation.

EBS:

  • An EBS provides the generic operations that an EBO should have. Enterprise Business Services (EBSs) are the centerpiece of the AIA Reference Architecture by enabling the Loose-coupling of Requesters with Actual Service Providers.
  • An EBS is coarse-grained and performs a specific business activity or business task and is either an Activity Service or Data Service. 
  • Basically EBS's are the routing services.


EBF:
  • An Enterprise Business Flow (EBF) is used to implement a business activity or a task that involves leveraging capabilities available in multiple applications.
  • An EBF is needed when an enterprise business service (EBS) operation needs to be implemented with a set of tasks and involves invoking of multiple services.
  • So basically EBF will take care of the logics and EBS will do the routing to respective providers.
  • An EBF involves only system-to-system or service-to-service interactions and does not include any activity that requires human intervention.
  • In a canonical integration, the EBF is an implementation of an EBS operation and calls other EBSs. 
  • An EBF never calls an ABCS or application directly. EBF is always encapsulated by EBS.


Similarities:
  • Both operate only on EBMs.
  • Both are external application-independent.(Means both interact within AIA level.)
  • Both are developed at the same time of life cycle.
  • Both works only on single operation.