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.repository.filesystem.FileSystemRepositoryManager.java
/** * Insert the repository item./* w w w . java 2 s . c o m*/ * @param fileName It should be the UUID. It will remove "urn:uuid:". * @param item The repository item. */ public void insert(ServerRequestContext context, RepositoryItem item) throws RegistryException { try { String id = item.getId(); // Strip off the "urn:uuid:" id = Utility.getInstance().stripId(id); String itemPath = getRepositoryItemPath(id); log.debug("itemPath = " + itemPath); File itemFile = new File(itemPath); if (itemFile.exists()) { String errmsg = ServerResourceBundle.getInstance() .getString("message.RepositoryItemWithIdAlreadyExists", new Object[] { item.getId() }); log.error(errmsg); throw new RegistryException(errmsg); } //Writing out the RepositoryItem itself FileOutputStream fos = new FileOutputStream(itemPath); item.getDataHandler().writeTo(fos); fos.flush(); fos.close(); // Writing out the ri 's signature // if it exists. Element sigElement = item.getSignatureElement(); File itemSig = new File(getRepositoryItemPath(id) + ".sig"); if (itemSig.exists()) { String errmsg = ServerResourceBundle.getInstance() .getString("message.PayloadSignatureAlreadyExists", new Object[] { item.getId() }); log.error(errmsg); throw new RegistryException(errmsg); } FileOutputStream sigFos = new FileOutputStream(itemSig); TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); trans.transform(new DOMSource(sigElement), new StreamResult(sigFos)); sigFos.flush(); sigFos.close(); } catch (Exception e) { log.error(e); throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.persistence.rdb.ServiceBindingDAO.java
/** * Returns the SQL fragment string needed by insert or update statements * within insert or update method of sub-classes. This is done to avoid code * duplication.//from w w w . ja va2s . c o m */ protected String getSQLStatementFragment(Object ro) throws RegistryException { ServiceBindingType serviceBinding = (ServiceBindingType) ro; String stmtFragment = null; String serviceId = serviceBinding.getService(); if (serviceId == null) { serviceId = ((IdentifiableType) parent).getId(); } if (serviceId == null) { throw new RegistryException(ServerResourceBundle.getInstance().getString( "message.serviceBindingHasNoParentService", new Object[] { serviceBinding.getId() })); } String accessURI = serviceBinding.getAccessURI(); if (accessURI != null) { accessURI = "'" + accessURI + "'"; } String targetBindingId = serviceBinding.getTargetBinding(); if (targetBindingId != null) { targetBindingId = "'" + targetBindingId + "'"; } if (action == DAO_ACTION_INSERT) { stmtFragment = "INSERT INTO ServiceBinding " + super.getSQLStatementFragment(ro) + ", '" + serviceId + "', " + accessURI + ", " + targetBindingId + " ) "; } else if (action == DAO_ACTION_UPDATE) { stmtFragment = "UPDATE ServiceBinding SET " + super.getSQLStatementFragment(ro) + ", service='" + serviceId + "', accessURI=" + accessURI + ", targetBinding=" + targetBindingId + " WHERE id = '" + ((RegistryObjectType) ro).getId() + "' "; } else if (action == DAO_ACTION_DELETE) { stmtFragment = super.getSQLStatementFragment(ro); } return stmtFragment; }
From source file:it.cnr.icar.eric.server.persistence.rdb.IdentifiableDAO.java
protected List<String> getIdentifiablesIds(List<?> identifiables) throws RegistryException { List<String> ids = new ArrayList<String>(); try {//w ww .ja v a 2 s .com //log.info("size: " + identifiables.size()); Iterator<?> iter = identifiables.iterator(); while (iter.hasNext()) { String id = BindingUtility.getInstance().getObjectId(iter.next()); ids.add(id); } } catch (JAXRException e) { throw new RegistryException(e); } return ids; }
From source file:it.cnr.icar.eric.server.interfaces.rest.QueryManagerURLHandler.java
/** Process the QueryManager request and sends the response back to the client * @param// w ww. j a v a2 s.c om * */ void processGetRequest() throws IOException, RegistryException, InvalidRequestException, UnimplementedException, ObjectNotFoundException { String method = request.getParameter("method"); String id = request.getParameter("param-id"); String lid = request.getParameter("param-lid"); String versionName = request.getParameter("param-versionName"); @SuppressWarnings("unused") String flavor = request.getParameter("flavor"); if ((method == null) || method.equals("")) { throw new InvalidRequestException( ServerResourceBundle.getInstance().getString("message.methodCannotBeNull")); } else if (method.equalsIgnoreCase("getRegistryObject")) { try { response.setContentType("text/xml; charset=UTF-8"); String queryString = getQueryStringForFindByIdLidVersion(id, lid, versionName); List<RegistryObjectType> results = submitQueryAs(queryString, currentUser); if (results.isEmpty()) { throw new ObjectNotFoundException(getNotFoundExceptionMsg(id, lid, versionName)); } else { if (results.size() > 1) { writeDirectoryListing(results); } else { RegistryObjectType ebRegistryObjectType = results.get(0); writeRegistryObject(ebRegistryObjectType); } } } catch (NullPointerException e) { log.error(e.toString(), e); throw new RegistryException( it.cnr.icar.eric.server.common.Utility.getInstance().getStackTraceFromThrowable(e)); } } else if (method.equalsIgnoreCase("getRepositoryItem")) { try { String queryString = getQueryStringForFindByIdLidVersion(id, lid, versionName); List<RegistryObjectType> results = submitQueryAs(queryString, currentUser); if (results.isEmpty()) { throw new ObjectNotFoundException(getNotFoundExceptionMsg(id, lid, versionName)); } else { // RegistryObjectType ro = (RegistryObjectType)results.get(0); // take ComplexType from Element //RegistryObjectType ebRegistryObjectType = ((JAXBElement<RegistryObjectType>)(results.get(0))).getValue(); RegistryObjectType ebRegistryObjectType = results.get(0); // check the first ComplexType in result if (!(ebRegistryObjectType instanceof ExtrinsicObjectType)) { //return the error code throw new InvalidRequestException(ServerResourceBundle.getInstance().getString( "message.expectedExtrinsicObjectNotFound", new Object[] { ebRegistryObjectType.getClass() })); } if (results.size() > 1) { writeDirectoryListing(results); } else { ExtrinsicObjectType ebExtrinsicObjectType = (ExtrinsicObjectType) ebRegistryObjectType; writeRepositoryItem(ebExtrinsicObjectType); } } } catch (NullPointerException e) { log.error(e.toString(), e); throw new RegistryException( it.cnr.icar.eric.server.common.Utility.getInstance().getStackTraceFromThrowable(e)); } } else if (method.equalsIgnoreCase("submitAdhocQuery")) { try { String startIndex = request.getParameter("startIndex"); if (startIndex == null) { startIndex = "0"; } String maxResults = request.getParameter("maxResults"); if (maxResults == null) { maxResults = "-1"; } String queryId = request.getParameter("queryId"); if (queryId == null) { queryId = "urn:freebxml:registry:query:BusinessQuery"; } //Create and populate queryParamsMap from request params map Map<String, String> queryParams = new HashMap<String, String>(); Iterator<String> iter = request.getParameterMap().keySet().iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof String) { String paramName = (String) obj; //Only use params whose names begin with '$' char if (paramName.charAt(0) == '$') { String paramValue = request.getParameter(paramName); queryParams.put(paramName, paramValue); } } } ServerRequestContext context = new ServerRequestContext( "QueryManagerURLHandler.processGetRequest.submitAdhocQuery", null); List<IdentifiableType> ebIdentifiableTypeResultList = invokeParameterizedQuery(context, queryId, queryParams, currentUser, Integer.parseInt(startIndex), Integer.parseInt(maxResults)); String getRepositoryItem = request.getParameter("getRepositoryItem"); if ((getRepositoryItem != null) && ((getRepositoryItem.equalsIgnoreCase("true")) || (getRepositoryItem.equals("1")))) { writeRepositoryItemList(ebIdentifiableTypeResultList); } else { writeRegistryObjectList(ebIdentifiableTypeResultList); } } catch (NullPointerException e) { log.error(e.toString(), e); throw new RegistryException( it.cnr.icar.eric.server.common.Utility.getInstance().getStackTraceFromThrowable(e)); } } else if (method.equalsIgnoreCase("newUUID")) { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); UUIDFactory uuidFac = UUIDFactory.getInstance(); out.print(uuidFac.newUUID().toString()); out.close(); } else { //return the error code throw new InvalidRequestException( ServerResourceBundle.getInstance().getString("message.unknownMethod", new Object[] { method })); } }
From source file:it.cnr.icar.eric.server.cms.ContentCatalogingServiceManager.java
/** * Invokes appropriate Content Management Services for the * in the <code>RegistryObject</code>. * * @param ebRegistryObjectType a <code>RegistryObject</code> value * @param ri a <code>RepositoryItem</code> value *//*ww w .j a va 2 s . c om*/ public boolean invokeServiceForObject(ServiceInvocationInfo sii, RegistryObjectType ebRegistryObjectType, RepositoryItem ri, ServerRequestContext context) throws RegistryException { //Cataloging services only apply to Submit/UpdateObjectsRequests RegistryRequestType request = context.getCurrentRegistryRequest(); if (!((request instanceof SubmitObjectsRequest) || (request instanceof UpdateObjectsRequest))) { return false; } if (log.isTraceEnabled()) { log.trace("ContentCatalogingServiceManager.invokeServiceForObject()"); } try { ContentManagementService cms = (ContentManagementService) sii.getConstructor() .newInstance((java.lang.Object[]) null); System.err.println("cms: " + cms.getClass().getName()); ServiceOutput so = null; //Note that ri will be null for ExternalLink ro. so = cms.invoke(context, new ServiceInput(ebRegistryObjectType, ri), sii.getService(), sii.getInvocationController(), context.getUser()); if (!(so.getOutput() instanceof ServerRequestContext)) { throw new InvalidConfigurationException(ServerResourceBundle.getInstance().getString( "message.CatalogingServiceInstanceShouldReturnRequestContext", new Object[] { so.getOutput().getClass().getName() })); } ServerRequestContext outputContext = (ServerRequestContext) so.getOutput(); if (outputContext != null) { ArrayList<IdentifiableType> list = new ArrayList<IdentifiableType>( outputContext.getTopLevelRegistryObjectTypeMap().values()); if (log.isDebugEnabled()) { Iterator<IdentifiableType> listIter = list.iterator(); while (listIter.hasNext()) { RegistryObjectType debugRO = (RegistryObjectType) listIter.next(); log.debug(debugRO.getId() + " " + debugRO.getClass().getName() + " " + debugRO.getName()); } log.debug("Objects found: " + list.size()); } outputContext.checkObjects(); pm.insert(outputContext, list); } } catch (RegistryException re) { log.error(re, re); throw re; } catch (Exception e) { log.error(e, e); throw new RegistryException(e); } return true; }
From source file:it.cnr.icar.eric.server.persistence.rdb.PersonDAO.java
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void loadObject(Object obj, ResultSet rs) throws RegistryException { try {/* ww w . j a v a 2 s. c o m*/ if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.PersonType)) { throw new RegistryException(ServerResourceBundle.getInstance().getString("message.PersonExpected", new Object[] { obj })); } PersonType person = (PersonType) obj; super.loadObject(obj, rs); String firstName = rs.getString("personName_firstName"); String middleName = rs.getString("personName_middleName"); String lastName = rs.getString("personName_lastName"); PersonNameType ebPersonNameType = bu.rimFac.createPersonNameType(); ebPersonNameType.setFirstName(firstName); ebPersonNameType.setMiddleName(middleName); ebPersonNameType.setLastName(lastName); person.setPersonName(ebPersonNameType); PostalAddressDAO postalAddressDAO = new PostalAddressDAO(context); postalAddressDAO.setParent(person); List addresses = postalAddressDAO.getByParent(); if (addresses != null) { person.getAddress().addAll(addresses); } TelephoneNumberDAO telephoneNumberDAO = new TelephoneNumberDAO(context); telephoneNumberDAO.setParent(person); List phones = telephoneNumberDAO.getByParent(); if (phones != null) { person.getTelephoneNumber().addAll(phones); } EmailAddressDAO emailAddressDAO = new EmailAddressDAO(context); emailAddressDAO.setParent(person); List emails = emailAddressDAO.getByParent(); if (emails != null) { person.getEmailAddress().addAll(emails); } } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCataloger.java
/** * Catalogs WSDL files./*from w w w . jav a 2s . c o m*/ * * @param partCatalogContentRequest CatalogContentRequest containing * the ExtrinisicObject representing the WSDL file. * * @throws RemoteException if an error occurs * @return SOAPElement containing an updated ExtrinsicObject */ @SuppressWarnings("unchecked") public ServiceOutput invoke(ServerRequestContext context, ServiceInput input, ServiceType service, InvocationController invocationController, UserType user) throws RegistryException { if (log.isTraceEnabled()) { log.trace("WSDLCataloger.invoke()"); } RegistryObjectType registryObject = input.getRegistryObject(); RepositoryItem repositoryItem = input.getRepositoryItem(); DataHandler dh = null; if (repositoryItem != null) { dh = repositoryItem.getDataHandler(); } if ((registryObject instanceof ExtrinsicObjectType) && (repositoryItem == null)) { throw new MissingRepositoryItemException(input.getRegistryObject().getId()); } ServerRequestContext outputContext = null; try { outputContext = context; //new RequestContext(null); CatalogingServiceEngine engine = new WSDLCatalogerEngine(); CatalogingServiceInput input1 = new CatalogingServiceInput((DataHandler) null, dh, registryObject); CatalogingServiceOutput output1 = engine.catalogContent(input1); RegistryObjectListType catalogedMetadata = bu.rimFac.createRegistryObjectListType(); // FIXME: Setting catalogedMetadata as CatalogedContent results in incorrect serialization. catalogedMetadata.getIdentifiable().addAll( (Collection<? extends JAXBElement<? extends IdentifiableType>>) output1.getRegistryObjects()); //Add cataloged repository items to outputContext HashMap<String, Object> idToRepositoryItemMap = output1.getRepositoryItemMap(); outputContext.getRepositoryItemsMap().putAll(idToRepositoryItemMap); // TODO: User should refer to "Service object for the // Content Management Service that generated the // Cataloged Content." outputContext.setUser(user); bu.getObjectRefsAndRegistryObjects(catalogedMetadata, outputContext.getTopLevelRegistryObjectTypeMap(), outputContext.getObjectRefTypeMap()); } catch (Exception e) { if (outputContext != context) { outputContext.rollback(); } throw new RegistryException(e); } ServiceOutput so = new ServiceOutput(); so.setOutput(outputContext); // Setting this error list is redundant, but Content Validation Services // currently output a Boolean and a RegistryErrorList, so using // same mechanism to report errors from Content Cataloging Services. so.setErrorList(outputContext.getErrorList()); if (outputContext != context) { outputContext.commit(); } return so; }
From source file:it.cnr.icar.eric.server.persistence.rdb.AbstractDAO.java
/** * Gets a List of binding objects from specified ResultSet. *///from w w w . j a v a 2 s. c o m public List<Object> getObjects(ResultSet rs, int startIndex, int maxResults) throws RegistryException { List<Object> res = new ArrayList<Object>(); try { if (startIndex > 0) { // calling rs.next() is a workaround for some drivers, such // as Derby's, that do not set the cursor during call to // rs.relative(...) rs.next(); @SuppressWarnings("unused") boolean onRow = rs.relative(startIndex - 1); } int cnt = 0; while (rs.next()) { Object obj = createObject(); loadObject(obj, rs); res.add(obj); if (++cnt == maxResults) { break; } } } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } catch (JAXBException j) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), j); throw new RegistryException(j); } return res; }
From source file:it.cnr.icar.eric.server.cache.ObjectCache.java
private void cacheStoredQueries(ServerRequestContext context) throws RegistryException { try {//from w ww.j a va 2 s .com String sqlQuery = "Select q.* from AdhocQuery q"; List<?> results = executeQueryInternal(context, sqlQuery, null, "AdhocQuery"); Iterator<?> iter = results.iterator(); while (iter.hasNext()) { RegistryObjectType ro = (RegistryObjectType) iter.next(); putRegistryObject(ro); } } catch (RegistryException e) { throw e; } catch (Exception e) { throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.cms.CanonicalXMLFilteringService.java
@SuppressWarnings("unchecked") public ServiceOutput invoke(ServerRequestContext context, ServiceInput si, ServiceType service, InvocationController invocationController, UserType user) throws RegistryException { if (log.isTraceEnabled()) { log.trace("CanonicalXMLFilteringService.invoke()"); }//from w w w . ja va 2s . c om ServiceOutput so = new ServiceOutput(); so.setOutput(context); RepositoryItem repositoryItem = si.getRepositoryItem(); String roId = si.getRegistryObject().getId(); ServerRequestContext outputContext = context; //new RequestContext(null); try { HashMap<String, String> params = new HashMap<String, String>(); params.put("subjectId", context.getUser().getId()); //First filter the RegistryObject metadata StreamSource input = getAsStreamSource(si.getRegistryObject()); StreamSource xslt = rm.getAsStreamSource(invocationController.getEoId()); //Specify empty value to indicate that only metadata should be transformed //in this first XSLT invocation. params.put("repositoryItem", ""); File output = runXSLT(input, xslt, getURIResolver(context), params); JAXBElement<RegistryObjectType> ebRegistryObject = (JAXBElement<RegistryObjectType>) bu.getJAXBContext() .createUnmarshaller().unmarshal(output); // take ComplexType from Element RegistryObjectType ebRegistryObjectType = ebRegistryObject.getValue(); //Replace input RegistryObject with output RegistryObject. outputContext.getQueryResults().remove(si.getRegistryObject()); outputContext.getQueryResults().add(ebRegistryObjectType); //Now filter the RepositoryItem content if any if (repositoryItem != null) { input = new StreamSource(repositoryItem.getDataHandler().getInputStream()); xslt = rm.getAsStreamSource(invocationController.getEoId()); params.put("repositoryItem", roId); output = runXSLT(input, xslt, getURIResolver(context), params); RepositoryItem outputRI = new RepositoryItemImpl(roId, new DataHandler(new FileDataSource(output))); //Replace input RepositoryItem with output RepositoryItem. outputContext.getRepositoryItemsMap().put(roId, outputRI); } // TODO: User should refer to "Service object for the // Content Management Service that generated the // Cataloged Content." outputContext.setUser(user); } catch (Exception e) { if (outputContext != context) { outputContext.rollback(); } throw new RegistryException(e); } so.setOutput(outputContext); // Setting this error list is redundant, but Content Validation Services // currently output a Boolean and a RegistryErrorList, so using // same mechanism to report errors from Content Filtering Services. so.setErrorList(outputContext.getErrorList()); if (outputContext != context) { outputContext.commit(); } return so; }