com.barclays.dfe.fw.DFEErrorPacket.java Source code

Java tutorial

Introduction

Here is the source code for com.barclays.dfe.fw.DFEErrorPacket.java

Source

/*
Copyright 2014 the original author or authors
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
    
The Error packet packages up the error and sends it to the Barclays Monitoring system
      
**/

package com.barclays.dfe.fw;
/**
 * 
 * Integration with LOGBACK Appender 
 */

import java.lang.reflect.Field;

import org.apache.commons.lang3.exception.ExceptionUtils;

// TODO: Auto-generated Javadoc
/**
 * The Class DFEErrorPacket.
 */
public class DFEErrorPacket {

    /** The dtx. */
    private DFETransferContext dtx; // Context if supplied can provide details on transfer request   

    /** The DFE error. */
    public Exception DFEError;

    /** The error. */
    public String theError; // The error message that thrown

    /** The error code. */
    public int errorCode; // Error Code

    /** The svc code. */
    public String svcCode; // Service Code;

    /** The app code. */
    public String appCode; // Application srvice code

    /** The called. */
    public boolean called = false; // Set this for a fatal error - so that we dont end up with multiple stack traces

    // Basic constructor - must have all the info
    /**
        * Instantiates a new DFE error packet.
        *
        * @param mess the mess
        * @param e the e
        * @param code the code
        * @param svc the svc
        * @param appID the app id
        */
    DFEErrorPacket(String mess, Exception e, int code, String svc, String appID) {

        DFEError = e;
        theError = mess;
        svcCode = svc;

    }

    /**
     * Instantiates a new DFE error packet.
     *
     * @param mess the mess
     * @param e the e
     * @param code the code
     */
    DFEErrorPacket(String mess, Exception e, int code) {

        DFEError = e;
        theError = mess;
        svcCode = "SVC000000";

    }

    /**
     * Instantiates a new DFE error packet.
     *
     * @param e the e
     * @param DFEdtx the DF edtx
     */
    DFEErrorPacket(Exception e, DFETransferContext DFEdtx) {

        DFEError = e;
        this.dtx = DFEdtx.getCopy(); // Save a copy for the journey 

    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override

    // For now do the simple ones.

    public String toString() {

        StringBuilder result = new StringBuilder();
        String newLine = System.getProperty("line.separator");

        result.append(newLine);
        //result.append( this.getClass().getName() );
        if (dtx != null) {
            result.append(" DFE Context Settings {");
            result.append(this.dtx.toString());
            result.append("}");
            result.append(newLine);
        }

        result.append(" DFE Error Packet Details {");
        result.append(newLine);

        result.append(newLine);
        result.append(ExceptionUtils.getStackTrace(DFEError));

        result.append("}");

        return result.toString();
    }

}