Forum Stats

  • 3,826,547 Users
  • 2,260,663 Discussions
  • 7,896,992 Comments

Discussions

Failed to connect to weblogic topic using java

User_TT8YT
User_TT8YT Member Posts: 1 Blue Ribbon

Hi,

I am trying to connect to weblgic topic using java code. Here is my code

package com.oracle.xml.notification;


import com.oracle.schemas.soa.fault.Commonfault;


import javax.faces.bean.ManagedBean;


import java.io.StringWriter;


import java.math.BigInteger;


import java.util.Hashtable;


import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBException;

import javax.xml.bind.Marshaller;


import javax.naming.InitialContext;

import javax.naming.*;


import javax.jms.*;


import javax.jms.Topic;

import javax.jms.Session;

import javax.jms.TextMessage;

import javax.jms.TopicPublisher;

import javax.jms.DeliveryMode;

import javax.jms.JMSException;

import javax.jms.TopicSession;

import javax.jms.TopicConnection;

import javax.jms.TopicConnectionFactory;


import javax.naming.NamingException;


@ManagedBean(name = "SendNotificationToQueue")

public class SendNotificationToQueue {


  // Defines the JNDI context factory.

  public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";


  // Defines the JMS context factory.

  public final static String JMS_FACTORY = "jms/Notification";


  // Defines the topic.

  public final static String MyTOPIC = "jms/Notification_Topic";


  // Defines the WebLogic URL. The port is for the Managed Server or

  // the Admin Server where the JMS Server is running.

  public final static String WebLogicURL = "t3s://fmwsoaupgnrldev.adr.alcoa.com:7211";



  public static void main(String args[]) throws JAXBException {

    SendNotificationToQueue sendNotificationToQueue = new SendNotificationToQueue();

    Commonfault inputXML = new Commonfault();

    inputXML.setInterfaceDetail("ID");

    inputXML.setComponentName("ComponentName");

    inputXML.setCompositeDN("CompisiteName");

    inputXML.setEngineType("EngineType");


    inputXML.setFaultName("FaultName");

    inputXML.setFaultType("FaultType");

    inputXML.setFlowID(new BigInteger("1234"));

    inputXML.setMessage("Message");


    JAXBContext jaxbContext = JAXBContext.newInstance(Commonfault.class);

    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    StringWriter sw = new StringWriter();

    jaxbMarshaller.marshal(inputXML, sw);

    String xmlContent = sw.toString();

    System.out.println(xmlContent);

    try {

      sendNotificationToQueue.publishToTopic(xmlContent);

    } catch (Exception e) {

      System.out.println("Exception occured ##############################" + e.getMessage());

    }


  }


  public void publishToTopic(String message) throws NamingException, JMSException {

    Hashtable env = new Hashtable();

    env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);

    env.put(Context.PROVIDER_URL, WebLogicURL);

     

    System.out.println("111111111111111111111111111111111111");

    InitialContext ic = new InitialContext(env);

    System.out.println("222222222222222222222222222222");

    TopicConnectionFactory f = (TopicConnectionFactory) ic.lookup(JMS_FACTORY);

    System.out.println("333333333333333333333333333333333");

    TopicConnection con = f.createTopicConnection();

    System.out.println("4444444444444444444444444444444");

    con.start();


    //2) create topic session

    TopicSession ses = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);


    //3) get the Topic object

    Topic topic = (Topic) ic.lookup(MyTOPIC);

    //4)create topic publisher

    TopicPublisher topicPublisher = ses.createPublisher(topic);

    topicPublisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);


    //5) create TextMessage object

    TextMessage msg = ses.createTextMessage();

    msg.setText(message);


    //7) send message

    topicPublisher.publish(msg);


    System.out.println("Message successfully published: " + msg);


    //8) connection close

    con.close();


  }

}


I am getting following error.


Exception occured ##############################Unable to resolve 'jms.Notification_Topic'. Resolved 'jms'

Can anyone help?

Answers