Example usage for javax.ejb EJBException EJBException

List of usage examples for javax.ejb EJBException EJBException

Introduction

In this page you can find the example usage for javax.ejb EJBException EJBException.

Prototype

public EJBException(Exception ex) 

Source Link

Document

Constructs an EJBException that embeds the originally thrown exception.

Usage

From source file:be.fedict.eid.idp.model.bean.IdentityServiceSingletonBean.java

/**
 * @return current identity's configuration or <codE>null</code> if none.
 */// www. j a va2 s .  c o  m
public IdPIdentityConfig findIdentityConfig() {

    String activeIdentity = findActiveIdentityName();
    if (null == activeIdentity) {
        return null;
    }
    IdPIdentityConfig idPIdentityConfig = findIdentityConfig(activeIdentity);
    if (null == idPIdentityConfig) {
        throw new EJBException("Identity config " + activeIdentity + " not found!");
    }
    return idPIdentityConfig;
}

From source file:edu.harvard.iq.dvn.core.analysis.NetworkDataServiceBean.java

public File getSubsetExport(boolean getGraphML, boolean getTabular) {

    if (!getGraphML && !getTabular) {
        throw new IllegalArgumentException("At least one download type must be set to true.");
    }/*from   ww  w . j a  va  2  s .  c  o  m*/

    //  Map<String, String> resultInfo = dgs.liveConnectionExport(rWorkspace);
    //return new File( resultInfo.get(DvnRGraphServiceImpl.GRAPHML_FILE_EXPORTED) );
    File xmlFile;
    File vertsFile;
    File edgesFile;
    File zipOutputFile;
    ZipOutputStream zout;
    try {

        xmlFile = File.createTempFile("graphml", "xml");
        vertsFile = File.createTempFile("vertices", "tab");
        edgesFile = File.createTempFile("edges", "tab");

        String delimiter = "\t";
        if (getGraphML) {
            dvnGraph.dumpGraphML(xmlFile.getAbsolutePath());
        }
        if (getTabular) {
            dvnGraph.dumpTables(vertsFile.getAbsolutePath(), edgesFile.getAbsolutePath(), delimiter);
        }

        // Create zip file
        String exportTimestamp = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss").format(new Date());
        zipOutputFile = File.createTempFile("subset_" + exportTimestamp, "zip");
        zout = new ZipOutputStream((OutputStream) new FileOutputStream(zipOutputFile));

        if (getGraphML) {
            addZipEntry(zout, xmlFile.getAbsolutePath(), "graphml_" + exportTimestamp + ".xml");
        }
        if (getTabular) {
            addZipEntry(zout, vertsFile.getAbsolutePath(), "vertices_" + exportTimestamp + ".tab");
            addZipEntry(zout, edgesFile.getAbsolutePath(), "edges_" + exportTimestamp + ".tab");
        }

        zout.close();

    } catch (IOException e) {
        throw new EJBException(e);
    }

    return zipOutputFile;
}

From source file:org.ejbca.core.protocol.ocsp.extension.unid.OCSPUnidExtension.java

@Override
public Map<ASN1ObjectIdentifier, Extension> process(X509Certificate[] requestCertificates, String remoteAddress,
        String remoteHost, X509Certificate cert, CertificateStatus status) {
    if (m_log.isTraceEnabled()) {
        m_log.trace(">process()");
    }/*from w  ww.  j a v a2s .c  o  m*/
    // Check authorization first
    if (!checkAuthorization(requestCertificates, remoteAddress, remoteHost)) {
        errCode = OCSPUnidExtension.ERROR_UNAUTHORIZED;
        return null;
    }
    // If the certificate is revoked, we must not return an FNR
    if (status != null) {
        errCode = OCSPUnidExtension.ERROR_CERT_REVOKED;
        return null;
    }
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet result = null;
    String fnr = null;
    String sn = null;
    try {
        // The Unis is in the DN component serialNumber
        sn = CertTools.getPartFromDN(cert.getSubjectDN().getName(), "SN");
        if (sn != null) {
            if (m_log.isDebugEnabled()) {
                m_log.debug("Found serialNumber: " + sn);
            }
            String iMsg = intres.getLocalizedMessage("ocsp.receivedunidreq", remoteAddress, remoteHost, sn);
            m_log.info(iMsg);
            try {
                con = ServiceLocator.getInstance().getDataSource(dataSourceJndi).getConnection();
            } catch (SQLException e) {
                String errMsg = intres.getLocalizedMessage("ocsp.errordatabaseunid");
                m_log.error(errMsg, e);
                errCode = OCSPUnidExtension.ERROR_SERVICE_UNAVAILABLE;
                return null;
            }
            ps = con.prepareStatement("select fnr from UnidFnrMapping where unid=?");
            ps.setString(1, sn);
            result = ps.executeQuery();
            if (result.next()) {
                fnr = result.getString(1);
            }
        } else {
            String errMsg = intres.getLocalizedMessage("ocsp.errorunidnosnindn", cert.getSubjectDN().getName());
            m_log.error(errMsg);
            errCode = OCSPUnidExtension.ERROR_NO_SERIAL_IN_DN;
            return null;
        }
        m_log.trace("<process()");
    } catch (Exception e) {
        throw new EJBException(e);
    } finally {
        JDBCUtil.close(con, ps, result);
    }

    // Construct the response extentsion if we found a mapping
    if (fnr == null) {
        String errMsg = intres.getLocalizedMessage("ocsp.errorunidnosnmapping", sn);
        m_log.error(errMsg);
        errCode = OCSPUnidExtension.ERROR_NO_FNR_MAPPING;
        return null;

    }
    String errMsg = intres.getLocalizedMessage("ocsp.returnedunidresponse", remoteAddress, remoteHost, fnr, sn);
    m_log.info(errMsg);
    FnrFromUnidExtension ext = new FnrFromUnidExtension(fnr);
    HashMap<ASN1ObjectIdentifier, Extension> ret = new HashMap<ASN1ObjectIdentifier, Extension>();
    try {
        ret.put(FnrFromUnidExtension.FnrFromUnidOid,
                new Extension(FnrFromUnidExtension.FnrFromUnidOid, false, new DEROctetString(ext)));
    } catch (IOException e) {
        throw new IllegalStateException("Unexpected IOException caught.", e);
    }
    return ret;
}

From source file:be.fedict.eid.dss.model.bean.IdentityServiceSingletonBean.java

/**
 * @return current identity's configuration or <codE>null</code> if none.
 *///from   w w w .j  a  v a 2s.co  m
public DSSIdentityConfig findIdentityConfig() {

    String activeIdentity = findActiveIdentityName();
    if (null == activeIdentity) {
        return null;
    }
    DSSIdentityConfig dssIdentityConfig = findIdentityConfig(activeIdentity);
    if (null == dssIdentityConfig) {
        throw new EJBException("Identity config " + activeIdentity + " not found!");
    }
    return dssIdentityConfig;
}

From source file:com.geodetix.geo.dao.PostGisGeometryDAOImpl.java

/**
 * PostGIS implementation of the entity bean's lifecicle method 
 * <code>ejbStore()</code>./*from w w  w.  j  a v  a 2  s  . c om*/
 * 
 * @param ejb the ejb whose data must be stored.
 * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
 */
public void store(com.geodetix.geo.ejb.GeometryBean ejb) throws javax.ejb.EJBException {

    PreparedStatement pstm = null;
    Connection con = null;

    try {

        con = this.dataSource.getConnection();

        pstm = con.prepareStatement(PostGisGeometryDAO.EJB_STORE_STATEMENT);

        pstm.setObject(1, new PGgeometry(ejb.getGeometry()));
        pstm.setString(2, ejb.getDescription());
        pstm.setInt(3, ejb.getId().intValue());

        if (pstm.executeUpdate() != 1) {
            throw new EJBException("ejbStore unable to update EJB.");
        }

    } catch (SQLException se) {

        throw new EJBException(se);

    } finally {

        try {
            if (pstm != null) {
                pstm.close();
            }
        } catch (Exception e) {
        }

        try {
            if (con != null) {
                con.close();
            }

        } catch (Exception e) {
        }
    }
}

From source file:gov.nih.nci.firebird.web.interceptor.FirebirdExceptionHandlingInterceptorTest.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test/*from  w  w w  .  java  2  s .  c  om*/
public void testIntercept_EJBException() throws Exception {
    when(mockInvocation.invoke()).thenThrow(new EJBException(new IllegalStateException()));

    try {
        interceptor.intercept(mockInvocation);
        fail();
    } catch (IllegalStateException e) {

    }

    ArgumentCaptor<Map> parametersCaptor = ArgumentCaptor.forClass(Map.class);
    verify(mockTemplateService).generateMessage(eq(FirebirdMessageTemplate.UNHANDLED_EXCEPTION_EMAIL),
            parametersCaptor.capture());
    Map<FirebirdTemplateParameter, Object> parameters = parametersCaptor.getValue();
    assertTrue(StringUtils.isNotBlank((String) parameters.get(FirebirdTemplateParameter.TIMESTAMP)));
    assertNull(parameters.get(FirebirdTemplateParameter.FIREBIRD_USER));
    assertEquals(TEST_URL, parameters.get(FirebirdTemplateParameter.REQUEST_URL));
    assertEquals("param = value1,value2\n", parameters.get(FirebirdTemplateParameter.REQUEST_PARAMETERS));
    assertTrue(StringUtils.isNotBlank((String) parameters.get(FirebirdTemplateParameter.STACKTRACE)));
    verify(mockEmailService).sendMessage(eq(TEST_SUPPORT_ADDRESS), anyCollectionOf(String.class),
            isNull(String.class), any(FirebirdMessage.class));
    verify(mockInvocation).invoke();
}

From source file:org.ejbca.core.protocol.ocsp.OCSPUnidExtension.java

/** Called by OCSP responder when the configured extension is found in the request.
 * //from   w  w  w .  j a  v  a  2  s.  co  m
 * @param request HttpServletRequest that can be used to find out information about caller, TLS certificate etc.
 * @param cert X509Certificate the caller asked for in the OCSP request
  * @param status CertificateStatus the status the certificate has according to the OCSP responder, null means the cert is good
 * @return X509Extension that will be added to responseExtensions by OCSP responder, or null if an error occurs
 */
public Hashtable process(HttpServletRequest request, X509Certificate cert, CertificateStatus status) {
    if (m_log.isTraceEnabled()) {
        m_log.trace(">process()");
    }
    // Check authorization first
    if (!checkAuthorization(request)) {
        errCode = OCSPUnidExtension.ERROR_UNAUTHORIZED;
        return null;
    }
    // If the certificate is revoked, we must not return an FNR
    if (status != null) {
        errCode = OCSPUnidExtension.ERROR_CERT_REVOKED;
        return null;
    }
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet result = null;
    String fnr = null;
    String sn = null;
    try {
        // The Unis is in the DN component serialNumber
        sn = CertTools.getPartFromDN(cert.getSubjectDN().getName(), "SN");
        if (sn != null) {
            if (m_log.isDebugEnabled()) {
                m_log.debug("Found serialNumber: " + sn);
            }
            String iMsg = intres.getLocalizedMessage("ocsp.receivedunidreq", request.getRemoteAddr(),
                    request.getRemoteHost(), sn);
            m_log.info(iMsg);
            try {
                con = ServiceLocator.getInstance().getDataSource(dataSourceJndi).getConnection();
            } catch (SQLException e) {
                String errMsg = intres.getLocalizedMessage("ocsp.errordatabaseunid");
                m_log.error(errMsg, e);
                errCode = OCSPUnidExtension.ERROR_SERVICE_UNAVAILABLE;
                return null;
            }
            ps = con.prepareStatement("select fnr from UnidFnrMapping where unid=?");
            ps.setString(1, sn);
            result = ps.executeQuery();
            if (result.next()) {
                fnr = result.getString(1);
            }
        } else {
            String errMsg = intres.getLocalizedMessage("ocsp.errorunidnosnindn", cert.getSubjectDN().getName());
            m_log.error(errMsg);
            errCode = OCSPUnidExtension.ERROR_NO_SERIAL_IN_DN;
            return null;
        }
        m_log.trace("<process()");
    } catch (Exception e) {
        throw new EJBException(e);
    } finally {
        JDBCUtil.close(con, ps, result);
    }

    // Construct the response extentsion if we found a mapping
    if (fnr == null) {
        String errMsg = intres.getLocalizedMessage("ocsp.errorunidnosnmapping", sn);
        m_log.error(errMsg);
        errCode = OCSPUnidExtension.ERROR_NO_FNR_MAPPING;
        return null;

    }
    String errMsg = intres.getLocalizedMessage("ocsp.returnedunidresponse", request.getRemoteAddr(),
            request.getRemoteHost(), fnr, sn);
    m_log.info(errMsg);
    FnrFromUnidExtension ext = new FnrFromUnidExtension(fnr);
    Hashtable ret = new Hashtable();
    ret.put(FnrFromUnidExtension.FnrFromUnidOid, new X509Extension(false, new DEROctetString(ext)));
    return ret;
}

From source file:com.egt.ejb.toolkit.ToolKitSessionBean.java

@Override
public void generarURX() {
    Utils.traceContext();//from  w  w w  .j a  va2 s  .  c o m
    //      List<Aplicacion> aplicaciones = aplicacionFacade.findAll(REFRESH);
    List<Aplicacion> aplicaciones = aplicacionFacade.findAll(REFRESH);
    try {
        generarURX(aplicaciones);
        TLC.getBitacora().info(Bundle.getString("generar.urx.ok"));
    } catch (Exception ex) {
        //          TLC.getBitacora().fatal(ex);
        throw ex instanceof EJBException ? (EJBException) ex : new EJBException(ex);
    }
}

From source file:edu.harvard.iq.dvn.core.study.StudyServiceBean.java

public void setReleased(Long studyId, String versionNote) {

    Study study = em.find(Study.class, studyId);
    StudyVersion latestVersion = study.getLatestVersion();
    if (!latestVersion.isWorkingCopy()) {
        throw new EJBException(
                "Cannot release latestVersion, incorrect state: " + latestVersion.getVersionState());
    }/*from  w ww  .ja  v  a 2 s. c  om*/

    Date releaseDate = new Date();

    // Archive the previously released or deaccessioned version
    StudyVersion releasedVersion = study.getReleasedVersion();
    if (releasedVersion != null) {
        releasedVersion.setVersionState(StudyVersion.VersionState.ARCHIVED);
        releasedVersion.setArchiveTime(releaseDate);
        releasedVersion.setArchiveNote("Replaced by version " + latestVersion.getVersionNumber());
    } else {
        StudyVersion deaccessionedVersion = study.getDeaccessionedVersion();
        if (deaccessionedVersion != null) {
            deaccessionedVersion.setVersionState(StudyVersion.VersionState.ARCHIVED);
        }
    }

    latestVersion.setVersionState(StudyVersion.VersionState.RELEASED);
    latestVersion.setReleaseTime(releaseDate);

    if (versionNote != null) {
        latestVersion.setVersionNote(versionNote);
    }

    VDCRole studyCreatorRole = study.getCreator().getVDCRole(study.getOwner());

    if (studyCreatorRole != null && studyCreatorRole.getRole().getName().equals(RoleServiceLocal.CONTRIBUTOR)) {
        mailService.sendStudyReleasedNotification(study.getCreator().getEmail(),
                latestVersion.getMetadata().getTitle(), study.getOwner().getName());
    }
    //if DOI then publicize status
    if (study.getProtocol().equals("doi")) {
        doiEZIdServiceLocal.publicizeIdentifier(study);
    }

    // tweet release of study
    TwitterCredentials tc = study.getOwner().getTwitterCredentials();
    if (tc != null) {
        String message = latestVersion.getVersionNumber() == 1 ? "New study released: " : "Study updated: ";
        message += latestVersion.getMetadata().getTitle();
        URL url = new GlobalId(latestVersion.getStudy().getProtocol(), latestVersion.getStudy().getAuthority(),
                latestVersion.getStudy().getStudyId()).toURL();
        TwitterUtil.tweet(tc, message, url);
    }

    // finally, re-index the study metadata:
    indexService.updateStudy(studyId);
}

From source file:edu.harvard.iq.dvn.core.analysis.NetworkDataServiceBean.java

@Remove
public void ingest(StudyFileEditBean editBean) {
    dbgLog.fine("Begin ingest() ");
    // Initialize NetworkDataFile with new DataTable objects
    NetworkDataFile ndf = (NetworkDataFile) editBean.getStudyFile();

    DataTable vertexTable = new DataTable();
    vertexTable.setStudyFile(ndf);/*from   www  .  j  a  va  2s  .  co m*/
    vertexTable.setDataVariables(new ArrayList<DataVariable>());
    ndf.setVertexDataTable(vertexTable);

    DataTable edgeTable = new DataTable();
    edgeTable.setStudyFile(ndf);
    edgeTable.setDataVariables(new ArrayList<DataVariable>());
    ndf.setEdgeDataTable(edgeTable);

    try {
        // Populate DataTables using GraphML file
        processXML(editBean.getTempSystemFileLocation(), ndf);

        //Copy GraphML file to "ingested" location
        copyFile(editBean);
    } catch (Exception e) {
        throw new EJBException(e);
    }

    // Convert the GraphML file to a Neo4j DB File (for the qraph stucture, and a SQLite set of files (for the property values), and
    // save it in "ingested" location so it can be loaded later for subsetting
    saveNetworkDBFiles(editBean);

}