diff --git a/java/src/org/exist/jms/messaging/MessagingJmsListener.java b/java/src/org/exist/jms/messaging/MessagingJmsListener.java index f467c838..f57d5444 100644 --- a/java/src/org/exist/jms/messaging/MessagingJmsListener.java +++ b/java/src/org/exist/jms/messaging/MessagingJmsListener.java @@ -53,6 +53,7 @@ import java.util.zip.GZIPInputStream; import static org.exist.jms.shared.Constants.*; +import static org.exist.jms.shared.ErrorCodes.*; /** * JMS message receiver. Passes call to XQuery callback function. @@ -254,7 +255,7 @@ private Sequence getContent(final Message msg) throws IOException, XPathExceptio // Unsupported JMS message type final String txt = String.format("Unsupported JMS Message type %s", msg.getClass().getCanonicalName()); - final XPathException ex = new XPathException(txt); + final XPathException ex = new XPathException(JMS021, txt); report.addListenerError(ex); LOG.error(txt); throw ex; @@ -394,7 +395,7 @@ private Sequence handleObjectMessage(final ObjectMessage msg) throws JMSExceptio } else { final String txt = String.format("Unable to convert the object %s", obj.toString()); - final XPathException ex = new XPathException(txt); + final XPathException ex = new XPathException(JMS022, txt); report.addListenerError(ex); LOG.error(txt); throw ex; @@ -445,12 +446,12 @@ private Sequence processXML(final byte[] data, final boolean isGzipped) throws X } else { final String txt = String.format("Received document is not valid: %s", validationReport.toString()); LOG.debug(txt); - throw new XPathException(txt); + throw new XPathException(JMS023, txt); } } catch (SAXException | ParserConfigurationException | IOException ex) { report.addListenerError(ex); - throw new XPathException(ex.getMessage()); + throw new XPathException(JMS003, ex.getMessage(), ex); } diff --git a/java/src/org/exist/jms/replication/publish/PublisherParameters.java b/java/src/org/exist/jms/replication/publish/PublisherParameters.java index c6b602aa..ad6cd846 100644 --- a/java/src/org/exist/jms/replication/publish/PublisherParameters.java +++ b/java/src/org/exist/jms/replication/publish/PublisherParameters.java @@ -26,8 +26,6 @@ import org.exist.jms.replication.shared.TransportException; import org.exist.jms.shared.Constants; -import javax.jms.DeliveryMode; -import javax.jms.Message; import javax.naming.Context; /** diff --git a/java/src/org/exist/jms/replication/publish/ReplicationTrigger.java b/java/src/org/exist/jms/replication/publish/ReplicationTrigger.java index a300a83a..fdb430e8 100644 --- a/java/src/org/exist/jms/replication/publish/ReplicationTrigger.java +++ b/java/src/org/exist/jms/replication/publish/ReplicationTrigger.java @@ -32,7 +32,6 @@ import org.exist.dom.persistent.DocumentImpl; import org.exist.jms.replication.shared.MessageHelper; import org.exist.jms.replication.shared.ReplicationGuard; -import org.exist.jms.replication.shared.TransportException; import org.exist.jms.shared.eXistMessage; import org.exist.storage.DBBroker; import org.exist.storage.txn.Txn; @@ -65,6 +64,7 @@ public class ReplicationTrigger extends SAXTrigger implements DocumentTrigger, C private boolean isJMSOrigin(final Txn transaction) { // Get originId. + @SuppressWarnings("deprecation") final String originId = transaction.getOriginId(); return StringUtils.startsWith(originId, JMS_EXTENSION_PKG); @@ -430,13 +430,9 @@ private void sendMessage(final eXistMessage msg) /* throws TriggerException */ sender.sendMessage(msg); - } catch (final TransportException ex) { - LOGGER.error(ex.getMessage(), ex); - //throw new TriggerException(ex.getMessage(), ex); - } catch (final Throwable ex) { LOGGER.error(ex.getMessage(), ex); - //throw new TriggerException(ex.getMessage(), ex); + //throw new TriggerException(ex.getMessage(), ex); TransportException } } diff --git a/java/src/org/exist/jms/replication/shared/ClientParameters.java b/java/src/org/exist/jms/replication/shared/ClientParameters.java index f78f4807..db2ebdde 100644 --- a/java/src/org/exist/jms/replication/shared/ClientParameters.java +++ b/java/src/org/exist/jms/replication/shared/ClientParameters.java @@ -40,7 +40,7 @@ public abstract class ClientParameters { // public static final String DESTINATION = Constants.DESTINATION; //"topic"; // public static final String CLIENT_ID = Constants.CLIENT_ID; //"client-id"; // public static final String PARAMETER_GROUPING = ".."; - + protected final Properties props = new Properties(); protected String connectionFactory = null; protected String clientId = null; protected String topic = null; @@ -49,8 +49,6 @@ public abstract class ClientParameters { protected String connectionUsername = null; protected String connectionPassword = null; - protected final Properties props = new Properties(); - /** * Retrieve configuration value when available as String. * diff --git a/java/src/org/exist/jms/replication/shared/MessageHelper.java b/java/src/org/exist/jms/replication/shared/MessageHelper.java index ba9b5820..42977c0e 100644 --- a/java/src/org/exist/jms/replication/shared/MessageHelper.java +++ b/java/src/org/exist/jms/replication/shared/MessageHelper.java @@ -183,6 +183,6 @@ public static void retrieveFromDocument(final Map props, final D } public static void retrieveFromCollection(final Map props, final Collection collection) { - props.put(EXIST_RESOURCE_CREATIONTIME, collection.getCreationTime()); + props.put(EXIST_RESOURCE_CREATIONTIME, collection.getMetadata().getCreated()); } } diff --git a/java/src/org/exist/jms/replication/subscribe/ReplicationJmsListener.java b/java/src/org/exist/jms/replication/subscribe/ReplicationJmsListener.java index 5cb079f6..65f1e667 100644 --- a/java/src/org/exist/jms/replication/subscribe/ReplicationJmsListener.java +++ b/java/src/org/exist/jms/replication/subscribe/ReplicationJmsListener.java @@ -118,8 +118,9 @@ public void onMessage(final Message msg) { if (StringUtils.isNotEmpty(localID)) { final String remoteID = msg.getStringProperty(Constants.EXIST_INSTANCE_ID); if (localID.equals(remoteID)) { - LOG.info("Incoming JMS messsage was originally sent by this instance. Processing stopped."); - return; // TODO: throw exception? probably not because message does not need to be re-received + LOG.info("Incoming JMS messsage was originally sent by this instance. Stopped processing."); + msg.acknowledge(); + return; // Do not throw exeception; Receive was OK } } diff --git a/java/src/org/exist/jms/send/Sender.java b/java/src/org/exist/jms/send/Sender.java index 4f823900..f1feea84 100644 --- a/java/src/org/exist/jms/send/Sender.java +++ b/java/src/org/exist/jms/send/Sender.java @@ -48,6 +48,7 @@ import java.util.zip.GZIPOutputStream; import static org.exist.jms.shared.Constants.*; +import static org.exist.jms.shared.ErrorCodes.*; //import org.exist.dom.persistent.NodeProxy; @@ -119,7 +120,7 @@ public NodeImpl send(final JmsConfiguration jmsConfig, final JmsMessagePropertie final ConnectionFactory cf = getConnectionFactoryInstance(context, jmsConfig); if (cf == null) { - throw new XPathException("Unable to create connection factory"); + throw new XPathException(JMS026, "Unable to create connection factory"); } // Setup username/password when required @@ -183,16 +184,16 @@ public NodeImpl send(final JmsConfiguration jmsConfig, final JmsMessagePropertie Throwable cause = ex.getCause(); - if("Error while attempting to add new Connection to the pool".contentEquals(ex.getMessage()) && cause!=null){ - throw new XPathException(cause.getMessage()); + if ("Error while attempting to add new Connection to the pool".contentEquals(ex.getMessage()) && cause != null) { + throw new XPathException(JMS004, cause.getMessage()); } else { - throw new XPathException(ex.getMessage()); + throw new XPathException(JMS004, ex.getMessage()); } } catch (final Throwable ex) { LOG.error(ex.getMessage(), ex); - throw new XPathException(ex.getMessage()); + throw new XPathException(JMS000, ex.getMessage()); } finally { try { @@ -278,8 +279,8 @@ private Message createMessageFromItem(final Session session, final Item item, fi IOUtils.copy(is, os); } catch (final IOException ex) { - LOG.error(ex); - throw new XPathException(ex); + LOG.error(ex.getMessage(), ex); + throw new XPathException(JMS001, ex.getMessage(), ex); } finally { IOUtils.closeQuietly(is); @@ -323,7 +324,7 @@ private Message createMessageFromItem(final Session session, final Item item, fi } catch (final IOException ex) { LOG.error(ex); - throw new XPathException(ex); + throw new XPathException(JMS001, ex.getMessage(), ex); } finally { IOUtils.closeQuietly(is); @@ -369,7 +370,7 @@ private Message createMessageFromItem(final Session session, final Item item, fi objectMessage.setObject(booleanValue); break; default: - throw new XPathException( + throw new XPathException(JMS027, String.format("Unable to convert '%s' of type '%s' into a JMS object.", item.getStringValue(), item.getType())); } diff --git a/java/src/org/exist/jms/shared/ErrorCodes.java b/java/src/org/exist/jms/shared/ErrorCodes.java new file mode 100644 index 00000000..e0f4c6ea --- /dev/null +++ b/java/src/org/exist/jms/shared/ErrorCodes.java @@ -0,0 +1,63 @@ +/* + * eXist Open Source Native XML Database + * Copyright (C) 2013 The eXist Project + * http://exist-db.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +package org.exist.jms.shared; + +import org.exist.dom.QName; +import org.exist.xquery.ErrorCodes.ErrorCode; + +import static org.exist.jms.xquery.JmsModule.NAMESPACE_URI; +import static org.exist.jms.xquery.JmsModule.PREFIX; + +/** + * ErrorCodes definition + */ +public class ErrorCodes { + + public final static ErrorCode JMS000 = new JmsErrorCode("JMS000", "Generic exception."); + public final static ErrorCode JMS001 = new JmsErrorCode("JMS001", "Internal IO error."); + public final static ErrorCode JMS002 = new JmsErrorCode("JMS002", "Function does not exist."); + public final static ErrorCode JMS003 = new JmsErrorCode("JMS003", "XML parse(r) error."); + public final static ErrorCode JMS004 = new JmsErrorCode("JMS004", "Generic JMS Exception."); + + public final static ErrorCode JMS010 = new JmsErrorCode("JMS010", "Unauthorized usage."); + public final static ErrorCode JMS011 = new JmsErrorCode("JMS011", "Configuration error."); + + public final static ErrorCode JMS020 = new JmsErrorCode("JMS020", "Receiver does not exist."); + public final static ErrorCode JMS021 = new JmsErrorCode("JMS021", "Unsupported JMS message."); + public final static ErrorCode JMS022 = new JmsErrorCode("JMS022", "Unable to convert JMS ObjectMessage to object."); + public final static ErrorCode JMS023 = new JmsErrorCode("JMS023", "Received XML document is not valid."); + + public final static ErrorCode JMS025 = new JmsErrorCode("JMS025", "JMS connection is not initialized."); + public final static ErrorCode JMS026 = new JmsErrorCode("JMS026", "No ConnectionFactory."); + public final static ErrorCode JMS027 = new JmsErrorCode("JMS027", "Unable to convert object to JMS ObjectMessage."); + + public final static ErrorCode JMS030 = new JmsErrorCode("JMS030", "Missing collection trigger configuration."); + public final static ErrorCode JMS031 = new JmsErrorCode("JMS031", "Missing resource."); + + + protected final static class JmsErrorCode extends ErrorCode { + + public JmsErrorCode(String code, String description) { + super(new QName(code, NAMESPACE_URI, PREFIX), description); + } + + } + +} diff --git a/java/src/org/exist/jms/shared/JmsConfiguration.java b/java/src/org/exist/jms/shared/JmsConfiguration.java index 9fe8bfa7..eee134b0 100644 --- a/java/src/org/exist/jms/shared/JmsConfiguration.java +++ b/java/src/org/exist/jms/shared/JmsConfiguration.java @@ -37,6 +37,8 @@ import javax.jms.Message; import javax.naming.Context; +import static org.exist.jms.shared.ErrorCodes.JMS011; + /** * Wrapper for managing JMS configuration items. @@ -215,22 +217,22 @@ public void validate() throws XPathException { final String initialContextFactory = getInitialContextFactory(); if (initialContextFactory == null) { - throw new XPathException(String.format(CONFIG_ERROR_MSG, Context.INITIAL_CONTEXT_FACTORY)); + throw new XPathException(JMS011, String.format(CONFIG_ERROR_MSG, Context.INITIAL_CONTEXT_FACTORY)); } final String providerURL = getBrokerURL(); if (providerURL == null) { - throw new XPathException(String.format(CONFIG_ERROR_MSG, Context.PROVIDER_URL)); + throw new XPathException(JMS011, String.format(CONFIG_ERROR_MSG, Context.PROVIDER_URL)); } final String connectionFactory = getConnectionFactory(); if (connectionFactory == null) { - throw new XPathException(String.format(CONFIG_ERROR_MSG, Constants.CONNECTION_FACTORY)); + throw new XPathException(JMS011, String.format(CONFIG_ERROR_MSG, Constants.CONNECTION_FACTORY)); } final String destination = getDestination(); if (destination == null) { - throw new XPathException(String.format(CONFIG_ERROR_MSG, Constants.DESTINATION)); + throw new XPathException(JMS011, String.format(CONFIG_ERROR_MSG, Constants.DESTINATION)); } } diff --git a/java/src/org/exist/jms/shared/Receiver.java b/java/src/org/exist/jms/shared/Receiver.java index 59ac5428..08a0d6f2 100644 --- a/java/src/org/exist/jms/shared/Receiver.java +++ b/java/src/org/exist/jms/shared/Receiver.java @@ -36,6 +36,8 @@ import javax.xml.datatype.Duration; import java.util.Properties; +import static org.exist.jms.shared.ErrorCodes.*; + /** * JMS messages receiver, represents a JMS connection. *

@@ -114,7 +116,7 @@ public void start() throws XPathException { if (connection == null) { final String txt = "JMS connection must be initialized first"; LOG.error(txt); - throw new XPathException(txt); + throw new XPathException(JMS025, txt); } try { @@ -126,9 +128,9 @@ public void start() throws XPathException { state = STATE.STARTED; } catch (final JMSException ex) { - LOG.error(ex); + LOG.error(ex.getMessage(), ex); messageListener.getReport().addReceiverError(ex); - throw new XPathException(ex.getMessage()); + throw new XPathException(JMS004, ex.getMessage()); } } @@ -219,7 +221,7 @@ public void initialize() throws XPathException { LOG.debug("" + jmsConfig.toString()); messageListener.getReport().addReceiverError(t); - throw new XPathException(t.getMessage()); + throw new XPathException(JMS000, t.getMessage()); } } @@ -235,7 +237,7 @@ public void stop() throws XPathException { if (connection == null) { final String txt = "JMS connection must be initialized first"; LOG.error(txt); - throw new XPathException(txt); + throw new XPathException(JMS025, txt); } try { @@ -247,10 +249,10 @@ public void stop() throws XPathException { state = STATE.STOPPED; } catch (final JMSException ex) { - LOG.error(ex); + LOG.error(ex.getMessage(), ex); messageListener.getReport().addReceiverError(ex); - throw new XPathException(ex.getMessage()); + throw new XPathException(JMS004, ex.getMessage()); } } @@ -265,7 +267,7 @@ public void close() throws XPathException { if (connection == null) { final String txt = "JMS connection must be initialized first"; LOG.error(txt); - throw new XPathException(txt); + throw new XPathException(JMS025, txt); } // If not stopped, try to stop first @@ -285,7 +287,7 @@ public void close() throws XPathException { try { clientId = connection.getClientID(); } catch (final JMSException ex) { - LOG.debug(ex); + LOG.debug(ex.getMessage(), ex); } // Start listener @@ -301,10 +303,10 @@ public void close() throws XPathException { state = STATE.CLOSED; } catch (final JMSException ex) { - LOG.error(ex); + LOG.error(ex.getMessage(), ex); messageListener.getReport().addReceiverError(ex); - throw new XPathException(ex.getMessage()); + throw new XPathException(JMS004, ex.getMessage()); } } diff --git a/java/src/org/exist/jms/shared/ReportItem.java b/java/src/org/exist/jms/shared/ReportItem.java index 6a6ed4ea..75723a54 100644 --- a/java/src/org/exist/jms/shared/ReportItem.java +++ b/java/src/org/exist/jms/shared/ReportItem.java @@ -53,7 +53,7 @@ public Throwable getThowable() { } public String getTimeStamp() { - return DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(timestamp); + return DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.format(timestamp); } public String getMessage() { diff --git a/java/src/org/exist/jms/xquery/management/ListReceivers.java b/java/src/org/exist/jms/xquery/management/ListReceivers.java index bb2ee753..0727c8d2 100644 --- a/java/src/org/exist/jms/xquery/management/ListReceivers.java +++ b/java/src/org/exist/jms/xquery/management/ListReceivers.java @@ -26,6 +26,8 @@ import org.exist.xquery.*; import org.exist.xquery.value.*; +import static org.exist.jms.shared.ErrorCodes.JMS010; + /** * Implementation of the jms:list() function. Provides information about the receivers. * @@ -57,7 +59,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro if (!context.getSubject().hasDbaRole() && !context.getSubject().hasGroup(Constants.JMS_GROUP)) { final String txt = String.format("Permission denied, user '%s' must be a DBA or be in group '%s'", context.getSubject().getName(), Constants.JMS_GROUP); - final XPathException ex = new XPathException(this, txt); + final XPathException ex = new XPathException(this, JMS010, txt); LOG.error(txt); throw ex; } diff --git a/java/src/org/exist/jms/xquery/management/ManageReceivers.java b/java/src/org/exist/jms/xquery/management/ManageReceivers.java index ba503d2b..b26b9b84 100644 --- a/java/src/org/exist/jms/xquery/management/ManageReceivers.java +++ b/java/src/org/exist/jms/xquery/management/ManageReceivers.java @@ -27,6 +27,8 @@ import org.exist.xquery.*; import org.exist.xquery.value.*; +import static org.exist.jms.shared.ErrorCodes.*; + /** * Implementation of the start-stop-close-getReport functions * @@ -85,7 +87,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro if (!context.getSubject().hasDbaRole() && !context.getSubject().hasGroup(Constants.JMS_GROUP)) { final String txt = String.format("Permission denied, user '%s' must be a DBA or be in group '%s'", context.getSubject().getName(), Constants.JMS_GROUP); - final XPathException ex = new XPathException(this, txt); + final XPathException ex = new XPathException(this, JMS010, txt); LOG.error(txt, ex); throw ex; } @@ -98,7 +100,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro // Verify if receiver is available if (receiver == null) { - throw new XPathException(this, String.format("No receiver exists for id '%s'", id)); + throw new XPathException(this, JMS020, String.format("No receiver exists for id '%s'", id)); } try { @@ -127,7 +129,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro } else { // DW: to check - throw new XPathException(this, String.format("Function '%s' does not exist.", getSignature().getName().getLocalPart())); + throw new XPathException(this, JMS002, String.format("Function '%s' does not exist.", getSignature().getName().getLocalPart())); } return returnValue; @@ -139,7 +141,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro } catch (final Throwable t) { LOG.error(t.getMessage(), t); - throw new XPathException(this, t); + throw new XPathException(this, JMS000, t); } } } diff --git a/java/src/org/exist/jms/xquery/management/RegisterReceiver.java b/java/src/org/exist/jms/xquery/management/RegisterReceiver.java index ac28206f..7bd938de 100644 --- a/java/src/org/exist/jms/xquery/management/RegisterReceiver.java +++ b/java/src/org/exist/jms/xquery/management/RegisterReceiver.java @@ -22,15 +22,16 @@ import org.exist.dom.QName; import org.exist.jms.messaging.MessagingJmsListener; import org.exist.jms.shared.Constants; -import org.exist.jms.shared.JmsConfiguration; -import org.exist.jms.shared.Receiver; -import org.exist.jms.shared.ReceiversManager; +import org.exist.jms.shared.ErrorCodes; +import org.exist.jms.shared.*; import org.exist.jms.xquery.MessagingModule; import org.exist.xquery.*; import org.exist.xquery.functions.map.AbstractMapType; import org.exist.xquery.functions.request.RequestModule; import org.exist.xquery.value.*; +import static org.exist.jms.shared.ErrorCodes.JMS010; + /** * Implementation of the jms:register() function. * @@ -64,7 +65,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro if (!context.getSubject().hasDbaRole() && !context.getSubject().hasGroup(Constants.JMS_GROUP)) { final String txt = String.format("Permission denied, user '%s' must be a DBA or be in group '%s'", context.getSubject().getName(), Constants.JMS_GROUP); - final XPathException ex = new XPathException(this, txt); + final XPathException ex = new XPathException(this, JMS010, txt); LOG.error(txt, ex); throw ex; } @@ -110,7 +111,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro } catch (final Throwable t) { LOG.error(t.getMessage(), t); - throw new XPathException(this, t); + throw new XPathException(this, ErrorCodes.JMS000, t); } } } diff --git a/java/src/org/exist/jms/xquery/messaging/SendMessage.java b/java/src/org/exist/jms/xquery/messaging/SendMessage.java index f2833c88..4b3144d0 100644 --- a/java/src/org/exist/jms/xquery/messaging/SendMessage.java +++ b/java/src/org/exist/jms/xquery/messaging/SendMessage.java @@ -22,6 +22,7 @@ import org.exist.dom.QName; import org.exist.jms.send.Sender; import org.exist.jms.shared.Constants; +import org.exist.jms.shared.ErrorCodes; import org.exist.jms.shared.JmsConfiguration; import org.exist.jms.shared.JmsMessageProperties; import org.exist.jms.xquery.MessagingModule; @@ -29,6 +30,8 @@ import org.exist.xquery.functions.map.AbstractMapType; import org.exist.xquery.value.*; +import static org.exist.jms.shared.ErrorCodes.JMS010; + /** * Implementation of the jms:send() function. * @@ -63,7 +66,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro if (!context.getSubject().hasDbaRole() && !context.getSubject().hasGroup(Constants.JMS_GROUP)) { final String txt = String.format("Permission denied, user '%s' must be a DBA or be in group '%s'", context.getSubject().getName(), Constants.JMS_GROUP); - final XPathException ex = new XPathException(this, txt); + final XPathException ex = new XPathException(this, JMS010, txt); LOG.error(txt, ex); throw ex; } @@ -93,7 +96,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro } catch (final Throwable t) { LOG.error(t.getMessage(), t); - throw new XPathException(this, t); + throw new XPathException(this, ErrorCodes.JMS000, t); } } } diff --git a/java/src/org/exist/jms/xquery/replication/RegisterReceiver.java b/java/src/org/exist/jms/xquery/replication/RegisterReceiver.java index aec9d628..29014707 100644 --- a/java/src/org/exist/jms/xquery/replication/RegisterReceiver.java +++ b/java/src/org/exist/jms/xquery/replication/RegisterReceiver.java @@ -23,14 +23,15 @@ import org.exist.dom.QName; import org.exist.jms.replication.subscribe.ReplicationJmsListener; import org.exist.jms.shared.Constants; -import org.exist.jms.shared.JmsConfiguration; -import org.exist.jms.shared.Receiver; -import org.exist.jms.shared.ReceiversManager; +import org.exist.jms.shared.ErrorCodes; +import org.exist.jms.shared.*; import org.exist.jms.xquery.ReplicationModule; import org.exist.xquery.*; import org.exist.xquery.functions.map.AbstractMapType; import org.exist.xquery.value.*; +import static org.exist.jms.shared.ErrorCodes.JMS010; + /** * Implementation of the replication:register() function. * @@ -57,7 +58,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro if (!context.getSubject().hasDbaRole() && !context.getSubject().hasGroup(Constants.JMS_GROUP)) { final String txt = String.format("Permission denied, user '%s' must be a DBA or be in group '%s'", context.getSubject().getName(), Constants.JMS_GROUP); - final XPathException ex = new XPathException(this, txt); + final XPathException ex = new XPathException(this, JMS010, txt); LOG.error(txt, ex); throw ex; } @@ -94,7 +95,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro } catch (final Throwable t) { LOG.error(t.getMessage(), t); - throw new XPathException(this, t); + throw new XPathException(this, ErrorCodes.JMS000, t); } } } diff --git a/java/src/org/exist/jms/xquery/replication/ReplicationSwitch.java b/java/src/org/exist/jms/xquery/replication/ReplicationSwitch.java index 3f7d5791..c11af620 100644 --- a/java/src/org/exist/jms/xquery/replication/ReplicationSwitch.java +++ b/java/src/org/exist/jms/xquery/replication/ReplicationSwitch.java @@ -23,10 +23,13 @@ import org.exist.dom.QName; import org.exist.jms.replication.shared.ReplicationGuard; import org.exist.jms.shared.Constants; +import org.exist.jms.shared.ErrorCodes; import org.exist.jms.xquery.ReplicationModule; import org.exist.xquery.*; import org.exist.xquery.value.*; +import static org.exist.jms.shared.ErrorCodes.JMS010; + /** * Implementation of the replication:register() function. * @@ -53,7 +56,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro if (!context.getSubject().hasDbaRole() && !context.getSubject().hasGroup(Constants.JMS_GROUP)) { final String txt = String.format("Permission denied, user '%s' must be a DBA or be in group '%s'", context.getSubject().getName(), Constants.JMS_GROUP); - final XPathException ex = new XPathException(this, txt); + final XPathException ex = new XPathException(this, JMS010, txt); LOG.error(txt, ex); throw ex; } @@ -75,7 +78,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro } catch (final Throwable t) { LOG.error(t.getMessage(), t); - throw new XPathException(this, t); + throw new XPathException(this, ErrorCodes.JMS000, t); } } diff --git a/java/src/org/exist/jms/xquery/replication/SyncResource.java b/java/src/org/exist/jms/xquery/replication/SyncResource.java index efc0c4b9..befcd932 100644 --- a/java/src/org/exist/jms/xquery/replication/SyncResource.java +++ b/java/src/org/exist/jms/xquery/replication/SyncResource.java @@ -30,6 +30,7 @@ import org.exist.dom.persistent.DocumentImpl; import org.exist.jms.replication.publish.ReplicationTrigger; import org.exist.jms.shared.Constants; +import org.exist.jms.shared.ErrorCodes; import org.exist.jms.xquery.ReplicationModule; import org.exist.security.PermissionDeniedException; import org.exist.storage.DBBroker; @@ -43,6 +44,9 @@ import java.util.List; import java.util.Optional; +import static org.exist.jms.shared.ErrorCodes.JMS030; +import static org.exist.jms.shared.ErrorCodes.JMS031; + /** * Implementation of the replication:register() function. * @@ -75,7 +79,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro if (!context.getSubject().hasDbaRole() && !context.getSubject().hasGroup(Constants.JMS_GROUP)) { final String txt = String.format("Permission denied, user '%s' must be a DBA or be in group '%s'", context.getSubject().getName(), Constants.JMS_GROUP); - final XPathException ex = new XPathException(this, txt); + final XPathException ex = new XPathException(this, ErrorCodes.JMS010, txt); LOG.error(txt, ex); throw ex; } @@ -106,7 +110,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro final Optional replicationTrigger = getReplicationTrigger(broker, parentCollection); if (!replicationTrigger.isPresent()) { parentCollection.release(Lock.READ_LOCK); - throw new XPathException(this, String.format("No trigger configuration found for collection %s", parentCollection)); + throw new XPathException(this, JMS030, String.format("No trigger configuration found for collection %s", parentCollection)); } final ReplicationTrigger trigger = replicationTrigger.get(); @@ -156,7 +160,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro } catch (final Throwable t) { LOG.error(t.getMessage(), t); - throw new XPathException(this, t); + throw new XPathException(this, ErrorCodes.JMS000, t); } finally { if (parentCollection != null) { @@ -197,7 +201,7 @@ private Collection getCollection(final DBBroker broker, final XmldbURI collectio final Collection collection = broker.openCollection(collectionURI, setReadLock ? Lock.READ_LOCK : Lock.NO_LOCK); if (collection == null && throwExceptionWHenNotExistent) { - throw new XPathException(this, String.format("Collection not found: %s", collectionURI)); + throw new XPathException(this, JMS031, String.format("Collection not found: %s", collectionURI)); } return collection; @@ -221,7 +225,7 @@ private DocumentImpl getDocument(final DBBroker broker, final XmldbURI collectio final DocumentImpl resource = collection.getDocument(broker, documentUri); if (resource == null) { collection.getLock().release(Lock.READ_LOCK); - throw new XPathException(this, String.format("No resource found for path: %s", documentUri)); + throw new XPathException(this, JMS031, String.format("No resource found for path: %s", documentUri)); } return resource;