Я пытаюсь выполнить простой пример JMS Java EE по следующему URL: https://javaee.github.io/tutorial/jms-examples003.html#GKTJS До этого раздела все было в порядке: https://javaee.github.io/tutorial/jms-examples003.html#to-run-the-producer-client
Код, выполняемый при возникновении проблем, выглядит следующим образом:
/**
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
*
* You may not modify, use, reproduce, or distribute this software except in
* compliance with the terms of the License at:
* https://github.com/javaee/tutorial-examples/LICENSE.txt
*/
package javaeetutorial.producer;
import javax.annotation.Resource;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.jms.JMSRuntimeException;
import javax.jms.Queue;
import javax.jms.Topic;
/**
* The Producer class consists only of a main method, which sends several
* messages to a queue or topic.
*
* Run this program in conjunction with SynchConsumer or AsynchConsumer. Specify
* "queue" or "topic" on the command line when you run the program. By default,
* the program sends one message. Specify a number after the destination name to
* send that number of messages.
*/
public class Producer {
@Resource(lookup = "java:comp/DefaultJMSConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "jms/MyQueue")
private static Queue queue;
@Resource(lookup = "jms/MyTopic")
private static Topic topic;
/**
* Main method.
*
* @param args the destination used by the example and, optionally, the
* number of messages to send
*/
public static void main(String[] args) {
final int NUM_MSGS;
if ((args.length < 1) || (args.length > 2)) {
System.err.println(
"Program takes one or two arguments: "
+ "<dest_type> [<number-of-messages>]");
System.exit(1);
}
String destType = args[0];
System.out.println("Destination type is " + destType);
if (!(destType.equals("queue") || destType.equals("topic"))) {
System.err.println("Argument must be \"queue\" or " + "\"topic\"");
System.exit(1);
}
if (args.length == 2) {
NUM_MSGS = (new Integer(args[1])).intValue();
} else {
NUM_MSGS = 1;
}
Destination dest = null;
try {
if (destType.equals("queue")) {
dest = (Destination) queue;
} else {
dest = (Destination) topic;
}
} catch (JMSRuntimeException e) {
System.err.println("Error setting destination: " + e.toString());
System.exit(1);
}
/*
* Within a try-with-resources block, create context.
* Create producer and message.
* Send messages, varying text slightly.
* Send end-of-messages message.
*/
try (JMSContext context = connectionFactory.createContext();) {
int count = 0;
for (int i = 0; i < NUM_MSGS; i++) {
String message = "This is message " + (i + 1)
+ " from producer";
// Comment out the following line to send many messages
System.out.println("Sending message: " + message);
context.createProducer().send(dest, message);
count += 1;
}
System.out.println("Text messages sent: " + count);
/*
* Send a non-text control message indicating end of
* messages.
*/
context.createProducer().send(dest, context.createMessage());
// Uncomment the following line if you are sending many messages
// to two synchronous consumers
// context.createProducer().send(dest, context.createMessage());
} catch (JMSRuntimeException e) {
System.err.println("Exception occurred: " + e.toString());
System.exit(1);
}
System.exit(0);
}
}
Существует также файл glassfish-resources.xml со следующим кодом:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<admin-object-resource enabled="true" jndi-name="jms/MyQueue" object-type="user" res-adapter="jmsra" res-type="javax.jms.Queue">
<description/>
<property name="Name" value="PhysicalQueue"/>
</admin-object-resource>
<admin-object-resource enabled="true" jndi-name="jms/MyTopic" object-type="user" res-adapter="jmsra" res-type="javax.jms.Topic">
<description/>
<property name="Name" value="PhysicalTopic"/>
</admin-object-resource>
</resources>
Этот XML-файл используется следующим образом:
asadmin add-resources src/main/setup/glassfish-resources.xml
Эта команда создает места назначения для очереди и темы. Я могу просмотреть их в консоли администратора GlassFish. Пожалуйста, смотрите скриншот этого ниже:
Программа запускается следующим образом:
appclient -client target/producer.jar queue 3
В этот момент я получил все эти ошибки:
C:\glassfish5\java_ee_sdk-8\glassfish5\docs\javaee-tutorial\examples\jms\simple\
producer>appclient -client target/producer.jar queue 3
org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort vmcid: OMG minor
code: 8 completed: Maybe
at com.sun.proxy.$Proxy38.connectionAbort(Unknown Source)
at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrateg
y(ConnectionImpl.java:1287)
at com.sun.corba.ee.impl.transport.ConnectionImpl.doWork(ConnectionImpl.
java:845)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performW
ork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(Thre
adPoolImpl.java:540)
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410011: IOException received when
reading from connection SocketOrChannelConnectionImpl[ java.nio.channels.Socket
Channel[connected local=/127.0.0.1:12255 remote=localhost/127.0.0.1:3700] ESTABL
ISHED true true] vmcid: OMG minor code: 11 completed: No
at com.sun.proxy.$Proxy38.ioexceptionWhenReadingConnection(Unknown Sourc
e)
at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(Connec
tionImpl.java:1465)
at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrateg
y(ConnectionImpl.java:1241)
... 3 more
Caused by: java.io.IOException: End-of-stream
at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(Connec
tionImpl.java:1458)
... 4 more
com.sun.enterprise.container.common.spi.util.InjectionException: Exception attem
pting to inject Res-Ref-Env-Property: javaeetutorial.producer.Producer/connectio
nFactory@javax.jms.ConnectionFactory@ resolved as: jndi: java:comp/DefaultJMSCon
nectionFactory@res principal: null@mail: null
No Runtime properties
Database Vendor : null
Create Tables at Deploy : false
Delete Tables at Undeploy : false into class javaeetutorial.producer.Producer: L
ookup failed for 'java:comp/env/javaeetutorial.producer.Producer/connectionFacto
ry' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.namin
g.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise
.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDISt
ateFactoryImpl}
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._i
nject(InjectionManagerImpl.java:740)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.in
ject(InjectionManagerImpl.java:507)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.in
jectClass(InjectionManagerImpl.java:235)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.in
jectClass(InjectionManagerImpl.java:227)
at org.glassfish.appclient.client.acc.AppClientContainer$ClientMainClass
Setting.getClientMainClass(AppClientContainer.java:636)
at org.glassfish.appclient.client.acc.AppClientContainer.getMainMethod(A
ppClientContainer.java:525)
at org.glassfish.appclient.client.acc.AppClientContainer.completePrepara
tion(AppClientContainer.java:419)
at org.glassfish.appclient.client.acc.AppClientContainer.prepare(AppClie
ntContainer.java:320)
at org.glassfish.appclient.client.AppClientFacade.prepareACC(AppClientFa
cade.java:283)
at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.prem
ain(AppClientContainerAgent.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Instrumenta
tionImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Instrument
ationImpl.java:401)
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/javaee
tutorial.producer.Producer/connectionFactory' in SerialContext[myEnv={java.namin
g.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.
naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com
.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is jav
ax.naming.NamingException: Lookup failed for 'java:comp/DefaultJMSConnectionFact
ory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.nami
ng.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterpris
e.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIS
tateFactoryImpl, com.sun.enterprise.naming.logicalName=java:comp/env/javaeetutor
ial.producer.Producer/connectionFactory} [Root exception is javax.naming.NamingE
xception: Lookup failed for 'jms/__defaultConnectionFactory' in SerialContext[my
Env={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContex
tFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.fa
ctory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root e
xception is javax.naming.NamingException: Unable to acquire SerialContextProvide
r for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming
.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.
naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDISta
teFactoryImpl} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Co
nnection abort vmcid: OMG minor code: 8 completed: Maybe]]]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:438)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._i
nject(InjectionManagerImpl.java:638)
... 15 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/DefaultJMS
ConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.e
nterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com
.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presenta
tion.rmi.JNDIStateFactoryImpl, com.sun.enterprise.naming.logicalName=java:comp/e
nv/javaeetutorial.producer.Producer/connectionFactory} [Root exception is javax.
naming.NamingException: Lookup failed for 'jms/__defaultConnectionFactory' in Se
rialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.Se
rialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactor
yImpl} [Root exception is javax.naming.NamingException: Unable to acquire Serial
ContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.ent
erprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.s
un.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentati
on.rmi.JNDIStateFactoryImpl} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE
: 00410008: Connection abort vmcid: OMG minor code: 8 completed: Maybe]]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:438)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNam
ingObjectFactory.java:90)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(Glas
sfishNamingManagerImpl.java:745)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(Glas
sfishNamingManagerImpl.java:715)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.j
ava:159)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:471)
... 18 more
Caused by: javax.naming.NamingException: Lookup failed for 'jms/__defaultConnect
ionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterpri
se.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.en
terprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rm
i.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable
to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.in
itial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.facto
ry.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.e
e.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is org.omg.CORBA.C
OMM_FAILURE: FINE: 00410008: Connection abort vmcid: OMG minor code: 8 complet
ed: Maybe]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:438)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.sun.enterprise.connectors.jms.system.DefaultJMSConnectionFactory.
handle(DefaultJMSConnectionFactory.java:84)
at com.sun.enterprise.naming.impl.NamedNamingObjectManager.tryNamedProxi
es(NamedNamingObjectManager.java:135)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.j
ava:164)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:471)
... 25 more
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider
for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.
impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.n
aming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStat
eFactoryImpl} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Con
nection abort vmcid: OMG minor code: 8 completed: Maybe]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContex
t.java:334)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.jav
a:477)
... 31 more
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort vmcid:
OMG minor code: 8 completed: Maybe
at com.sun.proxy.$Proxy38.connectionAbort(Unknown Source)
at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrateg
y(ConnectionImpl.java:1287)
at com.sun.corba.ee.impl.transport.ConnectionImpl.doWork(ConnectionImpl.
java:845)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performW
ork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(Thre
adPoolImpl.java:540)
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410011: IOException received when
reading from connection SocketOrChannelConnectionImpl[ java.nio.channels.Socket
Channel[connected local=/127.0.0.1:12255 remote=localhost/127.0.0.1:3700] ESTABL
ISHED true true] vmcid: OMG minor code: 11 completed: No
at com.sun.proxy.$Proxy38.ioexceptionWhenReadingConnection(Unknown Sourc
e)
at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(Connec
tionImpl.java:1465)
at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrateg
y(ConnectionImpl.java:1241)
... 3 more
Caused by: java.io.IOException: End-of-stream
at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(Connec
tionImpl.java:1458)
... 4 more
C:\glassfish5\java_ee_sdk-8\glassfish5\docs\javaee-tutorial\examples\jms\simple\
producer>
Я знаю, что сервер Glassfish работает, потому что я могу войти в консоль администрирования. Я заметил, что часть сообщения об ошибке исключения упоминает базу данных. Эта часть сообщения выглядит следующим образом: ConnectionFactory @ разрешается как: jndi: java: comp / DefaultJMSCon
nectionFactory @ res принципал: ноль @ почта: ноль
Нет Runtime-свойств
Поставщик базы данных: ноль
Создать таблицы при развертывании: false
Удалить таблицы при развертывании "
Я попытался запустить базу данных Derby, которая находится на сервере Glassfish, но получила ошибку. Я думаю, что это связано с номером порта. Мне нужно запустить базу данных по определенному номеру порта ... Может быть ... 0_O
Кто-нибудь знает, что происходит не так? Я пытаюсь изучить JMS, Java EE. Я просто следую инструкциям. Я понятия не имею, что происходит не так. Я думаю, что основная проблема заключается в следующих типах исключений:
com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Res-Ref-Env-Property: javaeetutorial.producer.Producer/connectionFactory@javax.jms.ConnectionFactory@ resolved as: jndi: java:comp/DefaultJMSConnectionFactory@res principal: null@mail: null
У меня такое чувство, что я никогда не узнаю ответ на этот вопрос. : 0
ОБНОВЛЕНИЕ - Пример работает (для меня) сейчас
Ну, я не знаю, в чем причина проблемы, но я смог запустить пример. Я снова повторил пример и mvn clean install
пересобрал программу Producer.java. В этом типе приложения Java EE много «движущихся частей». Я понятия не имею, что пошло не так. 0_o На приведенном ниже снимке экрана показано, что пример работает без всех предыдущих ошибок и, как показано на веб-странице в верхней части этого сообщения.