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.cms.CanonicalXMLValidationService.java
public ServiceOutput invoke(ServerRequestContext context, ServiceInput input, ServiceType service, InvocationController invocationController, UserType user) throws RegistryException { ServerRequestContext outputContext = context; try {/* ww w . ja v a2 s . c o m*/ //ExtrinsicObjectType eo = (ExtrinsicObjectType)input.getRegistryObject(); //RepositoryItem repositoryItem = input.getRepositoryItem(); //DataHandler dh = repositoryItem.getDataHandler(); InputSource inputSource = null; //registryObject MUST be ExrinsicObject or ExternalLink of objectType WSDL ExtrinsicObjectType ebExtrinsicObjectType = null; ExternalLinkType ebExternalLinkType = null; RegistryObjectType ebRegistryObjectType = input.getRegistryObject(); if (ebRegistryObjectType instanceof ExtrinsicObjectType) { ebExtrinsicObjectType = (ExtrinsicObjectType) ebRegistryObjectType; RepositoryItem repositoryItem = input.getRepositoryItem(); if (repositoryItem == null) { // Section 8.10 of the [ebRS] spec specifies that the RI // is optional. Log message and return log.info(ServerResourceBundle.getInstance().getString("message.noRepositoryItemIncluded", new String[] { ebRegistryObjectType.getId() })); ServiceOutput so = new ServiceOutput(); so.setOutput(outputContext); return so; } inputSource = new InputSource(repositoryItem.getDataHandler().getInputStream()); } else if (ebRegistryObjectType instanceof ExternalLinkType) { ebExternalLinkType = (ExternalLinkType) ebRegistryObjectType; String urlStr = ebExternalLinkType.getExternalURI(); urlStr = Utility.absolutize(Utility.getFileOrURLName(urlStr)); URL url = new URL(urlStr); InputStream is = url.openStream(); inputSource = new InputSource(is); } else { throw new ValidationException("RegistryObject not ExtrinsicObject or ExternalLink"); } StreamSource schematronInvControlFileSrc = rm.getAsStreamSource(invocationController.getEoId()); //Commenting out caching until we figure out how to reinit the stream position at begining //Currently if we cache then subsequent uses result in error: "Could not compile stylesheet" // The schematron XSLT file is expected to be stable and change infrequently. So, cache it. //if (schematronXSLTFileSrc == null) { schematronXSLTFileSrc = new StreamSource(this.getClass().getClassLoader() .getResourceAsStream("it/cnr/icar/eric/server/cms/conf/skeleton1-5.xsl")); //} if (log.isDebugEnabled()) { dumpStream(schematronInvControlFileSrc); dumpStream(schematronXSLTFileSrc); } // Use the Schematron Invocation Control File and Schematron XSLT to // create the XSLT Invocation Control File File xsltInvocationControlFile = File.createTempFile("InvocationControlFile_WSDLValidation", ".xslt"); xsltInvocationControlFile.deleteOnExit(); StreamResult xsltInvocationControlFileSR = new StreamResult(xsltInvocationControlFile); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(schematronXSLTFileSrc); configureTransformer(transformer); // This call creates the XSLT Invocation Control File using // schematron invocation control file and schematron xslt files transformer.transform(schematronInvControlFileSrc, xsltInvocationControlFileSR); // Use generated XSLT Invocation Control File to validate the WSDL file(s) StreamSource xsltInvocationControlFileSrc = new StreamSource(xsltInvocationControlFile); transformer = tFactory.newTransformer(xsltInvocationControlFileSrc); configureTransformer(transformer); //Set respository item as parameter transformer.setParameter("repositoryItem", input.getRegistryObject().getId()); if ((ebExtrinsicObjectType != null) && (ebExtrinsicObjectType.getMimeType().equalsIgnoreCase("application/zip"))) { ArrayList<File> files = Utility.unZip(TMP_DIR, inputSource.getByteStream()); //Now iterate and create ExtrinsicObject - Repository Item pair for each unzipped file Iterator<File> iter = files.iterator(); while (iter.hasNext()) { File file = iter.next(); @SuppressWarnings("resource") BufferedReader br = new BufferedReader(new FileReader(file)); StringBuffer sb = new StringBuffer(); while (br.ready()) { sb.append(br.readLine()); } StringReader reader = new StringReader(sb.toString()); StreamSource inputSrc = new StreamSource(reader); validateXMLFile(inputSrc, transformer); } } else { //Following will fail if there are unresolved imports in the WSDL StreamSource inputSrc = new StreamSource(inputSource.getByteStream()); //dumpStream(inputSrc); //inputSrc = new StreamSource(inputSource.getByteStream()); validateXMLFile(inputSrc, transformer); } } catch (ValidationException e) { if (outputContext != context) { outputContext.rollback(); } log.error(ServerResourceBundle.getInstance().getString("message.errorValidatingXML"), e); throw e; } catch (Exception e) { if (outputContext != context) { outputContext.rollback(); } log.error(ServerResourceBundle.getInstance().getString("message.errorValidatingXML"), e); throw new RegistryException(e); } ServiceOutput so = new ServiceOutput(); so.setOutput(outputContext); if (outputContext != context) { outputContext.commit(); } return so; }
From source file:it.cnr.icar.eric.server.repository.AbstractRepositoryManager.java
/** * Get the size of a repository item in bytes. * @param id Unique id for ExtrinsicObject whose repository item size is desired * @return 0 if the file does not exist. *///from w w w. jav a2 s . co m public long getItemSize(String id) throws RegistryException { long itemSize = 0; try { RepositoryItem ri = getRepositoryItem(id); itemSize = (long) ri.getSize(); } catch (RepositoryItemNotFoundException e) { //return 0; itemSize = 0; } catch (Exception e) { log.error(e, e); String msg = ServerResourceBundle.getInstance().getString("message.FailedToGetSizeForRepositoryItem", new Object[] { id, null }); throw new RegistryException(ServerResourceBundle.getInstance().getString("message.seeLogsForDetails", new Object[] { msg })); } return itemSize; }
From source file:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java
public SOAPMessage onMessage(SOAPMessage msg, HttpServletRequest req, HttpServletResponse resp) { //System.err.println("onMessage called for RegistrySOAPServlet"); SOAPMessage soapResponse = null; SOAPHeader sh = null;/*from w w w. j a v a2 s. c o m*/ try { // set 'sh' variable ASAP (before "firstly") SOAPPart sp = msg.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); SOAPBody sb = se.getBody(); sh = se.getHeader(); // Firstly we put save the attached repository items in a map HashMap<String, Object> idToRepositoryItemMap = new HashMap<String, Object>(); Iterator<?> apIter = msg.getAttachments(); while (apIter.hasNext()) { AttachmentPart ap = (AttachmentPart) apIter.next(); //Get the content for the attachment RepositoryItem ri = processIncomingAttachment(ap); idToRepositoryItemMap.put(ri.getId(), ri); } // Log received message //if (log.isTraceEnabled()) { // Warning! BAOS.toString() uses platform's default encoding /* ByteArrayOutputStream msgOs = new ByteArrayOutputStream(); msg.writeTo(msgOs); msgOs.close(); System.err.println(msgOs.toString()); */ //System.err.println(sb.getTextContent()); // log.trace("incoming message:\n" + msgOs.toString()); //} // verify signature // returns false if no security header, throws exception if invalid CredentialInfo credentialInfo = new CredentialInfo(); boolean noRegRequired = Boolean.valueOf( CommonProperties.getInstance().getProperty("eric.common.noUserRegistrationRequired", "false")) .booleanValue(); if (!noRegRequired) { WSS4JSecurityUtilBST.verifySOAPEnvelopeOnServerBST(se, credentialInfo); } //The ebXML registry request is the only element in the SOAPBody StringWriter requestXML = new StringWriter(); //The request as an XML String String requestRootElement = null; Iterator<?> iter = sb.getChildElements(); int i = 0; while (iter.hasNext()) { Object obj = iter.next(); if (!(obj instanceof SOAPElement)) { continue; } if (i++ == 0) { SOAPElement elem = (SOAPElement) obj; Name name = elem.getElementName(); requestRootElement = name.getLocalName(); StreamResult result = new StreamResult(requestXML); TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); trans.transform(new DOMSource(elem), result); } else { throw new RegistryException( ServerResourceBundle.getInstance().getString("message.invalidRequest")); } } if (requestRootElement == null) { throw new RegistryException( ServerResourceBundle.getInstance().getString("message.noebXMLRegistryRequest")); } // unmarshalling request to message Object message = bu.getRequestObject(requestRootElement, requestXML.toString()); if (message instanceof JAXBElement<?>) { // If Element; take ComplexType from Element message = ((JAXBElement<?>) message).getValue(); } // request sets ServerContext with ComplexType: RegistryObjectType BSTRequest request = new BSTRequest(req, credentialInfo, message, idToRepositoryItemMap); Response response = request.process(); // response.getMessage() is ComplexType again soapResponse = createResponseSOAPMessage(response); if (response.getIdToRepositoryItemMap().size() > 0 && (response.getMessage().getStatus() .equals(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success))) { idToRepositoryItemMap = response.getIdToRepositoryItemMap(); Iterator<?> mapKeysIter = idToRepositoryItemMap.keySet().iterator(); while (mapKeysIter.hasNext()) { String id = (String) mapKeysIter.next(); RepositoryItem repositoryItem = (RepositoryItem) idToRepositoryItemMap.get(id); String cid = WSS4JSecurityUtilBST.convertUUIDToContentId(id); DataHandler dh = repositoryItem.getDataHandler(); AttachmentPart ap = soapResponse.createAttachmentPart(dh); ap.setMimeHeader("Content-Type", "text/xml"); ap.setContentId(cid); soapResponse.addAttachmentPart(ap); if (log.isTraceEnabled()) { log.trace("adding attachment: contentId=" + id); } } } } catch (Throwable t) { //Do not log ObjectNotFoundException as it clutters the log if (!(t instanceof ObjectNotFoundException)) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException", new Object[] { t.getMessage() }), t); Throwable cause = t.getCause(); while (cause != null) { log.error(ServerResourceBundle.getInstance().getString("message.CausedBy", new Object[] { cause.getMessage() }), cause); cause = cause.getCause(); } } soapResponse = createFaultSOAPMessage(t, sh); } if (log.isTraceEnabled()) { try { ByteArrayOutputStream rspOs = new ByteArrayOutputStream(); soapResponse.writeTo(rspOs); rspOs.close(); // Warning! BAOS.toString() uses platform's default encoding log.trace("response message:\n" + rspOs.toString()); } catch (Exception e) { log.error(ServerResourceBundle.getInstance().getString("message.FailedToLogResponseMessage", new Object[] { e.getMessage() }), e); } } return soapResponse; }
From source file:it.cnr.icar.eric.server.persistence.rdb.AbstractDAO.java
/** * Gets objects based upon parent set for this DAO * *//*w w w .ja va2 s . co m*/ public List<Object> getByParent() throws RegistryException { List<Object> objects = new ArrayList<Object>(); PreparedStatement stmt = null; try { String str = "SELECT * FROM " + getTableName() + " WHERE " + getParentAttribute() + " = ? "; stmt = context.getConnection().prepareStatement(str); stmt.setString(1, getParentId()); ResultSet rs = stmt.executeQuery(); objects = getObjects(rs, 0, -1); } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } catch (JAXRException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } finally { closeStatement(stmt); } return objects; }
From source file:it.cnr.icar.eric.server.persistence.rdb.ClassificationNodeDAO.java
protected String checkClassificationNodeReferences(java.sql.Connection conn, String nodeId) throws RegistryException { String referencingNodeId = null; PreparedStatement stmt = null; try {/* w w w . j av a2 s .c o m*/ String sql = "SELECT id FROM ClassificationNode WHERE " + "parent=? AND parent IS NOT NULL"; stmt = context.getConnection().prepareStatement(sql); stmt.setString(1, nodeId); ResultSet rs = stmt.executeQuery(); log.trace(sql); if (rs.next()) { referencingNodeId = rs.getString(1); } return referencingNodeId; } catch (SQLException e) { throw new RegistryException(e); } finally { closeStatement(stmt); } }
From source file:it.cnr.icar.eric.server.event.EmailNotifier.java
private String transformContent(ServerRequestContext context, String xsltId, String xmlNotif, String action, String user) throws RegistryException { try {// ww w . j a va 2 s . co m RepositoryItem repositoryItem = RepositoryManagerFactory.getInstance().getRepositoryManager() .getRepositoryItem(xsltId); StreamSource xsltIn = new StreamSource(repositoryItem.getDataHandler().getInputStream()); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(xsltIn); //transformer.setURIResolver(rm.getURIResolver()); transformer.setErrorListener(new ErrorListener() { public void error(TransformerException exception) throws TransformerException { log.info(ServerResourceBundle.getInstance().getString("xsltError"), exception); } public void fatalError(TransformerException exception) throws TransformerException { log.error(ServerResourceBundle.getInstance().getString("xsltFatalError"), exception); throw exception; } public void warning(TransformerException exception) throws TransformerException { log.info(ServerResourceBundle.getInstance().getString("xsltWarning"), exception); } }); //Set parameters transformer.setParameter("action", action); transformer.setParameter("user", user); transformer.setParameter("registryBaseURL", RegistryProperties.getInstance().getProperty("eric.registry.baseurl")); ByteArrayInputStream bais = new ByteArrayInputStream(xmlNotif.getBytes("utf-8")); StreamSource inputSrc = new StreamSource(bais); //TODO: use file in case we have a large amount of data to transform? ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamResult streamResult = new StreamResult(baos); transformer.transform(inputSrc, streamResult); return baos.toString("utf-8"); } catch (Exception e) { log.error(ServerResourceBundle.getInstance().getString("message.prettyPrintNotificationFailure"), e); throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.persistence.rdb.ClassificationNodeDAO.java
protected void loadObject(Object obj, ResultSet rs) throws RegistryException { try {//from www. j ava 2 s.co m if (!(obj instanceof ClassificationNodeType)) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.ClassificationNodeExpected", new Object[] { obj })); } ClassificationNodeType ebClassificationNodeType = (ClassificationNodeType) obj; super.loadObject(obj, rs); String code = rs.getString("code"); ebClassificationNodeType.setCode(code); String parent = rs.getString("parent"); if (parent != null) { ObjectRefType ebObjectRefType = bu.rimFac.createObjectRefType(); ebObjectRefType.setId(parent); context.getObjectRefs().add(ebObjectRefType); ebClassificationNodeType.setParent(parent); } String path = rs.getString("path"); ebClassificationNodeType.setPath(path); } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.repository.AbstractRepositoryManager.java
/** * Gets the RepositoryItem as a stream of XML markup given its id. * * @param id Unique if for ExtrinsicObject whose repository item is desired * @return a <code>StreamSource</code> value * @exception RegistryException if an error occurs *//*from w w w. ja va 2s . c o m*/ public StreamSource getAsStreamSource(String id) throws RegistryException { try { return new StreamSource(getRepositoryItem(id).getDataHandler().getInputStream()); } catch (Exception e) { throw new RegistryException(e); } }
From source file:it.cnr.icar.eric.server.interfaces.soap.RegistrySAMLServlet.java
@SuppressWarnings("unchecked") public SOAPMessage onMessage(SOAPMessage msg, HttpServletRequest req, HttpServletResponse resp) { SOAPMessage soapResponse = null; SOAPHeader soapHeader = null; try {/*from w w w . ja va2 s . c o m*/ // extract SOAP related parts from incoming SOAP message // set 'soapHeader' variable ASAP (before "firstly") SOAPPart soapPart = msg.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); soapHeader = soapEnvelope.getHeader(); /**************************************************************** * * REPOSITORY ITEM HANDLING (IN) REPOSITORY ITEM HANDLING (IN) * ***************************************************************/ // Firstly we put save the attached repository items in a map HashMap<String, Object> idToRepositoryItemMap = new HashMap<String, Object>(); Iterator<AttachmentPart> apIter = msg.getAttachments(); while (apIter.hasNext()) { AttachmentPart ap = apIter.next(); // Get the content for the attachment RepositoryItem ri = processIncomingAttachment(ap); idToRepositoryItemMap.put(ri.getId(), ri); } /**************************************************************** * * LOGGING (IN) LOGGING (IN) LOGGING (IN) LOGGING (IN) * ***************************************************************/ // Log received message if (log.isTraceEnabled()) { // Warning! BAOS.toString() uses platform's default encoding ByteArrayOutputStream msgOs = new ByteArrayOutputStream(); msg.writeTo(msgOs); msgOs.close(); log.trace("incoming message:\n" + msgOs.toString()); } /**************************************************************** * * MESSAGE VERIFICATION (IN) MESSAGE VERIFICATION (IN) * ***************************************************************/ CredentialInfo credentialInfo = new CredentialInfo(); WSS4JSecurityUtilSAML.verifySOAPEnvelopeOnServerSAML(soapEnvelope, credentialInfo); /**************************************************************** * * RS:REQUEST HANDLING RS:REQUEST HANDLING RS:REQUEST * ***************************************************************/ // The ebXML registry request is the only element in the SOAPBody StringWriter requestXML = new StringWriter(); // The request as an // XML String String requestRootElement = null; Iterator<?> iter = soapBody.getChildElements(); int i = 0; while (iter.hasNext()) { Object obj = iter.next(); if (!(obj instanceof SOAPElement)) { continue; } if (i++ == 0) { SOAPElement elem = (SOAPElement) obj; Name name = elem.getElementName(); requestRootElement = name.getLocalName(); StreamResult result = new StreamResult(requestXML); TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); trans.transform(new DOMSource(elem), result); } else { throw new RegistryException( ServerResourceBundle.getInstance().getString("message.invalidRequest")); } } if (requestRootElement == null) { throw new RegistryException( ServerResourceBundle.getInstance().getString("message.noebXMLRegistryRequest")); } // unmarshalling request to message Object message = bu.getRequestObject(requestRootElement, requestXML.toString()); if (message instanceof JAXBElement<?>) { // If Element; take ComplexType from Element message = ((JAXBElement<?>) message).getValue(); } SAMLRequest request = new SAMLRequest(req, credentialInfo.assertion, message, idToRepositoryItemMap); Response response = request.process(); /**************************************************************** * * RESPONSE HANDLING RESPONSE HANDLING RESPONSE HANDLING * ***************************************************************/ soapResponse = createResponseSOAPMessage(response); if (response.getIdToRepositoryItemMap().size() > 0 && (response.getMessage().getStatus() .equals(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success))) { idToRepositoryItemMap = response.getIdToRepositoryItemMap(); Iterator<String> mapKeysIter = idToRepositoryItemMap.keySet().iterator(); while (mapKeysIter.hasNext()) { String id = mapKeysIter.next(); RepositoryItem repositoryItem = (RepositoryItem) idToRepositoryItemMap.get(id); String cid = WSS4JSecurityUtilSAML.convertUUIDToContentId(id); DataHandler dh = repositoryItem.getDataHandler(); AttachmentPart ap = soapResponse.createAttachmentPart(dh); ap.setContentId(cid); soapResponse.addAttachmentPart(ap); if (log.isTraceEnabled()) { log.trace("adding attachment: contentId=" + id); } } } } catch (Throwable t) { // Do not log ObjectNotFoundException as it clutters the log if (!(t instanceof ObjectNotFoundException)) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException", new Object[] { t.getMessage() }), t); Throwable cause = t.getCause(); while (cause != null) { log.error(ServerResourceBundle.getInstance().getString("message.CausedBy", new Object[] { cause.getMessage() }), cause); cause = cause.getCause(); } } soapResponse = createFaultSOAPMessage(t, soapHeader); } if (log.isTraceEnabled()) { try { ByteArrayOutputStream rspOs = new ByteArrayOutputStream(); soapResponse.writeTo(rspOs); rspOs.close(); // Warning! BAOS.toString() uses platform's default encoding log.trace("response message:\n" + rspOs.toString()); } catch (Exception e) { log.error(ServerResourceBundle.getInstance().getString("message.FailedToLogResponseMessage", new Object[] { e.getMessage() }), e); } } return soapResponse; }
From source file:it.cnr.icar.eric.server.security.authorization.RegistryPolicyFinderModule.java
/** * Returns the root or top level policy that contains a descendant policy with specified * id.//from ww w . jav a 2s .com */ @SuppressWarnings("rawtypes") private AbstractPolicy loadRootPolicyFor(ServerRequestContext context, String composedPolicyId) throws RegistryException { log.debug("Loading root policy for composed policy with id=" + composedPolicyId); AbstractPolicy rootPolicy = null; try { String id = null; ResponseOptionType ebResponseOptionType = BindingUtility.getInstance().queryFac .createResponseOptionType(); ebResponseOptionType.setReturnType(ReturnType.LEAF_CLASS); ebResponseOptionType.setReturnComposedObjects(true); String query = "SELECT policy.* from ExtrinsicObject policy, Slot s WHERE " + "((policy.objectType = '" + BindingUtility.CANONICAL_OBJECT_TYPE_LID_Policy + "') OR " + "(policy.objectType = '" + BindingUtility.CANONICAL_OBJECT_TYPE_LID_PolicySet + "')) AND s.name_ = 'ComposedPolicies' AND policy.id = " + "s.parent AND s.value = '" + composedPolicyId + "'"; List objectRefs = new ArrayList(); List<IdentifiableType> ebIdentifiableTypeResultList = pm.executeSQLQuery(context, query, ebResponseOptionType, "ExtrinsicObject", objectRefs); List<String> ids = bu.getIdsFromRegistryObjectTypes(ebIdentifiableTypeResultList); int cnt = ids.size(); if (cnt > 1) { log.warn(ServerResourceBundle.getInstance().getString( "message.MoreThan1AccessControlPolicyFoundContainingComposedPolicy", new Object[] { composedPolicyId })); } if (cnt >= 1) { id = ids.get(0); rootPolicy = loadPolicy(context, id); } } catch (RegistryException e) { throw e; } catch (Exception e) { throw new RegistryException(e); } return rootPolicy; }