List of usage examples for javax.naming CommunicationException CommunicationException
public CommunicationException(String explanation)
From source file:org.lsc.jndi.JndiServices.java
private boolean doApply(final JndiModifications jm) throws CommunicationException { if (jm == null) { return true; }// w ww . j ava 2 s . co m try { switch (jm.getOperation()) { case ADD_ENTRY: ctx.createSubcontext(new LdapName(rewriteBase(jm.getDistinguishName())), getAttributes(jm.getModificationItems(), true)); break; case DELETE_ENTRY: if (recursiveDelete) { deleteChildrenRecursively(rewriteBase(jm.getDistinguishName())); } else { ctx.destroySubcontext(new LdapName(rewriteBase(jm.getDistinguishName()))); } break; case MODIFY_ENTRY: Object[] table = jm.getModificationItems().toArray(); ModificationItem[] mis = new ModificationItem[table.length]; System.arraycopy(table, 0, mis, 0, table.length); ctx.modifyAttributes(new LdapName(rewriteBase(jm.getDistinguishName())), mis); break; case MODRDN_ENTRY: //We do not display this warning if we do not apply the modification with the option modrdn = false LOGGER.warn( "WARNING: updating the RDN of the entry will cancel other modifications! Relaunch synchronization to complete update."); ctx.rename(new LdapName(rewriteBase(jm.getDistinguishName())), new LdapName(rewriteBase(jm.getNewDistinguishName()))); break; default: LOGGER.error("Unable to identify the right modification type: {}", jm.getOperation()); return false; } return true; } catch (ContextNotEmptyException e) { LOGGER.error( "Object {} not deleted because it has children (LDAP error code 66 received). To delete this entry and it's subtree, set the dst.java.naming.recursivedelete property to true", jm.getDistinguishName()); return false; } catch (NamingException ne) { if (LOGGER.isErrorEnabled()) { StringBuilder errorMessage = new StringBuilder("Error while "); switch (jm.getOperation()) { case ADD_ENTRY: errorMessage.append("adding"); break; case MODIFY_ENTRY: errorMessage.append("modifying"); break; case MODRDN_ENTRY: errorMessage.append("renaming"); break; case DELETE_ENTRY: if (recursiveDelete) { errorMessage.append("recursively "); } errorMessage.append("deleting"); break; } errorMessage.append(" entry ").append(jm.getDistinguishName()); errorMessage.append(" in directory :").append(ne.toString()); LOGGER.error(errorMessage.toString()); } if (ne instanceof CommunicationException) { // we lost the connection to the source or destination, stop everything! throw (CommunicationException) ne; } if (ne instanceof ServiceUnavailableException) { // we lost the connection to the source or destination, stop everything! CommunicationException ce = new CommunicationException(ne.getExplanation()); ce.setRootCause(ne); throw ce; } return false; } }
From source file:org.lsc.service.AbstractJdbcService.java
/** * The simple object getter according to its identifier. * * @param pivotName Name of the entry to be returned, which is the name returned by * {@link #getListPivots()} (used for display only) * @param pivotAttributes Map of attribute names and values, which is the data identifier in the * source such as returned by {@link #getListPivots()}. It must identify a unique * entry in the source.// w ww. j a va2 s . c o m * @return The bean, or null if not found * @throws LscServiceException May throw a embedded {@link CommunicationException} if an SQLException is encountered */ public IBean getBean(String pivotName, LscDatasets pivotAttributes) throws LscServiceException { Map<String, Object> attributeMap = pivotAttributes.getDatasets(); try { return (IBean) sqlMapper.queryForObject(getRequestNameForObject(), attributeMap); } catch (SQLException e) { LOGGER.warn("Error while looking for a specific entry with id={} ({})", pivotName, e); LOGGER.debug(e.toString(), e); // TODO This SQLException may mean we lost the connection to the DB // This is a dirty hack to make sure we stop everything, and don't risk deleting everything... throw new LscServiceException(new CommunicationException(e.getMessage())); } }
From source file:org.lsc.service.AbstractJdbcService.java
/** * Override default AbstractJdbcSrcService to get a SimpleBean * @throws LscServiceException // w w w.j a va 2 s .c o m */ @SuppressWarnings("unchecked") @Override public IBean getBean(String id, LscDatasets attributes, boolean fromSameService) throws LscServiceException { IBean srcBean = null; try { srcBean = beanClass.newInstance(); List<?> records = sqlMapper.queryForList(getRequestNameForObjectOrClean(fromSameService), getAttributesMap(attributes)); if (records.size() > 1) { throw new LscServiceException("Only a single record can be returned from a getObject request ! " + "For id=" + id + ", there are " + records.size() + " records !"); } else if (records.size() == 0) { return null; } Map<String, Object> record = (Map<String, Object>) records.get(0); for (Entry<String, Object> entry : record.entrySet()) { if (entry.getValue() != null) { srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey(), entry.getValue()))); } else { srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey()))); } } srcBean.setMainIdentifier(id); return srcBean; } catch (InstantiationException e) { LOGGER.error( "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})", beanClass.getName(), e.toString()); LOGGER.debug(e.toString(), e); } catch (IllegalAccessException e) { LOGGER.error( "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})", beanClass.getName(), e.toString()); LOGGER.debug(e.toString(), e); } catch (SQLException e) { LOGGER.warn("Error while looking for a specific entry with id={} ({})", id, e); LOGGER.debug(e.toString(), e); // TODO This SQLException may mean we lost the connection to the DB // This is a dirty hack to make sure we stop everything, and don't risk deleting everything... throw new LscServiceException(new CommunicationException(e.getMessage())); } catch (NamingException e) { LOGGER.error("Unable to get handle cast: " + e.toString()); LOGGER.debug(e.toString(), e); } return null; }