diff --git a/apis/api-mal/src/main/java/org/ccsds/moims/mo/mal/MOErrorException.java b/apis/api-mal/src/main/java/org/ccsds/moims/mo/mal/MOErrorException.java index 098fe4146..3368e83eb 100644 --- a/apis/api-mal/src/main/java/org/ccsds/moims/mo/mal/MOErrorException.java +++ b/apis/api-mal/src/main/java/org/ccsds/moims/mo/mal/MOErrorException.java @@ -23,11 +23,14 @@ import java.io.Serializable; import org.ccsds.moims.mo.mal.structures.Attribute; import org.ccsds.moims.mo.mal.structures.UInteger; +import org.ccsds.moims.mo.mal.transport.MALEncodedBody; +import org.ccsds.moims.mo.mal.transport.MALEncodedElement; +import org.ccsds.moims.mo.mal.transport.MALErrorBody; /** * Represents a MAL error. */ -public class MOErrorException extends Exception implements Serializable { +public class MOErrorException extends Exception implements Serializable, MALErrorBody { private final UInteger errorNumber; private final Object extraInformation; @@ -72,6 +75,31 @@ public Object getExtraInformation() { return extraInformation; } + @Override + public MOErrorException getError() throws MALException { + return this; + } + + @Override + public int getElementCount() { + return 1; + } + + @Override + public Object getBodyElement(int index, Object element) throws MALException { + return this; + } + + @Override + public MALEncodedElement getEncodedBodyElement(int index) throws MALException { + return null; + } + + @Override + public MALEncodedBody getEncodedBody() throws MALException { + return null; + } + @Override public String toString() { final StringBuilder buf = new StringBuilder(); diff --git a/mal-impl/src/main/java/esa/mo/mal/impl/ips/DummyErrorBody.java b/mal-impl/src/main/java/esa/mo/mal/impl/ips/DummyErrorBody.java deleted file mode 100644 index 0a342e1b4..000000000 --- a/mal-impl/src/main/java/esa/mo/mal/impl/ips/DummyErrorBody.java +++ /dev/null @@ -1,69 +0,0 @@ -/* ---------------------------------------------------------------------------- - * Copyright (C) 2016 European Space Agency - * European Space Operations Centre - * Darmstadt - * Germany - * ---------------------------------------------------------------------------- - * System : CCSDS MO MAL Java Implementation - * ---------------------------------------------------------------------------- - * Licensed under the European Space Agency Public License, Version 2.0 - * You may not use this file except in compliance with the License. - * - * Except as expressly set forth in this License, the Software is provided to - * You on an "as is" basis and without warranties of any kind, including without - * limitation merchantability, fitness for a particular purpose, absence of - * defects or errors, accuracy or non-infringement of intellectual property rights. - * - * See the License for the specific language governing permissions and - * limitations under the License. - * ---------------------------------------------------------------------------- - */ -package esa.mo.mal.impl.ips; - -import org.ccsds.moims.mo.mal.MALException; -import org.ccsds.moims.mo.mal.MOErrorException; -import org.ccsds.moims.mo.mal.transport.MALEncodedBody; -import org.ccsds.moims.mo.mal.transport.MALEncodedElement; -import org.ccsds.moims.mo.mal.transport.MALErrorBody; - -/** - * Used when returning an internally generated error. - */ -public final class DummyErrorBody implements MALErrorBody { - - private final MOErrorException error; - - /** - * Constructor. - * - * @param error Error. - */ - public DummyErrorBody(MOErrorException error) { - this.error = error; - } - - @Override - public MOErrorException getError() throws MALException { - return error; - } - - @Override - public int getElementCount() { - return 1; - } - - @Override - public Object getBodyElement(int index, Object element) throws MALException { - return error; - } - - @Override - public MALEncodedElement getEncodedBodyElement(int index) throws MALException { - return null; - } - - @Override - public MALEncodedBody getEncodedBody() throws MALException { - return null; - } -} diff --git a/mal-impl/src/main/java/esa/mo/mal/impl/ips/IPConsumerHandler.java b/mal-impl/src/main/java/esa/mo/mal/impl/ips/IPConsumerHandler.java index 27594c532..2c8e0de60 100644 --- a/mal-impl/src/main/java/esa/mo/mal/impl/ips/IPConsumerHandler.java +++ b/mal-impl/src/main/java/esa/mo/mal/impl/ips/IPConsumerHandler.java @@ -23,7 +23,6 @@ import esa.mo.mal.impl.MALContextFactoryImpl; import java.util.Map; import java.util.logging.Level; -import org.ccsds.moims.mo.mal.MALHelper; import org.ccsds.moims.mo.mal.MALInteractionException; import org.ccsds.moims.mo.mal.MOErrorException; import org.ccsds.moims.mo.mal.structures.InteractionType; @@ -35,8 +34,6 @@ */ public abstract class IPConsumerHandler { - protected static final DummyErrorBody ERROR_BODY_INCORRECT_STATE - = new DummyErrorBody(new MOErrorException(MALHelper.INCORRECT_STATE_ERROR_NUMBER, null)); protected final boolean isSynchronous; protected final OperationResponseHolder responseHolder; diff --git a/mal-impl/src/main/java/esa/mo/mal/impl/ips/InvokeIPConsumerHandler.java b/mal-impl/src/main/java/esa/mo/mal/impl/ips/InvokeIPConsumerHandler.java index 70de2e9dc..382d6fcd6 100644 --- a/mal-impl/src/main/java/esa/mo/mal/impl/ips/InvokeIPConsumerHandler.java +++ b/mal-impl/src/main/java/esa/mo/mal/impl/ips/InvokeIPConsumerHandler.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.logging.Level; import org.ccsds.moims.mo.mal.MALException; +import org.ccsds.moims.mo.mal.MALHelper; import org.ccsds.moims.mo.mal.MALInteractionException; import org.ccsds.moims.mo.mal.MALInvokeOperation; import org.ccsds.moims.mo.mal.MOErrorException; @@ -75,7 +76,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException { } } else { finished = true; - listener.invokeAckErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos); + MOErrorException incorrectStateError = new MOErrorException( + MALHelper.INCORRECT_STATE_ERROR_NUMBER, + "The received message is not an INVOKE_ACK_STAGE!"); + listener.invokeAckErrorReceived(header, incorrectStateError, qos); } return; } @@ -93,7 +97,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException { } // If it is not ACK, nor RESPONSE, then something went wrong! - listener.invokeResponseErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos); + MOErrorException incorrectStateError = new MOErrorException( + MALHelper.INCORRECT_STATE_ERROR_NUMBER, + "The received message is not an INVOKE_ACK_STAGE, nor INVOKE_RESPONSE_STAGE!"); + listener.invokeResponseErrorReceived(header, incorrectStateError, qos); } catch (MALException ex) { // nothing we can do with this MALContextFactoryImpl.LOGGER.log(Level.WARNING, @@ -109,9 +116,9 @@ public synchronized void handleError(final MALMessageHeader hdr, } else { try { if (!receivedAck) { - responseHolder.getListener().invokeAckErrorReceived(hdr, new DummyErrorBody(error), qosMap); + responseHolder.getListener().invokeAckErrorReceived(hdr, error, qosMap); } else { - responseHolder.getListener().invokeResponseErrorReceived(hdr, new DummyErrorBody(error), qosMap); + responseHolder.getListener().invokeResponseErrorReceived(hdr, error, qosMap); } } catch (MALException ex) { // not a lot we can do with this at this stage apart from log it diff --git a/mal-impl/src/main/java/esa/mo/mal/impl/ips/ProgressIPConsumerHandler.java b/mal-impl/src/main/java/esa/mo/mal/impl/ips/ProgressIPConsumerHandler.java index 73d189027..e2ffcf67e 100644 --- a/mal-impl/src/main/java/esa/mo/mal/impl/ips/ProgressIPConsumerHandler.java +++ b/mal-impl/src/main/java/esa/mo/mal/impl/ips/ProgressIPConsumerHandler.java @@ -21,10 +21,10 @@ package esa.mo.mal.impl.ips; import esa.mo.mal.impl.MALContextFactoryImpl; -import static esa.mo.mal.impl.ips.IPConsumerHandler.ERROR_BODY_INCORRECT_STATE; import java.util.Map; import java.util.logging.Level; import org.ccsds.moims.mo.mal.MALException; +import org.ccsds.moims.mo.mal.MALHelper; import org.ccsds.moims.mo.mal.MALInteractionException; import org.ccsds.moims.mo.mal.MALProgressOperation; import org.ccsds.moims.mo.mal.MOErrorException; @@ -76,7 +76,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException { } } else { finished = true; - listener.progressAckErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos); + MOErrorException incorrectStateError = new MOErrorException( + MALHelper.INCORRECT_STATE_ERROR_NUMBER, + "The received message is not a PROGRESS_ACK_STAGE!"); + listener.progressAckErrorReceived(header, incorrectStateError, qos); } return; } @@ -104,7 +107,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException { } // If it is not ACK, PROGRESS, nor RESPONSE, then something went wrong! - listener.progressUpdateErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos); + MOErrorException incorrectStateError = new MOErrorException( + MALHelper.INCORRECT_STATE_ERROR_NUMBER, + "The received message is not a PROGRESS_ACK_STAGE, nor PROGRESS_UPDATE_STAGE, nor PROGRESS_RESPONSE_STAGE!"); + listener.progressUpdateErrorReceived(header, incorrectStateError, qos); } catch (MALException ex) { // nothing we can do with this MALContextFactoryImpl.LOGGER.log(Level.WARNING, @@ -120,9 +126,9 @@ public synchronized void handleError(final MALMessageHeader hdr, } else { try { if (!receivedAck) { - responseHolder.getListener().progressAckErrorReceived(hdr, new DummyErrorBody(error), qosMap); + responseHolder.getListener().progressAckErrorReceived(hdr, error, qosMap); } else { - responseHolder.getListener().progressResponseErrorReceived(hdr, new DummyErrorBody(error), qosMap); + responseHolder.getListener().progressResponseErrorReceived(hdr, error, qosMap); } } catch (MALException ex) { // not a lot we can do with this at this stage apart from log it diff --git a/mal-impl/src/main/java/esa/mo/mal/impl/ips/SubmitIPConsumerHandler.java b/mal-impl/src/main/java/esa/mo/mal/impl/ips/SubmitIPConsumerHandler.java index fb2fa1847..52bbff98c 100644 --- a/mal-impl/src/main/java/esa/mo/mal/impl/ips/SubmitIPConsumerHandler.java +++ b/mal-impl/src/main/java/esa/mo/mal/impl/ips/SubmitIPConsumerHandler.java @@ -109,8 +109,7 @@ public synchronized void handleError(final MALMessageHeader hdr, responseHolder.signalError(error); } else { try { - responseHolder.getListener().submitErrorReceived(hdr, - new DummyErrorBody(error), qosMap); + responseHolder.getListener().submitErrorReceived(hdr, error, qosMap); } catch (MALException ex) { // not a lot we can do with this at this stage apart from log it MALContextFactoryImpl.LOGGER.log(Level.WARNING,