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(String message, Exception ex) 

Source Link

Document

Constructs an EJBException that embeds the originally thrown exception with the specified detail message.

Usage

From source file:org.apache.cactus.spi.server.MessageDrivenBeanRedirector.java

/**
 * Called by the container to create an instance of this Message Driven
 * bean.//from w w  w.  ja  va 2 s . c  om
 *
 * @exception CreateException see the EJB specification
 */
public void ejbCreate() throws CreateException {
    LOGGER.debug("------------- MDB redirector service created");

    try {
        InitialContext initContext = new InitialContext();
        QueueConnectionFactory qcf = (QueueConnectionFactory) initContext.lookup("java:comp/env/jms/QCF1");
        connection = qcf.createQueueConnection();
        session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        connection.start();
    } catch (Exception e) {
        throw new EJBException("Failed to initialize MyMDB", e);
    }
}

From source file:Employee.java

 @PostConstruct
public void jndiInject(InvocationContext invocation) {
   Object target = invocation.getTarget();
   Field[] fields = target.getClass().getDeclaredFields();
   Method[] methods = target.getClass().getDeclaredMethods();

   // find all @JndiInjected fields methods and set them
   try {//from w w w  .  java  2s.c  om
      InitialContext ctx = new InitialContext();
      for (Method method : methods) {
         JndiInjected inject = method.getAnnotation(JndiInjected.class);
         if (inject != null) {
            Object obj = ctx.lookup(inject.value());
            method.setAccessible(true);
            method.invoke(target, obj);
         }
      }
      for (Field field : fields) {
         JndiInjected inject = field.getAnnotation(JndiInjected.class);
         if (inject != null) {
            Object obj = ctx.lookup(inject.value());
            field.setAccessible(true);
            field.set(target, obj);
         }
      }
      invocation.proceed();
   } catch (Exception ex) {
      throw new EJBException("Failed to execute @JndiInjected", ex);
   }
}

From source file:org.gss_project.gss.server.ejb.indexer.IndexerMDBean.java

/**
 * Decides to add or drop an item from the index depending on the message
 * received/*from  w w  w  . jav  a 2s  .c o  m*/
 *
 * It currently uses the patched solr API for rich documents. This API does not
 * allow indexing time field boosting. For this reason we have to use the dismax search API (instead of the
 * standard) that allows for search time field boosting
 *
 * @param msg
 * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
 */
@Override
public void onMessage(Message msg) {
    Long id = null;
    try {
        MapMessage map = (MapMessage) msg;
        id = (Long) map.getObject("id");
        boolean delete = map.getBoolean("delete");
        if (delete) {
            CommonsHttpSolrServer solr = new CommonsHttpSolrServer(getConfiguration().getString("solr.url"));
            sendDelete(solr, id);
            solr.commit();
        } else {
            service.postFileToSolr(id);
        }
    } catch (JMSException e) {
        throw new EJBException("Error processing file ID " + id, e);
    } catch (IOException e) {
        throw new EJBException("Error processing file ID " + id, e);
    } catch (SolrServerException e) {
        throw new EJBException(e);
    } catch (ObjectNotFoundException e) {
        throw new EJBException(e);
    }
}

From source file:org.ejbca.core.model.approval.approvalrequests.EditEndEntityApprovalRequest.java

public void execute(EndEntityManagementSession endEntityManagementSession)
        throws ApprovalRequestExecutionException {
    log.debug("Executing ChangeEndEntity for user:" + newuserdata.getUsername());
    try {//from  w ww . ja v a2 s  .  c o m
        endEntityManagementSession.changeUser(getRequestAdmin(), newuserdata, clearpwd);
    } catch (AuthorizationDeniedException e) {
        throw new ApprovalRequestExecutionException("Authorization Denied :" + e.getMessage(), e);
    } catch (UserDoesntFullfillEndEntityProfile e) {
        throw new ApprovalRequestExecutionException(
                "User Doesn't fullfil end entity profile :" + e.getMessage() + e.getMessage(), e);
    } catch (ApprovalException e) {
        throw new EJBException("This should never happen", e);
    } catch (WaitingForApprovalException e) {
        throw new EJBException("This should never happen", e);
    } catch (EjbcaException e) {
        throw new ApprovalRequestExecutionException(
                "Error with the SubjectDN serialnumber :" + e.getErrorCode() + e.getMessage(), e);
    } catch (CADoesntExistsException e) {
        throw new ApprovalRequestExecutionException("CA does not exist:" + e.getMessage(), e);
    }
}

From source file:org.jbpm.ejb.impl.CommandListenerBean.java

private Session createSession() throws JMSException {
    if (jmsConnection == null) {
        // lookup factory and create jms connection
        try {/*  w  ww .  j ava  2 s .  c o  m*/
            Context initial = new InitialContext();
            ConnectionFactory jmsConnectionFactory = (ConnectionFactory) initial
                    .lookup("java:comp/env/jms/JbpmConnectionFactory");
            jmsConnection = jmsConnectionFactory.createConnection();
        } catch (NamingException e) {
            throw new EJBException("error retrieving jms connection factory", e);
        }
    }
    /*
     * if the connection supports xa, the session will be transacted, else the
     * session will auto acknowledge; in either case no explicit transaction
     * control must be performed - see ejb 2.1 17.3.5
     */
    return jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}

From source file:com.stratelia.webactiv.survey.control.SurveySessionController.java

/**
 * Instantiate a question Container Bean Manager
 *///from ww  w  . ja  va 2 s  .  c  o  m
private void setQuestionContainerBm() {
    if (questionContainerBm == null) {
        try {
            questionContainerBm = EJBUtilitaire.getEJBObjectRef(JNDINames.QUESTIONCONTAINERBM_EJBHOME,
                    QuestionContainerBm.class);
        } catch (Exception e) {
            throw new EJBException(e.getMessage(), e);
        }
    }
}

From source file:com.stratelia.webactiv.survey.control.SurveySessionController.java

private void setQuestionResultBm() {
    if (questionResultBm == null) {
        try {/*from   w ww  .j av  a 2 s  .c o m*/
            questionResultBm = EJBUtilitaire.getEJBObjectRef(JNDINames.QUESTIONRESULTBM_EJBHOME,
                    QuestionResultBm.class);
        } catch (Exception e) {
            throw new EJBException(e.getMessage(), e);
        }
    }
}

From source file:org.jbpm.ejb.impl.CommandListenerBean.java

public void ejbCreate() {
    try {//www . j ava 2  s . co m
        Context initial = new InitialContext();
        LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome) initial
                .lookup("java:comp/env/ejb/LocalCommandServiceBean");
        commandService = commandServiceHome.create();
    } catch (NamingException e) {
        throw new EJBException("error retrieving command service home", e);
    } catch (CreateException e) {
        throw new EJBException("error creating command service", e);
    }
}

From source file:org.cesecore.certificates.ocsp.OcspResponseGeneratorSessionBean.java

/**
 * Checks the signature on an OCSP request. Does not check for revocation of the signer certificate
 * /*from  ww  w. j  a  va 2 s  . c  o  m*/
 * @param clientRemoteAddr The IP address or host name of the remote client that sent the request, can be null.
 * @param req The signed OCSPReq
 * @return X509Certificate which is the certificate that signed the OCSP request
 * @throws SignRequestSignatureException if signature verification fail, or if the signing certificate is not authorized
 * @throws SignRequestException if there is no signature on the OCSPReq
 * @throws OCSPException if the request can not be parsed to retrieve certificates
 * @throws NoSuchProviderException if the BC provider is not installed
 * @throws CertificateException if the certificate can not be parsed
 * @throws NoSuchAlgorithmException if the certificate contains an unsupported algorithm
 * @throws InvalidKeyException if the certificate, or CA key is invalid
 */
private X509Certificate checkRequestSignature(String clientRemoteAddr, OCSPReq req) throws SignRequestException,
        SignRequestSignatureException, CertificateException, NoSuchAlgorithmException {
    X509Certificate signercert = null;
    // Get all certificates embedded in the request (probably a certificate chain)
    try {
        final X509CertificateHolder[] certs = req.getCerts();
        String signerSubjectDn = null;
        // We must find a certificate to verify the signature with...
        boolean verifyOK = false;
        for (int i = 0; i < certs.length; i++) {
            final X509Certificate certificate = certificateConverter.getCertificate(certs[i]);
            try {
                if (req.isSignatureValid(
                        new JcaContentVerifierProviderBuilder().build(certificate.getPublicKey()))) {
                    signercert = certificate; // if the request signature verifies by this certificate, this is the signer cert 
                    signerSubjectDn = CertTools.getSubjectDN(signercert);
                    log.info(intres.getLocalizedMessage("ocsp.infosigner", signerSubjectDn));
                    verifyOK = true;
                    // Check that the signer certificate can be verified by one of the CA-certificates that we answer for
                    final X509Certificate signerca = CaCertificateCache.INSTANCE
                            .findLatestBySubjectDN(HashID.getFromIssuerDN(signercert));
                    if (signerca != null) {
                        try {
                            signercert.verify(signerca.getPublicKey());
                            final Date now = new Date();
                            if (log.isDebugEnabled()) {
                                log.debug("Checking validity. Now: " + now + ", signerNotAfter: "
                                        + signercert.getNotAfter());
                            }
                            try {
                                // Check validity of the request signing certificate
                                CertTools.checkValidity(signercert, now);
                            } catch (CertificateNotYetValidException e) {
                                log.info(intres.getLocalizedMessage("ocsp.infosigner.certnotyetvalid",
                                        signerSubjectDn, CertTools.getIssuerDN(signercert), e.getMessage()));
                                verifyOK = false;
                            } catch (CertificateExpiredException e) {
                                log.info(intres.getLocalizedMessage("ocsp.infosigner.certexpired",
                                        signerSubjectDn, CertTools.getIssuerDN(signercert), e.getMessage()));
                                verifyOK = false;
                            }
                            try {
                                // Check validity of the CA certificate
                                CertTools.checkValidity(signerca, now);
                            } catch (CertificateNotYetValidException e) {
                                log.info(intres.getLocalizedMessage("ocsp.infosigner.certnotyetvalid",
                                        CertTools.getSubjectDN(signerca), CertTools.getIssuerDN(signerca),
                                        e.getMessage()));
                                verifyOK = false;
                            } catch (CertificateExpiredException e) {
                                log.info(intres.getLocalizedMessage("ocsp.infosigner.certexpired",
                                        CertTools.getSubjectDN(signerca), CertTools.getIssuerDN(signerca),
                                        e.getMessage()));
                                verifyOK = false;
                            }
                        } catch (SignatureException e) {
                            log.info(intres.getLocalizedMessage("ocsp.infosigner.invalidcertsignature",
                                    signerSubjectDn, CertTools.getIssuerDN(signercert), e.getMessage()));
                            verifyOK = false;
                        } catch (InvalidKeyException e) {
                            log.info(intres.getLocalizedMessage("ocsp.infosigner.invalidcertsignature",
                                    signerSubjectDn, CertTools.getIssuerDN(signercert), e.getMessage()));
                            verifyOK = false;
                        }
                    } else {
                        log.info(intres.getLocalizedMessage("ocsp.infosigner.nocacert", signerSubjectDn,
                                CertTools.getIssuerDN(signercert)));
                        verifyOK = false;
                    }
                    break;
                }
            } catch (OperatorCreationException e) {
                // Very fatal error
                throw new EJBException("Can not create Jca content signer: ", e);
            }
        }
        if (!verifyOK) {
            if (signerSubjectDn == null && certs.length > 0) {
                signerSubjectDn = CertTools.getSubjectDN(certificateConverter.getCertificate(certs[0]));
            }
            String errMsg = intres.getLocalizedMessage("ocsp.errorinvalidsignature", signerSubjectDn);
            log.info(errMsg);
            throw new SignRequestSignatureException(errMsg);
        }
    } catch (OCSPException e) {
        throw new CryptoProviderException("BouncyCastle was not initialized properly.", e);
    } catch (NoSuchProviderException e) {
        throw new CryptoProviderException("BouncyCastle was not found as a provider.", e);
    }
    return signercert;
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public void revokeUser(Admin admin, String username, int reason) throws AuthorizationDeniedException,
        FinderException, ApprovalException, WaitingForApprovalException, AlreadyRevokedException {
    if (log.isTraceEnabled()) {
        log.trace(">revokeUser(" + username + ")");
    }//from   w  ww .j a v  a  2s.  co m
    final UserData userData = UserData.findByUsername(entityManager, username);
    if (userData == null) {
        throw new FinderException("Could not find user " + username);
    }
    final int caid = userData.getCaId();
    assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
    if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
        assertAuthorizedToEndEntityProfile(admin, userData.getEndEntityProfileId(),
                AccessRulesConstants.REVOKE_RIGHTS, caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
    }
    if (userData.getStatus() == UserDataConstants.STATUS_REVOKED) {
        final String msg = intres.getLocalizedMessage("ra.errorbadrequest",
                Integer.valueOf(userData.getEndEntityProfileId()));
        logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                LogConstants.EVENT_INFO_REVOKEDENDENTITY, msg);
        throw new AlreadyRevokedException(msg);
    }
    // Check if approvals is required.
    final int numOfReqApprovals = getNumOfApprovalRequired(admin, CAInfo.REQ_APPROVAL_REVOCATION, caid,
            userData.getCertificateProfileId());
    if (numOfReqApprovals > 0) {
        final RevocationApprovalRequest ar = new RevocationApprovalRequest(false, username, reason, admin,
                numOfReqApprovals, caid, userData.getEndEntityProfileId());
        if (ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_REVOKEUSER)) {
            approvalSession.addApprovalRequest(admin, ar, getGlobalConfiguration(admin));
            throw new WaitingForApprovalException(intres.getLocalizedMessage("ra.approvalrevoke"));
        }
    }
    // Revoke all certs, one at the time
    final Collection<Certificate> certs = certificateStoreSession.findCertificatesByUsername(admin, username);
    for (final Certificate cert : certs) {
        try {
            revokeCert(admin, CertTools.getSerialNumber(cert), CertTools.getIssuerDN(cert), reason);
        } catch (AlreadyRevokedException e) {
            if (log.isDebugEnabled()) {
                log.debug("Certificate from issuer '" + CertTools.getIssuerDN(cert) + "' with serial "
                        + CertTools.getSerialNumber(cert) + " was already revoked.");
            }
        }
    }
    // Finally set revoke status on the user as well
    try {
        setUserStatus(admin, userData, UserDataConstants.STATUS_REVOKED);
    } catch (ApprovalException e) {
        throw new EJBException("This should never happen", e);
    } catch (WaitingForApprovalException e) {
        throw new EJBException("This should never happen", e);
    }
    final String msg = intres.getLocalizedMessage("ra.revokedentity", username);
    logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
            LogConstants.EVENT_INFO_REVOKEDENDENTITY, msg);
    if (log.isTraceEnabled()) {
        log.trace("<revokeUser()");
    }
}