Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Failed to connect to weblogic topic using java

User_TT8YTMay 18 2022 — edited May 18 2022

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?

Comments

843834
Did you include your parser jar file in the archive tag? Thats required.

<applet code="Some.class" archive="some.jar, parser.jar" width=100 height=200></applet>
843834
Thank you very much Sir. Please inform me of the methods involved in assigning duke-dollars so i can give you some.
1 - 2

Post Details

Added on May 18 2022
2 comments
222 views