Sunday, October 14, 2012

Sending message to weblogic queue

A java class for sending text message to a weblogic queue
===============================


package test;

import java.util.Hashtable;

import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class QSendTest {
public static void main(String[] args)
throws Exception {
 QueueConnectionFactory qconFactory = null;
 QueueConnection qcon = null;
 QueueSession qsession = null;
 Queue queue = null;
 TextMessage msg = null;

 InitialContext ctx = getInitialContext();
 qconFactory = (QueueConnectionFactory)
 ctx.lookup("jms/MyTestConnectionFactory");
 qcon = qconFactory.createQueueConnection();
 qsession = qcon.createQueueSession(false,
  QueueSession.AUTO_ACKNOWLEDGE);

 queue = (Queue) ctx.lookup("jms/MyTestQueue");

//Posting message to Queue
 QueueSender qsender = qsession.createSender(queue);
 msg = qsession.createTextMessage();
 msg.setStringProperty("MSG_ID", "12345678947");
 msg.setText("Hello at " + System.currentTimeMillis());
 qsender.send(msg);
 System.out.println("Sent");
 qsender.close();

}

private static InitialContext getInitialContext()
throws NamingException {
 Hashtable<String, String> env = new Hashtable<String, String>();
 env.put(Context.INITIAL_CONTEXT_FACTORY,
   "weblogic.jndi.WLInitialContextFactory");
 env.put(Context.PROVIDER_URL, "t3://localhost:8001/");
 return new InitialContext(env);
}
}

Extract all your service end points using a java utility

Often we may find a need for publishing the endpoints of all your service to a new client. Instead of getting the end points for each and every service from em console a java class would do that job quickly.



Code
================

package test;

import java.util.Hashtable;
import java.util.UUID;
import java.util.List;

import javax.naming.Context;

import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.Service;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.ComponentInstance;


import oracle.fabric.common.NormalizedMessage;
import oracle.fabric.common.NormalizedMessageImpl;

import oracle.soa.management.util.CompositeInstanceFilter;
import oracle.soa.management.util.ComponentInstanceFilter;


import java.util.Map;

import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.Element;
import java.io.*;

import oracle.soa.management.CompositeDN;
import oracle.soa.management.facade.Component;


public class EndpointLister {
    public EndpointLister() {
        super();

        Hashtable jndiProps = new Hashtable();
        jndiProps.put(Context.PROVIDER_URL, "t3://localhost:8001/soa-infra");
        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
        jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
        jndiProps.put(Context.SECURITY_CREDENTIALS, "weblogic1");
        jndiProps.put("dedicated.connection", "true");
     
 

        Locator locator = null;
        try {
            // connect to the soa server
            locator = LocatorFactory.createLocator(jndiProps);

            // find composite
            List composite = locator.listComposites();
         
            for(int i=0;i<composite.size();i++){
           
              CompositeDN lCompositeDN = (CompositeDN)composite.get(i);
              Composite lComposite = locator.lookupComposite(lCompositeDN);
              List lServices = lComposite.getServices();
           
              for(int j=0;j<lServices.size();j++){
              Service lService =(Service)lServices.get(j);
              System.out.println(lService.getWSDLURL());
              }
            }
        }
            catch( Exception E){
              E.printStackTrace();;
            }
              }



    public static void main(String[] args) {
        EndpointLister endpointLister = new EndpointLister();
    }
}

Dependent Jars
===================
servers\soa_server1\tmp\_WL_user\soa-infra\ztorh\soa-infra-mgmt.jar
oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar
wlserver_10.3\server\lib\weblogic.jar
oracle_common\modules\oracle.jrf_11.1.1\jrf-api.jar