List of usage examples for javax.xml.registry RegistryException RegistryException
public RegistryException(Throwable cause)
JAXRException
object initialized with the given Throwable
object. From source file:it.cnr.icar.eric.server.security.authentication.CertificateAuthority.java
/** Extension request to sign specified cert and return the signed cert. */ @SuppressWarnings("static-access") public RegistryResponseHolder signCertificateRequest(UserType user, RegistryRequestType req, Map<?, ?> idToRepositoryItemMap) throws RegistryException { RegistryResponseHolder respHolder = null; RegistryResponseType ebRegistryResponseType = null; ServerRequestContext context = null; try {//from ww w .j a v a 2 s . c o m context = new ServerRequestContext("CertificateAUthority.signCertificateRequest", req); context.setUser(user); if (idToRepositoryItemMap.keySet().size() == 0) { throw new MissingRepositoryItemException( ServerResourceBundle.getInstance().getString("message.KSRepItemNotFound")); } String id = (String) idToRepositoryItemMap.keySet().iterator().next(); Object obj = idToRepositoryItemMap.get(id); if (!(obj instanceof RepositoryItem)) { throw new InvalidContentException(); } RepositoryItem ri = (RepositoryItem) obj; //This is the JKS keystore containing cert to be signed //Read original cert from keystore InputStream is = ri.getDataHandler().getInputStream(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(is, bu.FREEBXML_REGISTRY_KS_PASS_REQ.toCharArray()); is.close(); X509Certificate cert = (X509Certificate) keyStore .getCertificate(bu.FREEBXML_REGISTRY_USERCERT_ALIAS_REQ); //Sign the cert cert = signCertificate(cert); //Replace cert with signed cert in keystore keyStore.deleteEntry(bu.FREEBXML_REGISTRY_USERCERT_ALIAS_REQ); keyStore.setCertificateEntry(bu.FREEBXML_REGISTRY_USERCERT_ALIAS_RESP, cert); //Add CA root cert (RegistryOPerator's cert) to keystore. keyStore.setCertificateEntry(bu.FREEBXML_REGISTRY_CACERT_ALIAS, getCACertificate()); Certificate[] certChain = new Certificate[2]; certChain[0] = cert; certChain[1] = getCACertificate(); validateChain(certChain); File repositoryItemFile = File.createTempFile(".eric-ca-resp", ".jks"); repositoryItemFile.deleteOnExit(); FileOutputStream fos = new java.io.FileOutputStream(repositoryItemFile); keyStore.store(fos, bu.FREEBXML_REGISTRY_KS_PASS_RESP.toCharArray()); fos.flush(); fos.close(); DataHandler dh = new DataHandler(new FileDataSource(repositoryItemFile)); RepositoryItemImpl riNew = new RepositoryItemImpl(id, dh); ebRegistryResponseType = bu.rsFac.createRegistryResponseType(); ebRegistryResponseType.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success); HashMap<String, Object> respIdToRepositoryItemMap = new HashMap<String, Object>(); respIdToRepositoryItemMap.put(id, riNew); respHolder = new RegistryResponseHolder(ebRegistryResponseType, respIdToRepositoryItemMap); } catch (RegistryException e) { context.rollback(); throw e; } catch (Exception e) { context.rollback(); throw new RegistryException(e); } context.commit(); return respHolder; }
From source file:it.cnr.icar.eric.server.persistence.rdb.EmailAddressDAO.java
/** * Does a bulk update of a Collection of objects that match the type for this persister. * *///w ww . j a va 2 s. com public void update(String parentId, List<?> emailAddresss) throws RegistryException { log.debug(ServerResourceBundle.getInstance().getString("message.UpdatingEmailAddresss", new Object[] { new Integer(emailAddresss.size()) })); Statement stmt = null; try { stmt = context.getConnection().createStatement(); Iterator<?> iter = emailAddresss.iterator(); while (iter.hasNext()) { EmailAddressType ebEmailAddressType = (EmailAddressType) iter.next(); String address = ebEmailAddressType.getAddress(); String type = ebEmailAddressType.getType(); if (type != null) { type = "'" + type + "'"; } String str = "UPDATE EmailAddress SET " + //"accesControlPolicy = null, " + "SET address = '" + address + "', " + "SET type = " + type + " WHERE parent = '" + parentId + "' "; log.trace("stmt = " + str); stmt.addBatch(str); } stmt.executeBatch(); } catch (SQLException e) { RegistryException exception = new RegistryException(e); throw exception; } finally { closeStatement(stmt); } }
From source file:it.cnr.icar.eric.server.persistence.rdb.ClassificationNodeDAO.java
/** * Generate the path for the specified ClassificationNode. The path starts with a slash, followed * by the id of its ClassificationScheme, if any, which is followed by codes * of the intermidate ClassificationNodes and ends with the code of this * ClassificationNode. If any of the ClassificationNode does not have code, * empty string is appended for that ClassificationNode. * <br>// w w w.ja v a 2 s.c o m */ public String generatePath(ClassificationNodeType node) throws RegistryException { String path = null; String parentId = node.getParent(); RegistryObjectType _parent = null; if (parentId == null) { //It is possible for a ClassificationNode to have nu parent scheme //in this case the path is just "/<id of node>" path = "/" + node.getId(); } else { /* * Build the path of the ClassificationNode in the form of * /.../.../.. . It is composed of ClassificationScheme 's id as root and * then the codes of enclosing ClassificationNodes */ if (_parent == null) { //Try and get _parent from request _parent = (RegistryObjectType) context.getSubmittedObjectsMap().get(parentId); if (_parent == null) { //Try and get parent from database PersistenceManager pm = PersistenceManagerFactory.getInstance().getPersistenceManager(); ObjectRefType ebParentObjectRefType = bu.rimFac.createObjectRefType(); ebParentObjectRefType.setId(parentId); _parent = pm.getRegistryObject(context, ebParentObjectRefType); if (_parent == null) { throw new RegistryException( ServerResourceBundle.getInstance().getString("message.couldNotFindParent", new Object[] { parentId, node.getId(), node.getCode() })); } } } String parentPath = null; if (_parent instanceof ClassificationSchemeType) { parentPath = null; } else if (_parent instanceof ClassificationNodeType) { parentPath = ((ClassificationNodeType) _parent).getPath(); } else { throw new RegistryException( ServerResourceBundle.getInstance().getString("message.ClassificationNodeNotMatch", new Object[] { node.getId(), node.getCode(), _parent.getClass().getName() })); } if (parentPath == null) { if (_parent instanceof ClassificationSchemeType) { parentPath = "/" + _parent.getId(); } else if (_parent instanceof ClassificationNodeType) { parentPath = generatePath((ClassificationNodeType) _parent); ((ClassificationNodeType) _parent).setPath(parentPath); } } String code = node.getCode(); if (code == null) { String msg = ServerResourceBundle.getInstance().getString("message.ClassificationNodeNotMatch", new Object[] { node.getId() }); if (codeCannotBeNull) { throw new RegistryException(msg); } else { log.warn(msg); } } path = parentPath + "/" + code; node.setPath(path); } return path; }
From source file:it.cnr.icar.eric.server.persistence.rdb.ServiceBindingDAO.java
protected void loadObject(Object obj, ResultSet rs) throws RegistryException { if (!(obj instanceof ServiceBindingType)) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.ServiceBindingExpected", new Object[] { obj })); }/* ww w . j a va 2 s . c o m*/ ServiceBindingType ebServiceBindingType = (ServiceBindingType) obj; super.loadObject(ebServiceBindingType, rs); String accessUri = null; try { accessUri = rs.getString("accessuri"); ebServiceBindingType.setAccessURI(accessUri); String targetBindingId = rs.getString("targetBinding"); if (targetBindingId != null) { ObjectRefType ebTargetObjectRefType = bu.rimFac.createObjectRefType(); context.getObjectRefs().add(ebTargetObjectRefType); ebTargetObjectRefType.setId(targetBindingId); ebServiceBindingType.setTargetBinding(targetBindingId); } String serviceId = rs.getString("service"); if (serviceId != null) { ObjectRefType ebServiceObjectRefType = bu.rimFac.createObjectRefType(); context.getObjectRefs().add(ebServiceObjectRefType); ebServiceObjectRefType.setId(serviceId); ebServiceBindingType.setService(serviceId); } } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } boolean returnComposedObjects = context.getResponseOption().isReturnComposedObjects(); if (returnComposedObjects) { SpecificationLinkDAO specificationLinkDAO = new SpecificationLinkDAO(context); specificationLinkDAO.setParent(ebServiceBindingType); List<Object> specLinks = specificationLinkDAO.getByParent(); Iterator<Object> iter = specLinks.iterator(); while (iter.hasNext()) { SpecificationLinkType ebSpecificationLinkType = (SpecificationLinkType) iter.next(); ebServiceBindingType.getSpecificationLink().add(ebSpecificationLinkType); } } }
From source file:it.cnr.icar.eric.server.lcm.versioning.VersionProcessor.java
@SuppressWarnings("static-access") public boolean needToVersionRegistryObject(RegistryObjectType ro) throws RegistryException { boolean needToVersion = true; BindingUtility bu = BindingUtility.getInstance(); boolean newObject = false; try {//from w ww. j a v a 2 s . c o m needToVersion = isVersionableClass(ro); if (needToVersion) { HashMap<?, ?> slotsMap; // Honour dontVersion flag if specified on request if (!context.getRegistryRequestStack().empty()) { slotsMap = bu.getSlotsFromRequest(context.getCurrentRegistryRequest()); if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION)) { String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION); if (val.trim().equalsIgnoreCase("true")) { needToVersion = false; } } } //Honour dontVersion flag if specified on ro slotsMap = bu.getSlotsFromRegistryObject(ro); if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION)) { String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION); if (val.trim().equalsIgnoreCase("true")) { needToVersion = false; } } } //TODO: //Need to investigate case where not versioning and it is a new object. //Need unit test for this case. if (needToVersion) { versions = getAllRegistryObjectVersions(ro); if (versions.size() == 0) { // If there are any existing versions (ie. ro's with same LID) then we need to version //This is a new ro and therefore need not be versioned needToVersion = false; newObject = true; } } //Must set versionName to match latest versionName if existing object //or set to version 1.1 if new object. if (!needToVersion) { RegistryObjectType lastVersion = getLatestVersionOfRegistryObject(ro); String versionName = null; if (lastVersion == null) { versionName = "1.1"; } else { versionName = lastVersion.getVersionInfo().getVersionName(); //Must bump up versionName for new objects if (newObject) { versionName = nextVersion(versionName); } } VersionInfoType versionInfo = ro.getVersionInfo(); if (versionInfo == null) { versionInfo = bu.rimFac.createVersionInfoType(); ro.setVersionInfo(versionInfo); } versionInfo.setVersionName(versionName); if (!context.getRegistryRequestStack().empty()) { setVersionInfoComment(versionInfo); } } } catch (JAXBException e) { throw new RegistryException(e); } return needToVersion; }
From source file:it.cnr.icar.eric.server.persistence.rdb.TelephoneNumberDAO.java
/** * Does a bulk insert of a Collection of objects that match the type for this persister. * *//* w ww.j a va 2 s .co m*/ public void insert(String parentId, List<?> telephoneNumbers) throws RegistryException { Statement stmt = null; if (telephoneNumbers.size() == 0) { return; } log.debug(ServerResourceBundle.getInstance().getString("message.InsertingTelephoneNumbersSize", new Object[] { new Integer(telephoneNumbers.size()) })); try { stmt = context.getConnection().createStatement(); Iterator<?> iter = telephoneNumbers.iterator(); while (iter.hasNext()) { TelephoneNumberType telephoneNumber = (TelephoneNumberType) iter.next(); //Log.print(Log.TRACE, 8, "\tDATABASE EVENT: storing TelephoneNumber " ); String areaCode = telephoneNumber.getAreaCode(); if (areaCode != null) { areaCode = "'" + areaCode + "'"; } String countryCode = telephoneNumber.getCountryCode(); if (countryCode != null) { countryCode = "'" + countryCode + "'"; } String extension = telephoneNumber.getExtension(); if (extension != null) { extension = "'" + extension + "'"; } String number = telephoneNumber.getNumber(); if (number != null) { number = "'" + number + "'"; } String phoneType = telephoneNumber.getPhoneType(); if (phoneType != null) { phoneType = "'" + phoneType + "'"; } String str = "INSERT INTO TelephoneNumber " + "VALUES( " + areaCode + ", " + countryCode + ", " + extension + ", " + number + ", " + phoneType + ", " + "'" + parentId + "' )"; log.trace("stmt = " + str); stmt.addBatch(str); } if (telephoneNumbers.size() > 0) { stmt.executeBatch(); } } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } finally { closeStatement(stmt); } }
From source file:it.cnr.icar.eric.server.persistence.rdb.EmailAddressDAO.java
protected void loadObject(Object obj, ResultSet rs) throws RegistryException { try {/*from www . j a va 2 s . co m*/ if (!(obj instanceof EmailAddressType)) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.EmailAddressTypeExpected", new Object[] { obj })); } EmailAddressType addr = (EmailAddressType) obj; String address = rs.getString("address"); addr.setAddress(address); String type = rs.getString("type"); addr.setType(type); } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.persistence.rdb.TelephoneNumberDAO.java
protected void loadObject(Object obj, ResultSet rs) throws RegistryException { try {//from www . j a v a 2 s. co m if (!(obj instanceof TelephoneNumberType)) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.TelephoneNumberTypeExpected", new Object[] { obj })); } TelephoneNumberType phone = (TelephoneNumberType) obj; String areaCode = rs.getString("areaCode"); phone.setAreaCode(areaCode); String countryCode = rs.getString("countryCode"); phone.setCountryCode(countryCode); String extension = rs.getString("extension"); phone.setExtension(extension); String number = rs.getString("number_"); phone.setNumber(number); String phoneType = rs.getString("phoneType"); phone.setPhoneType(phoneType); } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.query.sql.SQLQueryProcessor.java
public RegistryObjectListType executeQuery(ServerRequestContext context, UserType user, String sqlQuery, ResponseOptionType responseOption, IterativeQueryParams paramHolder) throws RegistryException { RegistryObjectListType ebRegistryObjectListType = null; log.debug("unparsed query: " + sqlQuery + ";"); try {//from ww w.ja v a 2 s .com ebRegistryObjectListType = BindingUtility.getInstance().rimFac.createRegistryObjectListType(); //Fix the query according to the responseOption to return the right type of objects String fixedQuery = sqlQuery; String tableName = null; if (!bypassSQLParser) { //parse the queryString to get at certain info like the select column and table name etc. InputStream stream = new ByteArrayInputStream(sqlQuery.getBytes("utf-8")); SQLParser parser = new SQLParser(new InputStreamReader(stream, "utf-8")); fixedQuery = parser.processQuery(user, responseOption); log.debug("Fixed query: " + fixedQuery + ";"); tableName = parser.firstTableName; } else { String[] strs = sqlQuery.toUpperCase().split(" FROM "); if (strs.length > 1) { tableName = (strs[1].split(" "))[0]; } //tableName = sqlQuery.substring(sqlQuery.indexOf("FROM")); } if (log.isTraceEnabled()) { log.trace(ServerResourceBundle.getInstance().getString("message.executingQuery", new Object[] { fixedQuery })); } //Get the List of objects (ObjectRef, RegistryObject, leaf class) as //specified by the responeOption ArrayList<Object> objectRefs = new ArrayList<Object>(); List<String> queryParams = context.getStoredQueryParams(); if (queryParams.size() == 0) { queryParams = null; } log.debug("queryParams = " + queryParams); List<IdentifiableType> objs = PersistenceManagerFactory.getInstance().getPersistenceManager() .executeSQLQuery(context, fixedQuery, queryParams, responseOption, tableName, objectRefs, paramHolder); if (queryParams != null) { queryParams.clear(); } List<JAXBElement<? extends IdentifiableType>> ebIdentifiableTypeList = ebRegistryObjectListType .getIdentifiable(); if ((ebIdentifiableTypeList != null) && (objs != null)) { Iterator<?> iter = objs.iterator(); while (iter.hasNext()) { // iter over ComplexTypes // add as Identifiable elements into ebRegistryObjectListType ebIdentifiableTypeList.add( BindingUtility.getInstance().rimFac.createIdentifiable((IdentifiableType) iter.next())); } } //BindingUtility.getInstance().getJAXBContext().createMarshaller().marshal(objs.get(0), System.err); //BindingUtility.getInstance().getJAXBContext().createMarshaller().marshal(sqlResult, System.err); //TODO: Not sure what this code was about but leaving it commented for now. /* // Attaching the ObjectRef to the response. objectsRefs contains duplicates! Iterator objectRefsIter = objectRefs.iterator(); // It is to store the ObjectRef 's id after removing duplicated ObjectRef. It is a dirty fix, change it later!!!! List finalObjectRefsIds = new java.util.ArrayList(); List finalObjectRefs = new java.util.ArrayList(); while(objectRefsIter.hasNext()) { Object obj = objectRefsIter.next(); if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRef) { ObjectRef objectRef = (ObjectRef) obj; String id = objectRef.getId(); if (!finalObjectRefsIds.contains(id)) { finalObjectRefsIds.add(id); ObjectRef or = new ObjectRef(); or.setId(id); finalObjectRefs.add(or); } } else { throw new RegistryException("Unexpected object" + obj); } } Iterator finalObjectRefsIter = finalObjectRefs.iterator(); while (finalObjectRefsIter.hasNext()) { Object obj = finalObjectRefsIter.next(); if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRef) { RegistryObjectListTypeTypeItem li = new RegistryObjectListTypeTypeItem(); li.setObjectRef((ObjectRef)obj); sqlResult.addRegistryObjectListTypeTypeItem(li); } else { throw new RegistryException("Unexpected object" + obj); } } */ } catch (UnsupportedEncodingException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } catch (ParseException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } return ebRegistryObjectListType; }
From source file:it.cnr.icar.eric.server.interfaces.common.SessionManager.java
@SuppressWarnings("static-access") private boolean createHttpSession(Object message) throws RegistryException { boolean createSession = false; try {//from w w w. ja v a2 s.c o m if (message instanceof RegistryRequestType) { RegistryRequestType req = (RegistryRequestType) message; HashMap<String, Object> slotsMap = bu.getSlotsFromRequest(req); if (slotsMap.containsKey(bu.IMPL_SLOT_CREATE_HTTP_SESSION)) { String val = (String) slotsMap.get(bu.IMPL_SLOT_CREATE_HTTP_SESSION); if (val.trim().equalsIgnoreCase("true")) { createSession = true; } } } } catch (JAXBException e) { throw new RegistryException(e); } return createSession; }