package com.umessage.smscenter.sms.test;
import javax.jms.MessageListener;
import javax.naming.Context;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.QueueSender;
import javax.jms.QueueReceiver;
import javax.jms.Queue;
import java.io.Serializable;
import java.util.Properties;
import javax.jms.Message;
import javax.jms.JMSException;
/**
<p>Title:JMS demo </p>
<p>Description: </p>
<p>Copyright: Copyright (c) 2005</p>
<p>Company: </p>
@author lizongbo
@version 1.0
* Use this class to send and receive point-to-point messages.
* To send a text message:
* <code>
* JMSTest jMSTest = new JMSTest();
* jMSTest.sendText("Hello world");
* jMSTest.close(); //Release resources
* </code>
* To receive a message:
* <code>
* JMSTest jMSTest = new JMSTest();
* jMSTest.getQueueReceiver();
* </code>
*/
public class JMSTest implements MessageListener {
//上下文
private static Context context;
//是否触发事务
private boolean transacted = true;
//消息确认选项
private int acknowledgementMode = javax.jms.Session.AUTO_ACKNOWLEDGE;
//队列连接工厂
private QueueConnectionFactory queueConnectionFactory;
//队列连接
private QueueConnection queueConnection;
//队列会话
private QueueSession queueSession;
//消息发送者
private QueueSender queueSender;
//消息接受者
private QueueReceiver queueReceiver;
private Queue queue;
//队列连接工厂名
private String queueConnectionFactoryName = "smsConnectionFactory";
//发送消息队列
private String sendQueueName = "SendQueue";
//接收消息队列
private String recvQueueName = "ReceiveQueue";
public void setTransacted(boolean transacted) {
this.transacted = transacted;
}
/**
* Description:发送对象消息
* @param Serializable message
* @exception Exception
* @author xiaobian
*/
public void sendObject(Serializable message) throws Exception {
javax.jms.ObjectMessage objectMessage = getQueueSession().
createObjectMessage();
objectMessage.clearBody();
objectMessage.setObject(message);
getQueueSender().send(objectMessage);
if (isTransacted()) {
getQueueSession().commit();
}
}
/**
* Description:发送文本消息
* @param String message
* @exception Exception
* @author xiaobian
*/
public void sendText(String message) throws Exception {
javax.jms.TextMessage textMessage = getQueueSession().createTextMessage();
textMessage.clearBody();
textMessage.setText(message);
getQueueSender().send(textMessage);
if (isTransacted()) {
getQueueSession().commit();
}
}
public QueueReceiver getQueueReceiver() throws Exception {
if (queueReceiver == null) {
queueReceiver = getQueueSession().createReceiver(getRecvQueue());
queueReceiver.setMessageListener(this);
}
return queueReceiver;
}
public QueueSender getQueueSender() throws Exception {
if (queueSender == null) {
queueSender = getQueueSession().createSender(getSendQueue());
}
return queueSender;
}
public Queue getRecvQueue() throws Exception {
if (queue == null) {
Object obj = getContext().lookup(recvQueueName);
queue = (Queue) obj;
}
return queue;
}
public Queue getSendQueue() throws Exception {
if (queue == null) {
Object obj = getContext().lookup(sendQueueName);
queue = (Queue) obj;
}
return queue;
}
public QueueSession getQueueSession() throws Exception {
if (queueSession == null) {
queueSession = getQueueConnection().createQueueSession(isTransacted(),getAcknowledgementMode());
}
return queueSession;
}
public QueueConnection getQueueConnection() throws Exception {
if (queueConnection == null) {
queueConnection = getQueueConnectionFactory().createQueueConnection();
queueConnection.start();
}
return queueConnection;
}
public QueueConnectionFactory getQueueConnectionFactory() throws Exception {
if (queueConnectionFactory == null) {
Object obj = getContext().lookup(queueConnectionFactoryName);
queueConnectionFactory = (QueueConnectionFactory) obj;
}
return queueConnectionFactory;
}
public void setRecvQueueName(String recvQueueName) {
this.recvQueueName = recvQueueName;
}
public String getRecvQueueName() {
return recvQueueName;
}
public void setSendQueueName(String sendQueueName) {
this.sendQueueName = sendQueueName;
}
public String getSendQueueName() {
return sendQueueName;
}
public void setQueueConnectionFactoryName(String queueConnectionFactoryName) {
this.queueConnectionFactoryName = queueConnectionFactoryName;
}
public String getQueueConnectionFactoryName() {
return queueConnectionFactoryName;
}
public void setAcknowledgementMode(int acknowledgementMode) {
this.acknowledgementMode = acknowledgementMode;
}
public int getAcknowledgementMode() {
return acknowledgementMode;
}
public boolean isTransacted() {
return transacted;
}
/*
public static void main(String[] args) throws Exception {
JMSTest jt = new JMSTest();
jt.sendText("test jms Text message!!!--lizongbo " + new java.util.Date().toString());
jt.sendText("测试jms文本消息!!!--lizongbo" + new java.util.Date().toString());
}
*/
public Context getInitialContext() throws Exception {
// String url = "t3://*.*:7001";
// String user = null;
// String password = null;
String url = "t3://127.0.0.1:7001";
String user = "xiaobian";
String password = "12345678";
Properties properties;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS,password == null ? "" : password);
}
return new javax.naming.InitialContext(properties);
}
catch (Exception e) {
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
}
private Context getContext() throws Exception {
if (context == null) {
try {
context = getInitialContext();
}
catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
return context;
}
//消息监听器
public void onMessage(Message message) {
System.out.println("收到消息");
if (message instanceof javax.jms.BytesMessage) {
javax.jms.BytesMessage bytesMessage = (javax.jms.BytesMessage) message;
System.out.println("这是一个BytesMessage,内容是:" + bytesMessage);
/** @todo Process bytesMessage here */
}
else if (message instanceof javax.jms.MapMessage) {
javax.jms.MapMessage mapMessage = (javax.jms.MapMessage) message;
System.out.println("这是一个MapMessage,内容是:" + mapMessage);
/** @todo Process mapMessage here */
}
else if (message instanceof javax.jms.ObjectMessage) {
javax.jms.ObjectMessage objectMessage = (javax.jms.ObjectMessage) message;
System.out.println("这是一个objectMessage,内容是:" + objectMessage);
/** @todo Process objectMessage here */
}
else if (message instanceof javax.jms.StreamMessage) {
javax.jms.StreamMessage streamMessage = (javax.jms.StreamMessage) message;
System.out.println("这是一个StreamMessage,内容是:" + streamMessage);
/** @todo Process streamMessage here */
}
else if (message instanceof javax.jms.TextMessage) {
javax.jms.TextMessage objectMessage = (javax.jms.TextMessage) message;
System.out.println("这是一个TextMessage,内容是:" + objectMessage);
/** @todo Process textMessage here */
}
if (isTransacted()) {
try {
getQueueSession().commit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
public void close() throws Exception {
if (queueSender != null) {
queueSender.close();
}
if (queueReceiver != null) {
queueReceiver.close();
}
if (queueSession != null) {
queueSession.close();
}
if (queueConnection != null) {
queueConnection.close();
}
System.out.println("关闭资源");
}
}
package com.umessage.smscenter.sms.test;
/**
*
<p>Title:JMS demo </p>
<p>Description: </p>
<p>Copyright: Copyright (c) 2005</p>
<p>Company: </p>
@author lizongbo
@version 1.0
*/
public class JMSFetchTest {
public JMSFetchTest() {
super();
}
public static void main(String[] args) throws Exception {
JMSTest jt = new JMSTest();
jt.getQueueReceiver();
synchronized (jt) {
jt.wait(3000);
}
jt.sendObject("JMS消息测试");
// jt.sendText("消息测试");
// jt.sendText("消息测试");
// System.out.println("结束");
// jt.close();
}
}
分享到:
相关推荐
本压缩包文件"weblogic-server_jdbc.rar_weblogic"聚焦于WebLogic Server与JDBC(Java Database Connectivity)的整合,通过图形化的界面简化了数据库连接的复杂过程。 JDBC是Java语言中用于访问数据库的标准API,...
4. **设置Plugin配置文件**:创建或修改`weblogic-plugin.conf`文件,定义WebLogic Server的相关信息,如URL、端口、集群等。 5. **重启Apache**:完成配置后,重启Apache以使更改生效。 **安全性与优化**: 集成...
《Weblogic-CVE-2019-2725补丁升级方法详解》 WebLogic Server是一款由甲骨文公司开发的企业级应用服务器,它为构建、部署和管理企业级Java应用程序提供了全面的平台。然而,随着技术的发展,安全漏洞的出现是不可...
它包含了多种服务、API和容器,如Java Servlet、JavaServer Pages (JSP)、Java Persistence API (JPA) 和 Java Message Service (JMS)等,这些组件共同为开发人员提供了一个强大的后端开发环境。 Petstore应用是一...
Weblogic反序列化远程代码执行漏洞(CVE-2018-2893)是Oracle WebLogic Server中一个严重安全问题,它涉及到组件T3协议处理中的对象反序列化过程。该漏洞允许攻击者通过构造恶意的T3请求,远程执行任意代码,从而...
自用CVE-2018-3191 weblogic反序列化exp。
此外,它还集成了各种服务器适配器,如Tomcat, GlassFish, WebLogic等,使得与这些服务器的交互变得更加便捷。 Eclipse Mars 2的特性包括: 1. **改进的代码编辑器**:提供智能代码补全、语法高亮、错误检查等功能...
Weblogic JMS 依赖jar包是Oracle公司的中间件产品Weblogic Server中用于实现Java Message Service (JMS) 功能的关键组件。JMS是一种标准API,它允许应用程序在分布式环境中发送和接收消息,提供了异步通信的能力。在...
BEA WebLogic Server Products (Product, Version, License ID/file) ================================================================ BEA WebLogic Server Advantage Edition 10.0 - 10.0mp1 LIC-WLSA10.txt ...
在本文中,我们将深入探讨如何进行`weblogic9-jms-applet`的开发,涵盖从Applet的基础知识到WebLogic 9.2的JMS配置,以及相关注意事项和一个简单的JNI实例。让我们逐步解析这个过程。 **1. Applet基础问题** ...
【K8 weblogic-CVE-2018-2628-getshell】是一个针对Oracle WebLogic Server的渗透测试工具,主要用于检验系统是否存在CVE-2018-2628漏洞并利用该漏洞获取shell权限。这个工具的使用应该严格限制在合法的安全测试环境...
验证是否存在cve-2018-2628漏洞
WebLogic cve-2017-3506_webshell.jar利用工具
tar -xzf weblogic-server-10.3.6.0.tar.gz ``` 3. **创建Domain**:WebLogic Server的部署需要一个域(Domain),这是管理服务器、集群、应用程序和其他资源的基本单位。通过执行`WLST`(WebLogic Scripting ...
### WebLogic-CEV 反序列化漏洞及P28483404补丁安装升级指南 #### 一、WebLogic-CEV反序列化漏洞简介 WebLogic-CEV反序列化漏洞是一种常见的高危漏洞,该漏洞允许攻击者通过远程执行恶意代码或者上传文件等方式对...
weblogic-CVE-2023-21839-JNDIExploit-1.4-SNAPSHOT.jar
《Ant与WebLogic集成:深度解析ant-weblogic-1.6.2.jar.zip》 在IT行业中,构建和部署Java应用程序是一项重要的任务,而Apache Ant和Oracle WebLogic Server是两个在此过程中发挥关键作用的工具。Ant是一个基于Java...