List of usage examples for javax.xml.registry JAXRException JAXRException
public JAXRException(Throwable cause)
JAXRException
object initialized with the given Throwable
object. From source file:it.cnr.icar.eric.client.xml.registry.util.CertificateUtil.java
@SuppressWarnings("static-access") private static Certificate[] getCertificateSignedByRegistry(LifeCycleManager lcm, X509Certificate inCert) throws JAXRException { Certificate[] certChain = new Certificate[2]; try {/* w w w . j a va2s. com*/ // Save cert in a temporary keystore file which is sent as // repository item to server so it can be signed KeyStore tmpKeystore = KeyStore.getInstance("JKS"); tmpKeystore.load(null, bu.FREEBXML_REGISTRY_KS_PASS_REQ.toCharArray()); tmpKeystore.setCertificateEntry(bu.FREEBXML_REGISTRY_USERCERT_ALIAS_REQ, inCert); File repositoryItemFile = File.createTempFile(".eric-ca-req", ".jks"); repositoryItemFile.deleteOnExit(); FileOutputStream fos = new java.io.FileOutputStream(repositoryItemFile); tmpKeystore.store(fos, bu.FREEBXML_REGISTRY_KS_PASS_REQ.toCharArray()); fos.flush(); fos.close(); // Now have server sign the cert using extensionRequest javax.activation.DataHandler repositoryItem = new DataHandler(new FileDataSource(repositoryItemFile)); String id = it.cnr.icar.eric.common.Utility.getInstance().createId(); HashMap<String, Object> idToRepositoryItemsMap = new HashMap<String, Object>(); idToRepositoryItemsMap.put(id, repositoryItem); HashMap<String, String> slotsMap = new HashMap<String, String>(); slotsMap.put(BindingUtility.FREEBXML_REGISTRY_PROTOCOL_SIGNCERT, "true"); RegistryRequestType req = bu.rsFac.createRegistryRequestType(); bu.addSlotsToRequest(req, slotsMap); RegistryResponseHolder respHolder = ((LifeCycleManagerImpl) lcm).extensionRequest(req, idToRepositoryItemsMap); DataHandler responseRepositoryItem = (DataHandler) respHolder.getAttachmentsMap().get(id); InputStream is = responseRepositoryItem.getInputStream(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(is, bu.FREEBXML_REGISTRY_KS_PASS_RESP.toCharArray()); is.close(); certChain[0] = keyStore.getCertificate(bu.FREEBXML_REGISTRY_USERCERT_ALIAS_RESP); if (certChain[0] == null) { throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.CannotFindUserCert")); } certChain[1] = keyStore.getCertificate(bu.FREEBXML_REGISTRY_CACERT_ALIAS); if (certChain[1] == null) { throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.CannotFindCARootCert")); } } catch (Exception e) { throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.CertSignFailed"), e); } return certChain; }
From source file:it.cnr.icar.eric.client.ui.thin.SearchPanelBean.java
@SuppressWarnings("unchecked") private BulkResponse executeQuery(Query query, @SuppressWarnings("rawtypes") Map queryParams, IterativeQueryParams iqParams) throws JAXRException { BulkResponse bulkResponse = null;/*from w w w . j av a2 s .co m*/ try { DeclarativeQueryManagerImpl dqm = RegistryBrowser.getDQM(); // Use search depth parameter for all queries. Support can be // added incrementally on server side for depth-related requests. queryParams.put(CanonicalConstants.CANONICAL_SEARCH_DEPTH_PARAMETER, getSearchDepth()); if (isCompressContent) { ExportBean.getInstance().setZipFileName(null); Collection<String> filterQueryIds = new ArrayList<String>(); filterQueryIds.add(BindingUtility.FREEBXML_REGISTRY_FILTER_QUERY_COMPRESSCONTENT); queryParams.put("$queryFilterIds", filterQueryIds); } bulkResponse = dqm.executeQuery(query, queryParams, iqParams); Collection<?> exceptions = bulkResponse.getExceptions(); //TO DO: forward exceptions to an error JSP if (exceptions != null) { Iterator<?> iter = exceptions.iterator(); Exception exception = null; StringBuffer sb = new StringBuffer(WebUIResourceBundle.getInstance().getString("errorExecQuery")); while (iter.hasNext()) { exception = (Exception) iter.next(); } log.error("\n" + exception.getMessage()); throw new JAXRException(sb.toString()); } else { if (isCompressContent) { handleCompressedContent(bulkResponse); } } } catch (Throwable t) { log.error(WebUIResourceBundle.getInstance().getString("message.ErrorDuringRequestProcessing"), t); throw new JAXRException( WebUIResourceBundle.getInstance().getString("errorRequestProcessing") + t.getMessage()); } return bulkResponse; }
From source file:it.cnr.icar.eric.client.ui.common.ReferenceAssociation.java
public void setReferenceAttributeOnSourceObject() throws JAXRException { String referenceAttribute = this.getReferenceAttribute(); //Now use Refelection API to add target to src try {/* www .ja v a 2 s .co m*/ Class<? extends RegistryObject> srcClass = src.getClass(); Class<?> targetClass = target.getClass(); Class<?> registryObjectClass = null; String targetInterfaceName = targetClass.getName(); targetInterfaceName = targetInterfaceName.substring(targetInterfaceName.lastIndexOf(".") + 1); if (targetInterfaceName.endsWith("Impl")) { //Remove Impl suffix for JAXR provider Impl classes targetInterfaceName = targetInterfaceName.substring(0, targetInterfaceName.length() - 4); } targetInterfaceName = "javax.xml.registry.infomodel." + targetInterfaceName; ClassLoader classLoader = srcClass.getClassLoader(); try { targetClass = classLoader.loadClass(targetInterfaceName); registryObjectClass = classLoader.loadClass("javax.xml.registry.infomodel.RegistryObject"); } catch (ClassNotFoundException e) { throw new JAXRException("No JAXR interface found by name " + targetInterfaceName); } @SuppressWarnings("static-access") String suffix = UIUtility.getInstance().initCapString(referenceAttribute); Method method = null; Class<?>[] paramTypes = new Class[1]; //See if there is a simple attribute of this name using type of targetObject try { paramTypes[0] = targetClass; method = srcClass.getMethod("set" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = false; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //See if there is a simple attribute of this name using base type RegistryObject try { paramTypes[0] = registryObjectClass; method = srcClass.getMethod("set" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = false; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //See if there is a addCXXX method for suffix of XXX ending in "s" for plural if (suffix.endsWith("s")) { suffix = suffix.substring(0, suffix.length() - 1); } try { paramTypes[0] = targetClass; method = srcClass.getMethod("add" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = true; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //See if there is a addCXXX method for suffix of XXX ending in "es" for plural if (suffix.endsWith("e")) { suffix = suffix.substring(0, suffix.length() - 1); } try { paramTypes[0] = targetClass; method = srcClass.getMethod("add" + suffix, paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = true; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } //Special case while adding child organization to an organization if (src instanceof Organization && target instanceof Organization) { try { paramTypes[0] = targetClass; method = srcClass.getMethod("addChildOrganization", paramTypes); Object[] params = new Object[1]; params[0] = target; method.invoke(src, params); isCollectionRef = true; return; } catch (NoSuchMethodException | IllegalAccessException e) { method = null; } } throw new JAXRException("No method found for reference attribute " + referenceAttribute + " for src object of type " + srcClass.getName()); } catch (IllegalArgumentException e) { throw new JAXRException(e); } catch (InvocationTargetException e) { throw new JAXRException(e.getCause()); } catch (ExceptionInInitializerError e) { throw new JAXRException(e); } }
From source file:it.cnr.icar.eric.client.xml.registry.util.SecurityUtil.java
public Certificate[] getCertificateChain(java.security.cert.X509Certificate cert) throws JAXRException { Certificate[] certChain = null; getKeyStore();/*from w w w . ja va2 s .co m*/ try { String alias = keyStore.getCertificateAlias(cert); // Check if the alias is null and don't get the certificate chain // if it is as this will cause an NPE. This may be a bug in // the sun implementation of the KeyStore class // (sun.security.provider.JavaKeyStore) as the javadoc indicates that // the method should return null if the alias is not found. // Under normal operation, the alias should never be null, but // it is possible to set credentials on the connection that are not // in the jaxr client keystore, and this works fine except that // the getCertificateChain() method throws an NPE. if (alias != null) { certChain = keyStore.getCertificateChain(alias); } if (certChain == null) { certChain = new Certificate[1]; certChain[0] = cert; } } catch (KeyStoreException x) { throw new JAXRException(x); } return certChain; }
From source file:it.cnr.icar.eric.client.xml.registry.ConnectionImpl.java
/** * Sets the Credentials associated with this client. The * credentials is used to authenticate the client with the JAXR * provider. A JAXR client may dynamically change its identity by * changing the credentials associated with it. * * <p>/* w w w.j a va2 s . com*/ * <DL> * <dt> * <B>Capability Level: 0 </B> * </dt> * </dl> * </p> * * @param credentials a Collection of java.lang.Objects which * provide identity-related information for the caller. * * @throws JAXRException If the JAXR provider encounters an * internal error */ public void setCredentials(@SuppressWarnings("rawtypes") Set credentials) throws JAXRException { for (Iterator<?> it = credentials.iterator(); it.hasNext();) { Object obj = it.next(); // enable SAML v2 assertion if (obj instanceof Assertion) { assertion = (Assertion) obj; ((RegistryServiceImpl) getRegistryService()).setCredentialInfo(getCredentialInfo()); return; } else if (obj instanceof X500PrivateCredential) { x500Cred = (X500PrivateCredential) obj; ((RegistryServiceImpl) getRegistryService()).setCredentialInfo(getCredentialInfo()); return; } else if (localCallMode && credentials.size() == 1 && obj instanceof X509Certificate) { // this should work only for localCallMode mode, where no signing is // required and we trust the container to provide credentials setX509Certificate((X509Certificate) obj); ((RegistryServiceImpl) getRegistryService()).setCredentialInfo(getCredentialInfo()); return; } } // adapt exception to multi-dimensional credentials throw new JAXRException(JAXRResourceBundle.getInstance() .getString("Neither SAML v2 assertion nor X.500 credentials provided.")); }
From source file:it.cnr.icar.eric.client.xml.registry.RegistryFacadeImpl.java
@SuppressWarnings({ "unused", "static-access" }) public ExtrinsicObject publishFilesAsZip(String baseDirectory, String[] relativeFilePaths, Map<?, ?> metadata) throws JAXRException { ExtrinsicObjectImpl eo = null;//w ww . ja va 2 s . c o m if (getLifeCycleManager() == null) { throw new JAXRException("setEndpoint MUST be called before setCredentials is called."); } try { //Create the zip file File zipFile = File.createTempFile("eric-RegistryFacadeImpl", ".zip"); zipFile.deleteOnExit(); FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = Utility.createZipOutputStream(baseDirectory, relativeFilePaths, fos); zos.close(); javax.activation.DataSource ds = new javax.activation.FileDataSource(zipFile); javax.activation.DataHandler dh = new javax.activation.DataHandler(ds); if (dh == null) { throw new JAXRException("Error processing zip file" + zipFile.getAbsolutePath()); } eo = (ExtrinsicObjectImpl) getLifeCycleManager().createExtrinsicObject(dh); String id = (String) metadata.remove(bu.CANONICAL_SLOT_IDENTIFIABLE_ID); String name = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_NAME); String description = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_DESCRIPTION); String objectType = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_OBJECTTYPE); //If id is specified then use it. if (id != null) { eo.setKey(lcm.createKey(id)); eo.setLid(id); } String eoId = eo.getKey().getId(); //If name is specified then use it. if (name != null) { eo.setName(lcm.createInternationalString(name)); } //If description is specified then use it. if (description != null) { eo.setDescription(lcm.createInternationalString(description)); } if (objectType == null) { throw new InvalidRequestException( JAXRResourceBundle.getInstance().getString("message.error.missingMetadata", new Object[] { bu.CANONICAL_SLOT_REGISTRY_OBJECT_OBJECTTYPE })); } eo.setMimeType("application/zip"); eo.setObjectTypeRef(new RegistryObjectRef(getLifeCycleManager(), objectType)); ArrayList<RegistryObject> objects = new ArrayList<RegistryObject>(); objects.add(eo); //??Turn of versioning on save as it creates problems BulkResponse br = getLifeCycleManager().saveObjects(objects, dontVersionSlotsMap); if (br.getExceptions() != null) { throw new JAXRException("Error publishing to registry", (Exception) (br.getExceptions().toArray()[0])); } if (br.getStatus() != BulkResponse.STATUS_SUCCESS) { throw new JAXRException("Error publishing to registry. See server logs for detils."); } } catch (IOException e) { throw new JAXRException(e); } return eo; }
From source file:it.cnr.icar.eric.client.xml.registry.BulkResponseImpl.java
RegistryObject getRegistryObject() throws JAXRException { RegistryObject ro = null;/* www . jav a2 s. c om*/ // check for errors Collection<RegistryException> exceptions = getExceptions(); if (exceptions != null) { Iterator<RegistryException> iter = exceptions.iterator(); Exception exception = null; while (iter.hasNext()) { exception = iter.next(); throw new JAXRException(exception); } } Collection<?> results = getCollection(); Iterator<?> iter = results.iterator(); if (iter.hasNext()) { ro = (RegistryObject) iter.next(); } return ro; }
From source file:it.cnr.icar.eric.client.ui.thin.SearchPanelBean.java
private void handleCompressedContent(BulkResponse bulkResponse) throws JAXRException { try {// ww w.ja va2 s. co m Iterator<?> itr = bulkResponse.getCollection().iterator(); if (itr.hasNext()) { RegistryObject ro = (RegistryObject) itr.next(); if (ro != null) { Slot fileNameSlot = ro .getSlot(BindingUtility.FREEBXML_REGISTRY_FILTER_QUERY_COMPRESSCONTENT_FILENAME); if (fileNameSlot != null) { Iterator<?> slotItr = fileNameSlot.getValues().iterator(); if (slotItr.hasNext()) { String filename = (String) slotItr.next(); ExportBean.getInstance().setZipFileName(filename); } } } } } catch (Throwable t) { throw new JAXRException(t); } }
From source file:it.cnr.icar.eric.common.SOAPMessenger.java
/** Send a SOAP request to the registry server. Main entry point for * this class. If credentials have been set on the registry connection, * they will be used to sign the request. * * @param requestString/*from w w w.ja v a 2 s. c o m*/ * String that will be placed in the body of the * SOAP message to be sent to the server * * @param attachments * HashMap consisting of entries each of which * corresponds to an attachment where the entry key is the ContentId * and the entry value is a javax.activation.DataHandler of the * attachment. A parameter value of null means no attachments. * * @return * RegistryResponseHolder that represents the response from the * server */ @SuppressWarnings("unchecked") public RegistryResponseHolder sendSoapRequest(String requestString, Map<?, ?> attachments) throws JAXRException { boolean logRequests = Boolean.valueOf( CommonProperties.getInstance().getProperty("eric.common.soapMessenger.logRequests", "false")) .booleanValue(); if (logRequests) { PrintStream requestLogPS = null; try { requestLogPS = new PrintStream( new FileOutputStream(java.io.File.createTempFile("SOAPMessenger_requestLog", ".xml"))); requestLogPS.println(requestString); } catch (IOException e) { e.printStackTrace(); } finally { if (requestLogPS != null) { requestLogPS.close(); } } } // ================================================================= // // Remove the XML Declaration, if any // if (requestString.startsWith("<?xml")) { // requestString = requestString.substring(requestString.indexOf("?>")+2).trim(); // } // // StringBuffer soapText = new StringBuffer( // "<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">"); // // soapText.append("<soap-env:Header>\n"); // // tell server about our superior SOAP Fault capabilities // soapText.append("<"); // soapText.append(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName); // soapText.append(" xmlns='"); // soapText.append(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace); // soapText.append("'>"); // soapText.append(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes); // soapText.append("</"); // soapText.append(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName); // soapText.append(">\n"); // soapText.append("</soap-env:Header>\n"); // soapText.append("<soap-env:Body>\n"); // soapText.append(requestString); // soapText.append("</soap-env:Body>"); // soapText.append("</soap-env:Envelope>"); MessageFactory messageFactory; SOAPMessage message = null; SOAPPart sp = null; SOAPEnvelope se = null; SOAPBody sb = null; SOAPHeader sh = null; if (log.isTraceEnabled()) { log.trace("requestString=\"" + requestString + "\""); } try { messageFactory = MessageFactory.newInstance(); message = messageFactory.createMessage(); sp = message.getSOAPPart(); se = sp.getEnvelope(); sb = se.getBody(); sh = se.getHeader(); /* * <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> * <soap-env:Header> * <capabilities xmlns="urn:freebxml:registry:soap">urn:freebxml:registry:soap:modernFaultCodes</capabilities> * * change with explicit namespace * <ns1:capabilities xmlns:ns1="urn:freebxml:registry:soap">urn:freebxml:registry:soap:modernFaultCodes</ns1:capabilities> */ SOAPHeaderElement capabilityElement = sh .addHeaderElement(se.createName(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName, "ns1", BindingUtility.SOAP_CAPABILITY_HEADER_Namespace)); // capabilityElement.addAttribute( // se.createName("xmlns"), // BindingUtility.SOAP_CAPABILITY_HEADER_Namespace); capabilityElement.setTextContent(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes); /* * body */ // Remove the XML Declaration, if any if (requestString.startsWith("<?xml")) { requestString = requestString.substring(requestString.indexOf("?>") + 2).trim(); } // Generate DOM Document from request xml string DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); InputStream stream = new ByteArrayInputStream(requestString.getBytes("UTF-8")); // Inject request into body sb.addDocument(builderFactory.newDocumentBuilder().parse(stream)); // Is it never the case that there attachments but no credentials if ((attachments != null) && !attachments.isEmpty()) { addAttachments(message, attachments); } if (credentialInfo == null) { throw new JAXRException(resourceBundle.getString("message.credentialInfo")); } WSS4JSecurityUtilSAML.signSOAPEnvelopeOnClientSAML(se, credentialInfo); SOAPMessage response = send(message); // Check to see if the session has expired // by checking for an error response code // TODO: what error code to we look for? if (isSessionExpired(response)) { credentialInfo.sessionId = null; // sign the SOAPMessage this time // TODO: session - add method to do the signing // signSOAPMessage(msg); // send signed message // SOAPMessage response = send(msg); } // Process the main SOAPPart of the response //check for soapfault and throw RegistryException SOAPFault fault = response.getSOAPBody().getFault(); if (fault != null) { throw createRegistryException(fault); } Reader reader = processResponseBody(response, "Response"); RegistryResponseType ebResponse = null; try { Object obj = BindingUtility.getInstance().getJAXBContext().createUnmarshaller() .unmarshal(new InputSource(reader)); if (obj instanceof JAXBElement<?>) // if Element: take ComplexType from Element obj = ((JAXBElement<RegistryResponseType>) obj).getValue(); ebResponse = (RegistryResponseType) obj; } catch (Exception x) { log.error(CommonResourceBundle.getInstance().getString("message.FailedToUnmarshalServerResponse"), x); throw new JAXRException(resourceBundle.getString("message.invalidServerResponse")); } // Process the attachments of the response if any HashMap<String, Object> responseAttachments = processResponseAttachments(response); return new RegistryResponseHolder(ebResponse, responseAttachments); } catch (SAXException e) { throw new JAXRException(e); } catch (ParserConfigurationException e) { throw new JAXRException(e); } catch (UnsupportedEncodingException x) { throw new JAXRException(x); } catch (MessagingException x) { throw new JAXRException(x); } catch (FileNotFoundException x) { throw new JAXRException(x); } catch (IOException e) { throw new JAXRException(e); } catch (SOAPException x) { x.printStackTrace(); throw new JAXRException(resourceBundle.getString("message.cannotConnect"), x); } catch (TransformerConfigurationException x) { throw new JAXRException(x); } catch (TransformerException x) { throw new JAXRException(x); } }
From source file:it.cnr.icar.eric.client.ui.swing.JAXRClient.java
private void isConnected() throws JAXRException { if (!connected) { // try again, now synchro. will wait if in startup. synchronized (this) { if (!connected) { throw new JAXRException( JavaUIResourceBundle.getInstance().getString("message.error.noConnection")); }//from ww w. ja v a 2s. com } } }