Search in sources :

Example 6 with ErrorTrace

use of alma.ACSErr.ErrorTrace in project ACS by ACS-Community.

the class AcsJExceptionTest method testJCompletion.

/**
	 * Creates Completion objects from scratch, from other completion objects,
     * with and without associated exception, and checks the values.
	 */
public void testJCompletion() {
    // a completion without associated exception
    AcsJCompletion jcompl1 = new ACSErrTestOKAcsJCompletion();
    assertEquals(ACSErrTypeTest.value, jcompl1.getType());
    assertEquals(ACSErrTestOK.value, jcompl1.getCode());
    assertFalse(jcompl1.isError());
    assertTrue(jcompl1.getTimeStamp() > 0);
    Completion corbacompl = jcompl1.toCorbaCompletion();
    assertEquals(ACSErrTypeTest.value, corbacompl.type);
    assertEquals(ACSErrTestOK.value, corbacompl.code);
    assertTrue(corbacompl.previousError.length == 0);
    assertEquals(UTCUtility.utcJavaToOmg(jcompl1.getTimeStamp()), corbacompl.timeStamp);
    long timeMillisBeforeExceptionCreation = System.currentTimeMillis();
    // completion with associated exception, 
    // trying to wrap the previous completion (which has no exception that could be wrapped)
    AcsJCompletion jcompl2 = new ACSErrTest1AcsJCompletion(jcompl1);
    assertTrue(jcompl2.isError());
    AcsJException acsjex2 = jcompl2.getAcsJException();
    assertTrue(acsjex2 instanceof AcsJACSErrTest1Ex);
    assertNull(acsjex2.getCause());
    // completion with associated exception, 
    // but this time trying to wrap the plain CORBA completion instead of its AcsJ-equivalent.
    AcsJCompletion jcompl2b = new ACSErrTest2AcsJCompletion(corbacompl);
    assertTrue(jcompl2b.isError());
    AcsJException acsjex2b = jcompl2b.getAcsJException();
    assertTrue(acsjex2b instanceof AcsJACSErrTest2Ex);
    assertNull(acsjex2b.getCause());
    // now wrapping a completion with exception with another completion with exception
    AcsJCompletion jcompl3 = new ACSErrTest3AcsJCompletion(jcompl2);
    assertTrue(jcompl3.isError());
    AcsJException acsjex3 = jcompl3.getAcsJException();
    assertTrue(acsjex3 instanceof AcsJACSErrTest3Ex);
    Throwable acsjex_cause = acsjex3.getCause();
    assertNotNull(acsjex_cause);
    Throwable acsjex_cause2 = acsjex_cause.getCause();
    assertNull(acsjex_cause2);
    Completion corbacomp3 = jcompl3.toCorbaCompletion();
    assertEquals(ACSErrTypeTest.value, corbacomp3.type);
    assertEquals(ACSErrTest3.value, corbacomp3.code);
    assertNotNull(corbacomp3.previousError);
    assertEquals(1, corbacomp3.previousError.length);
    ErrorTrace trace_3_1 = corbacomp3.previousError[0];
    assertNotNull(trace_3_1);
    ErrorTrace trace_3_0 = trace_3_1.previousError[0];
    assertNotNull(trace_3_0);
    assertEquals(0, trace_3_0.previousError.length);
    // check the various timestamps
    long timeMillisAfterExceptionCreation = System.currentTimeMillis();
    assertTrue(timeMillisBeforeExceptionCreation <= acsjex2.getTimestampMillis());
    assertTrue(timeMillisAfterExceptionCreation >= acsjex2.getTimestampMillis());
    assertTrue(timeMillisBeforeExceptionCreation <= acsjex2b.getTimestampMillis());
    assertTrue(timeMillisAfterExceptionCreation >= acsjex2b.getTimestampMillis());
    long corbacomp3_millis = UTCUtility.utcOmgToJava(corbacomp3.timeStamp);
    assertTrue(timeMillisBeforeExceptionCreation <= corbacomp3_millis);
    assertTrue(timeMillisAfterExceptionCreation >= corbacomp3_millis);
    long trace_3_0_millis = UTCUtility.utcOmgToJava(trace_3_0.timeStamp);
    assertTrue(timeMillisBeforeExceptionCreation <= trace_3_0_millis);
    assertTrue(timeMillisAfterExceptionCreation >= trace_3_0_millis);
}
Also used : ACSErrTest3AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest3AcsJCompletion) ACSErrTest2AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest2AcsJCompletion) ACSErrTestOKAcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTestOKAcsJCompletion) ACSErrTest1AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest1AcsJCompletion) ACSErrTest3AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest3AcsJCompletion) ErrorTrace(alma.ACSErr.ErrorTrace) ACSErrTest2AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest2AcsJCompletion) ACSErrTestOKAcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTestOKAcsJCompletion) ACSErrTest1AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest1AcsJCompletion) ACSErrTest2AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest2AcsJCompletion) ACSErrTestOKAcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTestOKAcsJCompletion) ACSErrTest1AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest1AcsJCompletion) Completion(alma.ACSErr.Completion) ACSErrTest3AcsJCompletion(alma.ACSErrTypeTest.wrappers.ACSErrTest3AcsJCompletion) AcsJACSErrTest1Ex(alma.ACSErrTypeTest.wrappers.AcsJACSErrTest1Ex) AcsJACSErrTest3Ex(alma.ACSErrTypeTest.wrappers.AcsJACSErrTest3Ex) AcsJACSErrTest2Ex(alma.ACSErrTypeTest.wrappers.AcsJACSErrTest2Ex)

Example 7 with ErrorTrace

use of alma.ACSErr.ErrorTrace in project ACS by ACS-Community.

the class AcsJException method log.

/**
	 * Logs this exception and all causing exceptions.
     * For each such exception, a separate log entry is created, in accordance with the ACS error logging specification.
	 * 
	 * @param logger  the JDK logger to be used for logging this exception. 
	 */
public void log(Logger logger) {
    Throwable thr = this;
    // the common ID by which all log messages for the various ErrorTrace objects can later be assembled again
    String stackID = logger.getName() + System.currentTimeMillis();
    // stackLevel is a running integer counting down from the latest Throwable to the initial Throwable (index=0)
    for (int stackLevel = getTraceDepth() - 1; stackLevel >= 0; stackLevel--) {
        ErrorTrace et = createSingleErrorTrace(thr, m_timeMilli - 1);
        LogRecord logRec = createSingleErrorTraceLogRecord(et, stackID, stackLevel);
        logger.log(logRec);
        if (stackLevel > 0) {
            thr = thr.getCause();
        }
    }
}
Also used : ErrorTrace(alma.ACSErr.ErrorTrace) LogRecord(java.util.logging.LogRecord)

Example 8 with ErrorTrace

use of alma.ACSErr.ErrorTrace in project ACS by ACS-Community.

the class CorbaExceptionConverter method resurrectThrowable.

private static void resurrectThrowable(Throwable thr, ErrorTrace et) {
    if (thr == null || et == null) {
        throw new NullPointerException("resurrectThrowable: parameters must not be null!");
    }
    if (thr instanceof AcsJException) {
        // data specific to AcsJException
        AcsJException acsJEx = (AcsJException) thr;
        acsJEx.m_host = et.host;
        acsJEx.m_process = et.process;
        acsJEx.m_file = et.file;
        acsJEx.m_method = et.routine;
        acsJEx.m_line = et.lineNum;
        // todo check if error type and code match
        //et.errorType == acsJEx.getErrorType();
        //et.errorCode == acsJEx.getErrorCode();
        acsJEx.m_severity = et.severity;
        acsJEx.m_threadName = et.thread;
        acsJEx.m_timeMilli = UTCUtility.utcOmgToJava(et.timeStamp);
        acsJEx.m_properties = ErrorTraceManipulator.getProperties(et);
    }
    // We redundantly put source information also into a fake StackTrace,
    // which then looks better when logging such an AcsJException directly,
    // even though the rest of a single java exception's stack trace did not get 
    // forwarded over corba/ErrorTrace.
    StackTraceElement[] stackTrace = new StackTraceElement[1];
    stackTrace[0] = new StackTraceElement("---", et.routine, et.file, et.lineNum);
    thr.setStackTrace(stackTrace);
    if (et.previousError != null && et.previousError.length > 0 && et.previousError[0] != null) {
        ErrorTrace etCause = et.previousError[0];
        if (etCause != null) {
            // recursion
            Throwable thrCause = recursiveGetThrowable(etCause);
            thr.initCause(thrCause);
        }
    }
}
Also used : ErrorTrace(alma.ACSErr.ErrorTrace)

Example 9 with ErrorTrace

use of alma.ACSErr.ErrorTrace in project ACS by ACS-Community.

the class CorbaExceptionConverter method convertHiddenErrorTrace.

/**
	 * Checks if a given Throwable is of a CORBA type generated by the ACS error system.
	 * If so, the embedded error trace is converted to a chain of AcsJ-style exceptions.
	 * <p>
	 * The check is based on the fact that all ACS error system exceptions derive 
	 * from <code>org.omg.CORBA.UserException</code>, and have a field <code>errorTrace</code>
	 * of type <code>alma.ACSErr.ErrorTrace</code>.
	 * 
	 * @param thr
	 * @return The converted Throwable, or <code>thr</code> itself if no conversion is necessary,
	 *         or if the conversion failed with an exception.
	 */
public static Throwable convertHiddenErrorTrace(Throwable thr) {
    // that does not have an associated error trace 
    if (thr == null) {
        return null;
    }
    // all ACS error system exceptions derive from org.omg.CORBA.UserException 
    if (UserException.class.isAssignableFrom(thr.getClass())) {
        // check if thr is of an exception class generated by the ACS error system, then use its ErrorTrace
        try {
            Field errorTraceField = thr.getClass().getField("errorTrace");
            ErrorTrace etCause = (ErrorTrace) errorTraceField.get(thr);
            thr = recursiveGetThrowable(etCause);
        } catch (Exception ex) {
        // ignore: we assume that thr is not an ACS-style exception
        }
    }
    return thr;
}
Also used : Field(java.lang.reflect.Field) ErrorTrace(alma.ACSErr.ErrorTrace) UserException(org.omg.CORBA.UserException)

Example 10 with ErrorTrace

use of alma.ACSErr.ErrorTrace in project ACS by ACS-Community.

the class AcsJException method createSingleErrorTrace.

/**
     * Converts a Throwable that may not be an AcsJException to an <code>ErrorTrace</code>.
     * <p>
     * For example, <code>thr</code> could be a <code>NullPointerException</code> thrown in the same process and thus not yet converted 
     * to <code>DefaultAcsJException</code>, but wrapped by some subclass of AcsJException which contains the NPE as its cause.
     * 
     * @param defaultTimeMilli  Java-time (1970-based) used to estimate a time stamp if none is available, 
     *                          in order to avoid something from October 1582 in the new ErrorTrace.
     *                          Typically the timestamp from the wrapping AcsJException.
     * @see #createSingleErrorTrace()
     */
public static ErrorTrace createSingleErrorTrace(Throwable thr, long defaultTimeMilli) {
    ErrorTrace et = null;
    if (thr instanceof AcsJException) {
        et = ((AcsJException) thr).createSingleErrorTrace();
        return et;
    }
    et = new ErrorTrace();
    StackTraceElement[] stTrElems = thr.getStackTrace();
    if (stTrElems != null && stTrElems[0] != null) {
        StackTraceElement stTrEl = stTrElems[0];
        et.file = stTrEl.getFileName();
        et.routine = stTrEl.getMethodName();
        et.lineNum = stTrEl.getLineNumber();
    } else {
        // getStackTrace() only make its best-effort,
        // we might end up without the data...
        et.file = et.routine = "unknown";
        et.lineNum = -1;
    }
    // the non-ACS exception we are converting does not contain data for the following fields of ErrorTrace,
    // so we have to use defaults or smart guessing
    et.host = s_thisHost;
    et.process = s_thisProcess;
    et.sourceObject = ContextFinder.getSourceObject();
    et.thread = "NA";
    et.timeStamp = UTCUtility.utcJavaToOmg(defaultTimeMilli);
    // = ACSErrTypeJavaNative.value; this code is hardcoded otherwise we'll have problem with bulding and duplication of code 
    et.errorType = 9;
    et.errorCode = -1;
    et.shortDescription = thr.getClass().getName();
    et.severity = Severity.Error;
    et.data = new NameValue[0];
    addExceptionProperties(thr, et);
    return et;
}
Also used : ErrorTrace(alma.ACSErr.ErrorTrace)

Aggregations

ErrorTrace (alma.ACSErr.ErrorTrace)10 Completion (alma.ACSErr.Completion)2 ACSException (alma.ACSErr.ACSException)1 NameValue (alma.ACSErr.NameValue)1 ACSErrTest1AcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTest1AcsJCompletion)1 ACSErrTest2AcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTest2AcsJCompletion)1 ACSErrTest3AcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTest3AcsJCompletion)1 ACSErrTestOKAcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTestOKAcsJCompletion)1 AcsJACSErrTest1Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest1Ex)1 AcsJACSErrTest2Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest2Ex)1 AcsJACSErrTest3Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest3Ex)1 Field (java.lang.reflect.Field)1 LogRecord (java.util.logging.LogRecord)1 UserException (org.omg.CORBA.UserException)1