Compare commits

...

2 Commits

Author SHA1 Message Date
Peter Hormanns
8409ede74b v4.0.15 2023-08-05 19:56:23 +02:00
Peter Hormanns
f2ee187eaf set trusted packages in code 2023-08-05 19:51:30 +02:00
8 changed files with 68 additions and 57 deletions

View File

@ -5,7 +5,7 @@
<groupId>de.hsadmin</groupId> <groupId>de.hsadmin</groupId>
<artifactId>hsar</artifactId> <artifactId>hsar</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>4.0.14</version> <version>4.0.15</version>
<name>HSAdmin Stable Backend Webapp</name> <name>HSAdmin Stable Backend Webapp</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>
@ -36,12 +36,12 @@
<dependency> <dependency>
<groupId>de.hsadmin.core</groupId> <groupId>de.hsadmin.core</groupId>
<artifactId>hsadmin-util</artifactId> <artifactId>hsadmin-util</artifactId>
<version>4.0.14</version> <version>4.0.15</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>de.hsadmin.core</groupId> <groupId>de.hsadmin.core</groupId>
<artifactId>hsadmin-qserv</artifactId> <artifactId>hsadmin-qserv</artifactId>
<version>4.0.14</version> <version>4.0.15</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-httpclient</groupId> <groupId>commons-httpclient</groupId>

View File

@ -2,7 +2,6 @@ package de.hsadmin.servlets;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Set;
import javax.jms.ExceptionListener; import javax.jms.ExceptionListener;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -27,8 +26,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import de.hsadmin.core.model.TechnicalException; import de.hsadmin.core.model.TechnicalException;
import de.hsadmin.core.model.TicketValidator; import de.hsadmin.core.model.TicketValidator;
@ -43,6 +41,8 @@ public class QueueStatusReceiverServlet extends HttpServlet
private static final long serialVersionUID = -5701350884034782083L; private static final long serialVersionUID = -5701350884034782083L;
private static boolean initQueuesDone = false;
private String jmsUser; private String jmsUser;
private String jmsPass; private String jmsPass;
private QueueConnectionFactory queueConnectionFactory; private QueueConnectionFactory queueConnectionFactory;
@ -61,6 +61,14 @@ public class QueueStatusReceiverServlet extends HttpServlet
isConnected = false; isConnected = false;
messageCount = 0; messageCount = 0;
errorCount = 0; errorCount = 0;
try {
if (!initQueuesDone) {
initQueues();
}
initQueuesDone = true;
} catch (NamingException e) {
throw new ServletException(e);
}
try { try {
connect(); connect();
} catch (NamingException e) { } catch (NamingException e) {
@ -72,6 +80,35 @@ public class QueueStatusReceiverServlet extends HttpServlet
Config config = Config.getInstance(); Config config = Config.getInstance();
jmsUser = config.getProperty("hsadmin.jms.username", "hsadmin"); jmsUser = config.getProperty("hsadmin.jms.username", "hsadmin");
jmsPass = config.getProperty("hsadmin.jms.password", "hsadmin-pw"); jmsPass = config.getProperty("hsadmin.jms.password", "hsadmin-pw");
InitialContext ctx = new InitialContext();
Context env = (Context) ctx.lookup("java:comp/env");
queueConnectionFactory = (QueueConnectionFactory) env.lookup("jms/QueueCF");
if (queueConnectionFactory instanceof ActiveMQConnectionFactory) {
ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) queueConnectionFactory;
activeMQConnectionFactory.setTrustAllPackages(true);
}
int timeoutCounter = 10;
while (!isConnected && (timeoutCounter > 0)) {
try {
queueConnection = queueConnectionFactory.createQueueConnection(jmsUser, jmsPass);
queueConnection.setExceptionListener(this);
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) env.lookup("jms/hsadminStatus");
queueConnection.start();
QueueReceiver receiver = queueSession.createReceiver(queue);
receiver.setMessageListener(this);
isConnected = true;
} catch (JMSException e) {
close();
try {
timeoutCounter--;
Thread.sleep(2000);
} catch (InterruptedException e1) { }
}
}
}
private void initQueues() throws NamingException {
InitialContext ctx = new InitialContext(); InitialContext ctx = new InitialContext();
NamingEnumeration<NameClassPair> list = ctx.list("java:comp/env/jms"); NamingEnumeration<NameClassPair> list = ctx.list("java:comp/env/jms");
Transaction transaction = new Transaction("anonymous"); Transaction transaction = new Transaction("anonymous");
@ -91,43 +128,7 @@ public class QueueStatusReceiverServlet extends HttpServlet
} }
transaction.commitTransaction(); transaction.commitTransaction();
transaction.close(); transaction.close();
Context env = (Context) ctx.lookup("java:comp/env"); ctx.close();
queueConnectionFactory = (QueueConnectionFactory) env.lookup("jms/QueueCF");
int timeoutCounter = 10;
while (!isConnected && (timeoutCounter > 0)) {
try {
queueConnection = queueConnectionFactory.createQueueConnection(jmsUser, jmsPass);
queueConnection.setExceptionListener(this);
if (queueConnection instanceof ActiveMQConnection) {
checkQueues((ActiveMQConnection) queueConnection, new PrintWriter(System.out));
}
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) env.lookup("jms/hsadminStatus");
queueConnection.start();
QueueReceiver receiver = queueSession.createReceiver(queue);
receiver.setMessageListener(this);
isConnected = true;
} catch (JMSException e) {
close();
try {
timeoutCounter--;
Thread.sleep(2000);
} catch (InterruptedException e1) { }
}
}
}
private void checkQueues(ActiveMQConnection amqConn, PrintWriter writer) {
try {
writer.print("\n");
Set<ActiveMQQueue> queues = amqConn.getDestinationSource().getQueues();
for (ActiveMQQueue queue : queues) {
writer.print("Phys: " + queue.getPhysicalName() + " - Qual: " + queue.getQualifiedName() + "\n");
}
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
@Override @Override
@ -138,9 +139,6 @@ public class QueueStatusReceiverServlet extends HttpServlet
writer.println("Verbindungsstatus: " + (isConnected ? "OK" : "ERROR")); writer.println("Verbindungsstatus: " + (isConnected ? "OK" : "ERROR"));
writer.println("Verarbeitete Nachrichten: " + messageCount); writer.println("Verarbeitete Nachrichten: " + messageCount);
writer.println("Verarbeitungsfehler: " + errorCount); writer.println("Verarbeitungsfehler: " + errorCount);
if (queueConnection instanceof ActiveMQConnection) {
checkQueues((ActiveMQConnection) queueConnection, writer);
}
writer.close(); writer.close();
} }

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.hsadmin</groupId> <groupId>de.hsadmin</groupId>
<artifactId>hsadmin-qserv</artifactId> <artifactId>hsadmin-qserv</artifactId>
<version>4.0.14</version> <version>4.0.15</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HSAdmin-QServ</name> <name>HSAdmin-QServ</name>
@ -20,7 +20,7 @@
<dependency> <dependency>
<groupId>de.hsadmin.core</groupId> <groupId>de.hsadmin.core</groupId>
<artifactId>hsadmin-qserv</artifactId> <artifactId>hsadmin-qserv</artifactId>
<version>4.0.14</version> <version>4.0.15</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.activemq</groupId> <groupId>org.apache.activemq</groupId>

View File

@ -5,7 +5,7 @@ After=network.target nss-lookup.target
[Service] [Service]
Type=simple Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" Environment="PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
Environment="JAVA_OPTS=-Xbootclasspath/a:/etc/hsadmin/qserv/ -Djavax.net.ssl.keyStore=/etc/hsadmin/qserv/keystore -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=/etc/hsadmin/qserv/truststore -Djavax.net.ssl.trustStorePassword=password -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=java.lang,javax.security,java.util,org.apache.activemq,org.fusesource.hawtbuf,com.thoughtworks.xstream.mapper,de.hsadmin.core.qserv,de.hsadmin.mods.cust,de.hsadmin.mods.db,de.hsadmin.mods.dom,de.hsadmin.mods.email,de.hsadmin.mods.pac,de.hsadmin.mods.qstat,de.hsadmin.mods.user" Environment="JAVA_OPTS=-Xbootclasspath/a:/etc/hsadmin/qserv/ -Djavax.net.ssl.keyStore=/etc/hsadmin/qserv/keystore -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=/etc/hsadmin/qserv/truststore -Djavax.net.ssl.trustStorePassword=password -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*"
ExecStart=/usr/bin/java $JAVA_OPTS -jar /usr/local/lib/hostsharing/hsadmin/hsadmin-qserv-full.jar /etc/hsadmin/qserv/qserv.properties ExecStart=/usr/bin/java $JAVA_OPTS -jar /usr/local/lib/hostsharing/hsadmin/hsadmin-qserv-full.jar /etc/hsadmin/qserv/qserv.properties
StandardOutput=file:/var/log/hostsharing/hsadmin/hsar-qserv.err StandardOutput=file:/var/log/hostsharing/hsadmin/hsar-qserv.err
StandardError=inherit StandardError=inherit

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.hsadmin.core</groupId> <groupId>de.hsadmin.core</groupId>
<artifactId>hsadmin-qserv</artifactId> <artifactId>hsadmin-qserv</artifactId>
<version>4.0.14</version> <version>4.0.15</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version> <java.version>11</java.version>
@ -13,7 +13,7 @@
<dependency> <dependency>
<groupId>de.hsadmin.core</groupId> <groupId>de.hsadmin.core</groupId>
<artifactId>hsadmin-util</artifactId> <artifactId>hsadmin-util</artifactId>
<version>4.0.14</version> <version>4.0.15</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>

View File

@ -15,6 +15,7 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import javax.persistence.Query; import javax.persistence.Query;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.openjpa.persistence.OpenJPAEntityManager; import org.apache.openjpa.persistence.OpenJPAEntityManager;
import de.hsadmin.core.qserv.QueueClient; import de.hsadmin.core.qserv.QueueClient;
@ -42,6 +43,10 @@ public class Transaction {
ctx = new InitialContext(); ctx = new InitialContext();
Context env = (Context) ctx.lookup("java:comp/env"); Context env = (Context) ctx.lookup("java:comp/env");
queueConnectionFactory = (QueueConnectionFactory) env.lookup("jms/QueueCF"); queueConnectionFactory = (QueueConnectionFactory) env.lookup("jms/QueueCF");
if (queueConnectionFactory instanceof ActiveMQConnectionFactory) {
ActiveMQConnectionFactory activeMQconnectionFatory = (ActiveMQConnectionFactory) queueConnectionFactory;
activeMQconnectionFatory.setTrustAllPackages(true);
}
} catch (NamingException e) { } catch (NamingException e) {
throw new TechnicalException("no jms queue: jms/QueueCF", e); throw new TechnicalException("no jms queue: jms/QueueCF", e);
} }

View File

@ -7,7 +7,6 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination; import javax.jms.Destination;
import javax.jms.ExceptionListener; import javax.jms.ExceptionListener;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -24,6 +23,8 @@ import javax.jms.Session;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import org.apache.activemq.ActiveMQConnectionFactory;
public class QueueServer extends QueueCommons implements MessageListener, ExceptionListener { public class QueueServer extends QueueCommons implements MessageListener, ExceptionListener {
private static final String VERSION_NO = "4.0.11"; private static final String VERSION_NO = "4.0.11";
@ -84,7 +85,7 @@ public class QueueServer extends QueueCommons implements MessageListener, Except
} }
}); });
while (!qServ.connect()) { while (!qServ.connect()) {
Thread.sleep(120000); Thread.sleep(30000);
} }
while (true) { while (true) {
Thread.sleep(10000); Thread.sleep(10000);
@ -129,8 +130,11 @@ public class QueueServer extends QueueCommons implements MessageListener, Except
// create JMS connection and session // create JMS connection and session
try { try {
Context ctx = new InitialContext(); Context ctx = new InitialContext();
QueueConnectionFactory connectionFactory = QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup(jmsFactory);
(QueueConnectionFactory) ctx.lookup(jmsFactory); if (connectionFactory instanceof ActiveMQConnectionFactory) {
ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) connectionFactory;
activeMQConnectionFactory.setTrustAllPackages(true);
}
conn = connectionFactory.createQueueConnection(jmsUserName, jmsPassWord); conn = connectionFactory.createQueueConnection(jmsUserName, jmsPassWord);
conn.setExceptionListener(this); conn.setExceptionListener(this);
queueSession = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueSession = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
@ -211,7 +215,11 @@ public class QueueServer extends QueueCommons implements MessageListener, Except
try { try {
logger.log(Level.INFO, "sendStatus(" + queueMessage + ")"); logger.log(Level.INFO, "sendStatus(" + queueMessage + ")");
Context ctx = new InitialContext(); Context ctx = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(jmsFactory); QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup(jmsFactory);
if (connectionFactory instanceof ActiveMQConnectionFactory) {
ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) connectionFactory;
activeMQConnectionFactory.setTrustAllPackages(true);
}
Destination queue = (Destination) ctx.lookup(jmsStatusQueue); Destination queue = (Destination) ctx.lookup(jmsStatusQueue);
statusConnection = connectionFactory.createConnection(jmsUserName, jmsPassWord); statusConnection = connectionFactory.createConnection(jmsUserName, jmsPassWord);
statusSession = statusConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); statusSession = statusConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.hsadmin.core</groupId> <groupId>de.hsadmin.core</groupId>
<artifactId>hsadmin-util</artifactId> <artifactId>hsadmin-util</artifactId>
<version>4.0.14</version> <version>4.0.15</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version> <java.version>11</java.version>