Example usage for java.util.concurrent ExecutionException ExecutionException

List of usage examples for java.util.concurrent ExecutionException ExecutionException

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException ExecutionException.

Prototype

public ExecutionException(String message, Throwable cause) 

Source Link

Document

Constructs an ExecutionException with the specified detail message and cause.

Usage

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

protected boolean licensedOganizationExists(String orgId) throws ExecutionException {
    NamingEnumeration<SearchResult> searchResults = null;
    try {/*from w  w w .  j a  va  2s .  c  o  m*/
        searchResults = this.query(LDAPConnector.getSingletonInstance().getLicensedInstitutionsBaseDN(),
                new StringBuilder("(& (objectclass=").append(Constants.ldap_ddbOrg_ObjectClass).append(") (")
                        .append(Constants.ldap_ddbOrg_Id).append("=").append(orgId).append("))").toString(),
                new String[] { Constants.ldap_ddbOrg_Id, "+" }, SearchControls.SUBTREE_SCOPE);
        if (searchResults.hasMore()) {
            return true;
        } else {
            return false;
        }
    } catch (IllegalAccessException ex) {
        LOG.log(Level.SEVERE, "Connection-Error", ex);
        throw new ExecutionException(ex.getMessage(), ex.getCause());
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, "something went wrong while checking if userId exists", ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        if (searchResults != null) {
            try {
                searchResults.close();
            } catch (NamingException e) {
            }
        }
    }
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

protected Organisation convertLdapGroupsToOrganizationPrivileges(Organisation pOrg,
        NamingEnumeration<SearchResult> pPrivilegesResult) throws ExecutionException {
    try {/*w  w w . j  a  v a 2  s . c om*/
        if (pPrivilegesResult != null) {
            PrivilegeEnum p;
            SearchResult sr;
            String vCnPrivileg;
            // construct privileges
            while (pPrivilegesResult.hasMore()) {
                sr = pPrivilegesResult.next();
                vCnPrivileg = (String) sr.getAttributes().get(Constants.ldap_ddbPrivilege_Cn).get();
                p = this.mapToPrivilege(sr.getAttributes(), Constants.ldap_ddbPrivilege_Cn);
                if (p != null) {
                    pOrg.addPrivileges(p);
                } else {
                    LOG.log(Level.WARNING,
                            "Die Organisation ''{0}'' verfgt ber einen nicht existierende Privileg: ''{1}''!",
                            new Object[] { pOrg.getId(), vCnPrivileg });
                }
            }
            // -- releases this context's resources immediately, instead of waiting for the garbage collector
            pPrivilegesResult.close();
        }
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, null, ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        // -- releases this context's resources immediately, instead of waiting for the garbage collector
        if (pPrivilegesResult != null) {
            try {
                pPrivilegesResult.close();
            } catch (NamingException ex) {
            }
        }
    }
    return pOrg;
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

public NamingEnumeration<SearchResult> getAllSubOrgs(boolean pLicensedOrgs, OIDs pOIDs, int pScopy,
        String[] attributeFilter, AasPrincipal pPerformer) throws ExecutionException {
    if (pPerformer == null) {
        throw new IllegalArgumentException("The contractor is unknown: Performer == null");
    }//  www .ja  v  a2s  . c om
    if (attributeFilter == null) {
        attributeFilter = new String[] { "*", "+" };
    }

    String orgRdn = pOIDs.getOrgRDN();
    if (StringUtils.isEmpty(orgRdn)) {
        orgRdn = getOrgRdnForOrgId(pOIDs, pPerformer);
    }

    if (orgRdn == null) {
        throw new ExecutionException("OrgRDN = null", null);
    }
    InitialLdapContext ctx = null;
    try {
        ctx = LDAPConnector.getSingletonInstance().takeCtx();
        StringBuilder vBaseDn = new StringBuilder(Constants.ldap_ddbOrg_Id).append("=")
                .append(orgRdn.replaceAll(",", "," + Constants.ldap_ddbOrg_Id + "=")).append(",")
                .append((!pLicensedOrgs ? LDAPConnector.getSingletonInstance().getInstitutionBaseDN()
                        : LDAPConnector.getSingletonInstance().getLicensedInstitutionsBaseDN()));
        StringBuilder vFilter = new StringBuilder("(objectClass=").append(Constants.ldap_ddbOrg_ObjectClass)
                .append(")");
        NamingEnumeration<SearchResult> searchResults = this.query(ctx, vBaseDn.toString(), vFilter.toString(),
                attributeFilter, pScopy);
        return searchResults;
    } catch (IllegalAccessException ex) {
        LOG.log(Level.SEVERE, "Connection-Error", ex);
        throw new ExecutionException(ex.getMessage(), ex.getCause());
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, "NamingException", ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        if (ctx != null) {
            try {
                LDAPConnector.getSingletonInstance().putCtx(ctx);
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, "Exception", ex);
            }
        }
    }
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

public Set<OIDs> getAllSubOrgIds(boolean pLicensedOrgs, OIDs pOIDs, int pScopy, AasPrincipal pPerformer)
        throws ExecutionException {
    Set<OIDs> vSetOIDs = new HashSet<OIDs>();
    NamingEnumeration<SearchResult> searchResults = null;
    try {//from w  w  w. j  av  a2s. c  om
        searchResults = getAllSubOrgs(pLicensedOrgs, pOIDs, pScopy,
                new String[] { Constants.ldap_ddbOrg_Id, Constants.ldap_ddbOrg_PID, "+" }, pPerformer);
        SearchResult sr;
        Attribute attr;
        while (searchResults.hasMore()) {
            sr = searchResults.next();
            if ((attr = sr.getAttributes().get(Constants.ldap_ddb_EntryDN)) != null) {
                vSetOIDs.add(new OIDs(String.valueOf(attr.get()),
                        (attr = sr.getAttributes().get(Constants.ldap_ddbOrg_PID)) != null
                                ? String.valueOf(attr.get())
                                : null));
            } else {
                throw new ExecutionException("entryDN = null : OIDs = " + pOIDs, null);
            }
        }
    } catch (IllegalAccessException ex) {
        LOG.log(Level.SEVERE, "Connection-Error", ex);
        throw new ExecutionException(ex.getMessage(), ex.getCause());
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, "NamingException", ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        if (searchResults != null) {
            try {
                searchResults.close();
                searchResults = null;
            } catch (NamingException ex) {
            }
        }
    }
    return vSetOIDs;
}

From source file:com.orange.cepheus.broker.controller.NgsiControllerTest.java

@Test
public void postUpdateContextWithThrowExecutionException() throws Exception {

    //localRegistrations mock return always a providingApplication
    when(providingApplication.hasNext()).thenReturn(true);
    when(providingApplication.next()).thenReturn(new URI("http//iotagent:1234"));
    when(localRegistrations.findProvidingApplication(any(), any())).thenReturn(providingApplication);

    //subscriptions mock return always without matched subscriptions
    when(matchedSubscriptions.hasNext()).thenReturn(false);
    when(subscriptions.findSubscriptions(any(), any())).thenReturn(matchedSubscriptions);

    when(updateContextResponseListenableFuture.get())
            .thenThrow(new ExecutionException("execution exception", new Throwable()));

    //ngsiclient mock return always createUpdateContextREsponseTemperature when call updateContext
    when(ngsiClient.updateContext(any(), any(), any())).thenReturn(updateContextResponseListenableFuture);

    //check ngsiClient.notify is not called
    verify(ngsiClient, never()).notifyContext(any(), any(), any());

    mockMvc.perform(post("/v1/updateContext").content(json(mapper, createUpdateContextTempSensorAndPressure()))
            .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode.code").value("500"))
            .andExpect(/*from  ww w  . j  av  a 2s  . c  o  m*/
                    MockMvcResultMatchers.jsonPath("$.errorCode.reasonPhrase").value("Receiver internal error"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode.details")
                    .value("An unknown error at the receiver has occured"));
}

From source file:com.orange.cepheus.broker.controller.NgsiControllerTest.java

@Test
public void postQueryContextWithExecutionException() throws Exception {

    //localRegistrations mock return always a providingApplication
    when(providingApplication.hasNext()).thenReturn(true);
    when(providingApplication.next()).thenReturn(new URI("http//iotagent:1234"));
    when(localRegistrations.findProvidingApplication(any(), any())).thenReturn(providingApplication);

    when(queryContextResponseListenableFuture.get())
            .thenThrow(new ExecutionException("execution exception", new Throwable()));

    //ngsiclient mock return always createUpdateContextREsponseTemperature when call updateContext
    when(ngsiClient.queryContext(any(), any(), any())).thenReturn(queryContextResponseListenableFuture);

    mockMvc.perform(post("/v1/queryContext").content(json(mapper, createQueryContextTemperature()))
            .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode.code").value("500"))
            .andExpect(/* ww  w .  j  a v a 2  s.c  om*/
                    MockMvcResultMatchers.jsonPath("$.errorCode.reasonPhrase").value("Receiver internal error"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode.details")
                    .value("An unknown error at the receiver has occured"));
}