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:edu.harvard.i2b2.oauth2.AccessTokenService.java

public AccessToken createAccessTokenAndDeleteAuthToken(AuthToken authToken) {
    try {/*from   w w  w . j a v a 2  s.co  m*/
        OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
        final String accessTokenCode = oauthIssuerImpl.accessToken();

        AccessToken tok = new AccessToken();
        tok.setTokenString(accessTokenCode);
        tok.setResourceUserId(authToken.getResourceUserId());
        tok.setI2b2Token(authToken.getI2b2Token());
        tok.setI2b2Project(authToken.getI2b2Project());
        tok.setClientId(authToken.getClientId());
        tok.setScope(authToken.getScope());
        tok.setCreatedDate(new Date());
        tok.setExpiryDate(DateUtils.addMinutes(new Date(), 30));
        tok.setI2b2Url(authToken.getI2b2Url());
        tok.setI2b2Domain(authToken.getI2b2Domain());

        logger.info("Created .." + tok.toString());
        //// em.getTransaction().begin();
        em.persist(tok);

        AuthToken authTok = em.find(AuthToken.class, authToken.getAuthorizationCode());
        if (authTok == null)
            throw new RuntimeException("auth Tok was not found");
        logger.info("Removing authTok ");
        em.remove(authTok);

        //// em.getTransaction().commit();

        logger.info("Persisted " + tok.toString());
        return tok;
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        // em.getTransaction().rollback();
        throw new EJBException(ex.getMessage());
    }
}

From source file:edu.harvard.i2b2.fhirserver.ejb.AccessTokenBean.java

public void removeAccessToken(AccessToken authToken) {
    try {/*from  w w  w .  j  a  v a2s.  c  o  m*/
        em.getTransaction().begin();
        em.remove(authToken);
        em.getTransaction().commit();
    } catch (Exception ex) {
        em.getTransaction().rollback();
        logger.error(ex.getMessage(), ex);
        throw new EJBException(ex.getMessage());
    }
}

From source file:edu.harvard.i2b2.oauth2.AccessTokenService.java

public List<AccessToken> getAuthTokens() {
    try {/*from   w w  w .j a v a2  s  .c  o m*/
        List<AccessToken> tokens = em.createQuery("from AccessToken").getResultList();
        // em.getTransaction().commit();
        return tokens;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new EJBException(e.getMessage());
    }
}

From source file:net.maxgigapop.mrs.driver.GenericRESTDriver.java

@Override
@Asynchronous/*from w w  w. j  a  v a  2 s  . com*/
@SuppressWarnings("empty-statement")
public Future<String> pullModel(Long driverInstanceId) {
    DriverInstance driverInstance = DriverInstancePersistenceManager.findById(driverInstanceId);
    if (driverInstance == null) {
        throw new EJBException(String.format("pullModel cannot find driverInance(id=%d)", driverInstanceId));
    }
    String subsystemBaseUrl = driverInstance.getProperty("subsystemBaseUrl");
    if (subsystemBaseUrl == null) {
        throw new EJBException(String.format("%s has no property key=subsystemBaseUrl", driverInstance));
    }
    if (DriverInstancePersistenceManager.getDriverInstanceByTopologyMap() == null
            || !DriverInstancePersistenceManager.getDriverInstanceByTopologyMap()
                    .containsKey(driverInstance.getTopologyUri())) {
        return new AsyncResult<>("INITIALIZING");
    }
    // sync on cached DriverInstance object = once per driverInstance to avoid write multiple vi of same version 
    DriverInstance syncOnDriverInstance = DriverInstancePersistenceManager.getDriverInstanceByTopologyMap()
            .get(driverInstance.getTopologyUri());
    synchronized (syncOnDriverInstance) {
        String version = null;
        String ttlModel = null;
        String creationTimestamp = null;
        try {
            if (driverInstance.getHeadVersionItem() != null) {
                URL url = new URL(
                        subsystemBaseUrl + "/model/" + driverInstance.getHeadVersionItem().getReferenceUUID());
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                String status = this.executeHttpMethod(url, conn, "GET", null);
                if (status.toUpperCase().equals("LATEST")) {
                    return new AsyncResult<>("SUCCESS");
                }
            }
            // pull model from REST API
            URL url = new URL(subsystemBaseUrl + "/model");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            String responseStr = this.executeHttpMethod(url, conn, "GET", null);
            JSONObject responseJSON = (JSONObject) JSONValue.parseWithException(responseStr);
            version = responseJSON.get("version").toString();
            if (version == null || version.isEmpty()) {
                throw new EJBException(String.format("%s pulled model from subsystem with null/empty version",
                        driverInstance));
            }
            ttlModel = responseJSON.get("ttlModel").toString();
            if (ttlModel == null || ttlModel.isEmpty()) {
                throw new EJBException(String.format(
                        "%s pulled model from subsystem with null/empty ttlModel content", driverInstance));
            }
            creationTimestamp = responseJSON.get("creationTime").toString();
            if (creationTimestamp == null || creationTimestamp.isEmpty()) {
                throw new EJBException(String
                        .format("%s pulled model from subsystem with null/empty creationTime", driverInstance));
            }
        } catch (IOException ex) {
            throw new EJBException(
                    String.format("%s failed to connect to subsystem with exception (%s)", driverInstance, ex));
        } catch (ParseException ex) {
            throw new EJBException(
                    String.format("%s failed to parse pulled information from subsystem with exception (%s)",
                            driverInstance, ex));
        }
        VersionItem vi = null;
        DriverModel dm = null;
        try {
            // check if this version has been pulled before
            vi = VersionItemPersistenceManager.findByReferenceUUID(version);
            if (vi != null) {
                return new AsyncResult<>("SUCCESS");
            }
            // create new driverDelta and versioItem
            OntModel ontModel = ModelUtil.unmarshalOntModel(ttlModel);
            dm = new DriverModel();
            dm.setCommitted(true);
            dm.setOntModel(ontModel);
            Date creationTime = new Date(Long.parseLong(creationTimestamp));
            dm.setCreationTime(creationTime);
            ModelPersistenceManager.save(dm);
            vi = new VersionItem();
            vi.setModelRef(dm);
            vi.setReferenceUUID(version);
            vi.setDriverInstance(driverInstance);
            VersionItemPersistenceManager.save(vi);
            driverInstance.setHeadVersionItem(vi);
            VersionItemPersistenceManager.save(vi);
            logger.info(String.format("persisted %s", vi));
        } catch (Exception e) {
            try {
                if (dm != null) {
                    ModelPersistenceManager.delete(dm);
                }
                if (vi != null) {
                    VersionItemPersistenceManager.delete(vi);
                }
            } catch (Exception ex) {
                ; // do nothing (logging?)
            }
            throw new EJBException(
                    String.format("pullModel on %s raised exception[%s]", driverInstance, e.getMessage()));
        }
    }
    return new AsyncResult<>("SUCCESS");
}

From source file:edu.harvard.i2b2.oauth2.AccessTokenService.java

public void removeAccessToken(AccessToken authToken) {
    try {/* w w w .j  a  v a 2  s  . c o m*/
        // em.getTransaction().begin();
        em.remove(authToken);
        // em.getTransaction().commit();
    } catch (Exception ex) {
        // em.getTransaction().rollback();
        logger.error(ex.getMessage(), ex);
        throw new EJBException(ex.getMessage());
    }
}

From source file:edu.harvard.i2b2.fhirserver.ejb.AccessTokenBean.java

public AccessToken find(String accessCode) {
    try {/*  w w  w .jav  a  2 s .co m*/
        em.getTransaction().begin();
        logger.trace("find accesstok with id:" + accessCode);
        AccessToken tok = em.find(AccessToken.class, accessCode);
        if (tok != null) {
            logger.info("returning :" + tok);
        } else {
            logger.info("NOT found");
        }
        em.getTransaction().commit();
        return tok;
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        em.getTransaction().rollback();
        throw new EJBException(ex.getMessage());
    }

}

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

@Override
public void generarFacade() {
    try {//  www.j a  v a 2s.c o  m
        VelocityContext context = new VelocityContext();
        String query = VelocityEngineer.write(context, "sdk-query-generar-facade.vm").toString();
        List<SystemTable> systemTables = systemTableFacade.findByQuery(query, EnumTipoQuery.NATIVE, REFRESH);
        generarFacade(systemTables);
        TLC.getBitacora().info(Bundle.getString("generar.facades.ok"), systemTables.size());
    } catch (Exception ex) {
        //          TLC.getBitacora().fatal(ex);
        throw ex instanceof EJBException ? (EJBException) ex : new EJBException(ex);
    }
}

From source file:edu.harvard.i2b2.oauth2.AccessTokenService.java

public AccessToken find(String accessCode) {
    try {/*ww w  .ja  va2  s .c  o m*/
        // em.getTransaction().begin();
        logger.trace("find accesstok with id:" + accessCode);
        AccessToken tok = em.find(AccessToken.class, accessCode);
        if (tok != null) {
            logger.info("returning :" + tok);
        } else {
            logger.info("NOT found");
        }
        // em.getTransaction().commit();
        return tok;
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        // em.getTransaction().rollback();
        throw new EJBException(ex.getMessage());
    }

}

From source file:com.stratelia.webactiv.newsEdito.control.NewsEditoSessionController.java

/**
 * Method declaration/*  w w w .  j  av a 2 s.  c o m*/
 *
 * @param pubId
 * @see
 */
public void initNavigationForPublication(String pubId) throws NewsEditoException {
    try {
        Collection<NodePK> result = publicationBm
                .getAllFatherPK(new PublicationPK(pubId, getSpaceId(), getComponentId()));

        if (result.size() > 2) // 1 -> article normal, 2->article apparaissant
        // aussi dans l'dito
        {
            throw new EJBException("Cette publication a plus de deux noeud pere, mais " + result.size());
        }
        Iterator<NodePK> i = result.iterator();
        NodePK titlePK = i.next();

        if (nodeBm.getHeader(titlePK).getFatherPK().getId().equals("0") && (i.hasNext())) {
            titlePK = (NodePK) i.next();
        }

        NodePK archivePK = nodeBm.getHeader(titlePK).getFatherPK();

        if (!nodeBm.getHeader(archivePK).getFatherPK().getId().equals("0")) {
            throw new EJBException("Cette publication n'est ratachee a aucun titre ");

        }
        setArchiveId(archivePK.getId());
        setTitleId(titlePK.getId());
        setPublicationId(pubId);
    } catch (Exception e) {
        throw new NewsEditoException("NewsEditoSessionControl.getArchiveList", NewsEditoException.ERROR,
                "NewsEdito.EX_PROBLEM_TO_INITIALIZE_NAV_PUBLI", e);
    }
}

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

/**
 * PostGIS implementation of the entity bean's life cycle method 
 * <code>ejbLoad()</code>./*from   ww w . ja  v  a2 s  . co m*/
 * 
 * @param pk the primary key of the bean to load.
 * @param ejb the ejb whose data must be loaded.
 * @throws javax.ejb.EJBException launched if a generic EJB error is encountered.
 */
public void load(java.lang.Integer pk, com.geodetix.geo.ejb.GeometryBean ejb) throws javax.ejb.EJBException {

    PreparedStatement pstm = null;
    Connection con = null;
    ResultSet result = null;

    try {

        con = this.dataSource.getConnection();

        pstm = con.prepareStatement(PostGisGeometryDAO.EJB_LOAD_STATEMENT);

        pstm.setInt(1, pk.intValue());

        result = pstm.executeQuery();

        if (result.next()) {
            ejb.setId(pk);
            ejb.setGeometry(((PGgeometry) result.getObject("geometry")).getGeometry());
            ejb.setDescription((String) result.getString("description"));

        } else {

            throw new EJBException("ejbLoad unable to load EJB.");
        }

    } catch (SQLException se) {
        throw new EJBException(se);

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

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

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