Example usage for javax.xml.registry JAXRException JAXRException

List of usage examples for javax.xml.registry JAXRException JAXRException

Introduction

In this page you can find the example usage for javax.xml.registry JAXRException JAXRException.

Prototype

public JAXRException(Throwable cause) 

Source Link

Document

Constructs a JAXRException object initialized with the given Throwable object.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.util.JAXRUtility.java

/**
 * Throws exception if BulkResponse contains any exceptions.
 *
 * @param response/*  w ww. j  a  v  a  2 s. c o m*/
 * @throws JAXRException
 */
public static void checkBulkResponse(BulkResponse response) throws JAXRException {
    Collection<?> exes = response.getExceptions();
    if (exes == null) {
        return;
    }
    throw new JAXRException((JAXRException) getFirstObject(exes));
}

From source file:it.cnr.icar.eric.client.ui.thin.jsf.ExplorerGraphBean.java

private void loadRegistryObjectChildNodes(RegistryObjectNode parentNode) throws JAXRException {
    Concept concept = parentNode.getRegistryObjectType();
    Iterator<?> itr = concept.getChildrenConcepts().iterator();
    RegistryObjectNode roNode = null;//from w w w .j a  v a 2  s  . c  o m
    if (itr.hasNext()) {
        parentNode.clearChildren();
        RegistryPackage rOCPkg = null;
        while (itr.hasNext()) {
            Concept childConcept = (Concept) itr.next();
            try {
                rOCPkg = RegistryBrowser.getBLCM().createRegistryPackage(childConcept.getValue());
            } catch (Exception ex) {
                throw new JAXRException(ex);
            }
            roNode = new RegistryObjectNode(rOCPkg, childConcept);
            parentNode.addChild(roNode);
            roNode.setHasChild(childConcept.getChildConceptCount() > 0);
        }
        if (roNode != null) {
            roNode.setLast(true);
        }
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.ConnectionImpl.java

/**
 * Forces authentication to occur.//from   w w  w .  jav a  2s.  c  o  m
 ** Add to JAXR 2.0??
 *
 * @throws JAXRException DOCUMENT ME!
 */
public void authenticate() throws JAXRException {
    // Obtain a LoginContext, needed for authentication. Tell it 
    // to use the LoginModule implementation specified by the 
    // entry named "Sample" in the JAAS login configuration 
    // file and to also use the specified CallbackHandler.
    LoginContext lc = null;

    try {
        loginModuleMgr.createLoginConfigFile();

        String applicationName = loginModuleMgr.getApplicationName();
        handler = loginModuleMgr.getCallbackHandler();

        lc = new LoginContext(applicationName, handler);

        // attempt authentication
        lc.login();

        //Get the authenticated Subject.
        Subject subject = lc.getSubject();
        Set<Object> privateCredentials = subject.getPrivateCredentials();

        //Set credentials on JAXR Connections
        setCredentials(privateCredentials);

        log.info(JAXRResourceBundle.getInstance().getString("message.SetCredentialsOnConnection"));
    } catch (LoginException le) {
        String msg = le.getMessage();

        if ((msg != null) && (!(msg.equalsIgnoreCase("Login cancelled")))) {
            throw new JAXRException(le);
        }
    } catch (SecurityException se) {
        throw new JAXRException(se);
    }
}

From source file:it.cnr.icar.eric.client.ui.thin.security.SecurityUtil.java

/** Generate a key pair and add it to the keystore.
  *// w  w w .  java  2s . co m
  * @param alias
  * @return
  *     A HashSet of X500PrivateCredential objects.
  * @throws Exception
  */
private Set<Object> generateCredentials(String alias) throws JAXRException {

    try {
        HashSet<Object> credentials = new HashSet<Object>();

        // The keystore file is at ${jaxr-ebxml.home}/security/keystore.jks. If
        // the 'jaxr-ebxml.home' property is not set, ${user.home}/jaxr-ebxml/ is
        // used.
        File keyStoreFile = KeystoreUtil.getKeystoreFile();
        String storepass = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storepass",
                "ebxmlrr");
        String keypass = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.keypass");
        if (keypass == null) {
            // keytool utility requires a six character minimum password.
            // pad passwords with < six chars
            if (alias.length() >= 6) {
                keypass = alias;
            } else if (alias.length() == 5) {
                keypass = alias + "1";
            } else if (alias.length() == 4) {
                keypass = alias + "12";
            } else if (alias.length() == 3) {
                keypass = alias + "123";
            }
            // alias should have at least 3 chars
        }
        log.debug("Generating key pair for '" + alias + "' in '" + keyStoreFile.getAbsolutePath() + "'");

        // When run in S1WS 6.0, this caused some native library errors. It appears that S1WS
        // uses different encryption spis than those in the jdk. 
        //            String[] args = {
        //                "-genkey", "-alias", uid, "-keypass", "keypass",
        //                "-keystore", keyStoreFile.getAbsolutePath(), "-storepass",
        //                new String(storepass), "-dname", "uid=" + uid + ",ou=People,dc=sun,dc=com"
        //            };
        //            KeyTool keytool = new KeyTool();
        //            ByteArrayOutputStream keytoolOutput = new ByteArrayOutputStream();
        //            try {
        //                keytool.run(args, new PrintStream(keytoolOutput));
        //            }
        //            finally {
        //                log.info(keytoolOutput.toString());
        //            }
        // To work around this problem, generate the key pair using keytool (which executes
        // in its own vm. Note that all the parameters must be specified, or keytool prompts
        // for their values and this 'hangs'
        String[] cmdarray = { "keytool", "-genkey", "-alias", alias, "-keypass", keypass, "-keystore",
                keyStoreFile.getAbsolutePath(), "-storepass", storepass, "-dname", "cn=" + alias };
        Process keytool = Runtime.getRuntime().exec(cmdarray);
        try {
            keytool.waitFor();
        } catch (InterruptedException ie) {
        }
        if (keytool.exitValue() != 0) {
            log.error(WebUIResourceBundle.getInstance().getString("message.keytoolCommandFailedDetails"));
            Reader reader = new InputStreamReader(keytool.getErrorStream());
            BufferedReader bufferedReader = new BufferedReader(reader);
            while (bufferedReader.ready()) {
                log.error(bufferedReader.readLine());
            }
            throw new JAXRException(
                    WebUIResourceBundle.getInstance().getString("excKeyToolCommandFail") + keytool.exitValue());
        }
        log.debug("Key pair generated successfully.");

        // After generating the keypair in the keystore file, we have to reload
        // SecurityUtil's KeyStore object.
        KeyStore keyStore = it.cnr.icar.eric.client.xml.registry.util.SecurityUtil.getInstance().getKeyStore();
        keyStore.load(new FileInputStream(keyStoreFile), storepass.toCharArray());

        credentials.add(it.cnr.icar.eric.client.xml.registry.util.SecurityUtil.getInstance()
                .aliasToX500PrivateCredential(alias));

        return credentials;
    } catch (Exception e) {
        if (e instanceof JAXRException) {
            throw (JAXRException) e;
        } else {
            throw new JAXRException(e);
        }
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.jaas.LoginModuleManager.java

/**
 * This method is used to create the default login configuration file.
 * Currently, the default file is for the
 * com.sun.security.auth.module.KeystoreLoginModule
 *
 * @throws JAXRException//from w  w w.j  a  va  2  s.  co  m
 *  This is thrown if there is a problem writing the default login config
 *  file to the filesystem
 */
public void createDefaultLoginConfigFile() throws JAXRException {
    log.trace("start creation of default login config file");

    File keystoreFile = KeystoreUtil.getKeystoreFile();
    KeystoreUtil.canReadKeystoreFile(keystoreFile);

    // This property should always be set by java
    String userHomeFileName = System.getProperty("user.home");

    if ((userHomeFileName == null) || (userHomeFileName.length() == 0)) {
        throw new JAXRException(
                JAXRResourceBundle.getInstance().getString("message.error.not.find.system.property"));
    }

    File configFile;
    // Login config filename might be define as system property
    String configFileName = System.getProperty("java.security.auth.login.config");
    if (configFileName != null) {
        configFile = new File(configFileName);
    } else {
        configFile = new File(userHomeFileName, ".java.login.config");
    }

    if (configFile.exists()) {
        if (configFile.canRead()) {
            Configuration config = ConfigFile.getConfiguration();
            String appName = getApplicationName();
            AppConfigurationEntry[] defaultAppConfigEntries = getReloadedAppConfigurationEntries(config,
                    configFile.getPath() + ".tmp",
                    getDefaultConfigFileContents(DEFAULT_APPLICATION_NAME + ".tmp"), appName + ".tmp");
            AppConfigurationEntry[] userAppConfigEntries = config.getAppConfigurationEntry(appName);

            //TODO: Paul to verify this!! What if one of the Entries is null??
            boolean isCorrect;
            if (defaultAppConfigEntries == null && userAppConfigEntries == null) {
                // this will happen when using constructor LoginModuleManager(String applicationName)
                // and not having an entry for 'applicationName' in .java.login.config
                isCorrect = true;
            } else if (defaultAppConfigEntries != null && userAppConfigEntries == null) {
                // force add default to existing cfg file
                isCorrect = false;
            } else {
                isCorrect = checkLoginModules(userAppConfigEntries, defaultAppConfigEntries);
            }

            // if the user has a login config file with the same app name
            // as the default, but the login modules are different, rename
            // the existing user login config file and write the default
            // config file in place of the existing
            if (!isCorrect) {
                String userCfgFileName = configFile.getPath();
                String userCfgFileContent = getUserCfgFileContents(userCfgFileName);
                log.warn(JAXRResourceBundle.getInstance()
                        .getString("message.UserLoginConfigFileDoesNotHaveTheSameLoginModulesAsTheDefault"));
                renameCfgFile(userCfgFileName, userCfgFileName + ".bak");
                writeCfgFile(configFile, userCfgFileContent + LINE_SEPARATOR + getDefaultConfigFileContents(),
                        false);
                config.refresh();
                log.info(JAXRResourceBundle.getInstance().getString("message.createdNewLoginConfigFile",
                        new Object[] { configFile.getName() }));
            } else {
                log.info(JAXRResourceBundle.getInstance().getString("message.usingExistingConfigFile",
                        new Object[] { configFile.getName() }));

                return;
            }
        } else {
            throw new JAXRException(JAXRResourceBundle.getInstance().getString(
                    "message.error.file.not.readable", new Object[] { configFile.getAbsolutePath() }));
        }
    } else {
        writeCfgFile(configFile, getDefaultConfigFileContents(), false);
        log.info(JAXRResourceBundle.getInstance().getString("message.createdNewLoginConfigFile",
                new Object[] { configFile.getName() }));
    }

    log.trace("finish creation of default login config file");
}

From source file:it.cnr.icar.eric.client.xml.registry.RegistryFacadeImpl.java

/**
 * Get the specified artifacts from Service Registry.
 * // w  w w.  ja  va 2 s . c  om
 * @see [WSPROF] ebXML Registry Profile for Web Services: http://www.oasis-open.org/committees/document.php?document_id=14756
 * @param queryId Identifies the discovery query that is preconfigured registry
 * @param queryParams key is a parameter name String (e.g. $service.name), value is a parameter value String as described by [WSPROF]
 * @return Set of javax.xml.registry.infomodel.RegistryObject.
 *
 * @throws JAXRException an exception thrown by JAXR Provider.
 */
@SuppressWarnings("static-access")
public Collection<?> executeQuery(String queryId, Map<String, String> queryParams) throws JAXRException {
    if (getDeclarativeQueryManager() == null) {
        throw new JAXRException("setEndpoint MUST be called before setCredentials is called.");
    }

    Collection<?> registryObjects = null;

    queryParams.put(BindingUtility.getInstance().CANONICAL_SLOT_QUERY_ID, queryId);
    Query query = (getDeclarativeQueryManager()).createQuery(Query.QUERY_TYPE_SQL);
    BulkResponse bResponse = getDeclarativeQueryManager().executeQuery(query, queryParams);
    registryObjects = bResponse.getCollection();

    return registryObjects;
}

From source file:it.cnr.icar.eric.client.xml.registry.RegistryFacadeImpl.java

private void createConnection(String qmEndpoint, String lcmEndpoint) throws JAXRException {
    ConnectionFactory connFactory = JAXRUtility.getConnectionFactory();

    Properties props = new Properties();

    if (qmEndpoint == null) {
        throw new JAXRException("QueryManager endpoint MUST not be null");
    }//from  ww  w . j av a 2  s  .c  om
    props.put("javax.xml.registry.queryManagerURL", qmEndpoint);
    if (lcmEndpoint != null) {
        props.put("javax.xml.registry.lifeCycleManagerURL", qmEndpoint);
    }
    connFactory.setProperties(props);
    connection = connFactory.createConnection();

    service = getConnection().getRegistryService();
    bqm = (BusinessQueryManagerImpl) getService().getBusinessQueryManager();
    lcm = (BusinessLifeCycleManagerImpl) getService().getBusinessLifeCycleManager();
    dqm = (DeclarativeQueryManagerImpl) getService().getDeclarativeQueryManager();
}

From source file:it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl.java

/**
 * Creates instances of information model interfaces (factory method). To
 * create an Organization, use this method as follows:
 * /*from   w  ww  . j  ava 2s .co  m*/
 * <pre>
 * Organization org = (Organization) lifeCycleMgr.createObject(LifeCycleManager.ORGANIZATION);
 * </pre>
 * <p>
 * <DL>
 * <DT><B>Capability Level: 0 </B>
 * </DL>
 * 
 * @param interfaceName
 *            the unqualified name of an interface in the
 *            javax.xml.registry.infomodel package
 * 
 * @return an Object that can then be cast to an instance of the interface
 * 
 * @throws JAXRException
 *             if the JAXR provider encounters an internal error
 * 
 * @throws InvalidRequestException
 *             if the interface is not an interface in the
 *             javax.xml.registry.infomodel package
 * 
 * @throws UnsupportedCapabilityException
 *             if the client attempts to create an instance of an infomodel
 *             interface that is not supported by the capability level of
 *             the JAXR provider
 */
public Object createObject(String className)
        throws JAXRException, InvalidRequestException, UnsupportedCapabilityException {
    Object obj = null;

    try {
        // Try to find extended constructor by nickname
        Constructor<?> cons = imFactory.getConstructor1Arg(className);
        if (cons != null) {
            // use extended constructor
            Object[] args = { this };
            obj = cons.newInstance(args);

            // set extended type
            String typeId = imFactory.getTypeName(className);
            BusinessQueryManagerImpl bqm = (BusinessQueryManagerImpl) regService.getBusinessQueryManager();
            Concept typeConcept = (Concept) bqm.getRegistryObject(typeId, LifeCycleManager.CONCEPT);
            if (obj instanceof Association) {
                ((Association) obj).setAssociationType(typeConcept);
            } else if (obj instanceof ExtrinsicObject) {
                ((ExtrinsicObjectImpl) obj).setObjectType(typeConcept);
            }
        } else {
            // proceed the default way: infomodel class
            className = "it.cnr.icar.eric.client.xml.registry.infomodel."
                    + BindingUtility.mapEbXMLNameToJAXRName(className) + "Impl";

            Class<?> cls = this.getClass().getClassLoader().loadClass(className);
            Class<?> lcmCls = this.getClass().getClassLoader()
                    .loadClass("it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl");
            @SuppressWarnings("rawtypes")
            Class[] parmTypes = { lcmCls };
            cons = cls.getDeclaredConstructor(parmTypes);

            Object[] args = { this };
            obj = cons.newInstance(args);
        }

    } catch (ClassNotFoundException e) {
        throw new InvalidRequestException(JAXRResourceBundle.getInstance()
                .getString("message.error.invalid.classname", new Object[] { className }));
    } catch (NoSuchMethodException e) {
        throw new JAXRException(e);
    } catch (InvocationTargetException e) {
        throw new JAXRException(e.getCause());
    } catch (IllegalAccessException e) {
        throw new JAXRException(e);
    } catch (InstantiationException e) {
        throw new JAXRException(e);
    } catch (ExceptionInInitializerError e) {
        throw new JAXRException(e);
    } catch (SecurityException e) {
        throw new JAXRException(e);
    }

    return obj;
}

From source file:it.cnr.icar.eric.common.BindingUtility.java

/**
 * Get the id from an object that could either an ObjectRef or RegistryObject
 *//*  w w w .ja v a  2s .  co m*/
public String getObjectId(Object obj) throws JAXRException {
    String id = null;

    if (obj != null) {
        if (obj instanceof ObjectRefType) {
            id = ((ObjectRefType) obj).getId();
        } else if (obj instanceof RegistryObjectType) {
            id = ((RegistryObjectType) obj).getId();
        } else if (obj instanceof String) {
            id = (String) obj;
        } else {
            throw new JAXRException(resourceBundle.getString("message.unexpectedObjectType", new String[] {
                    obj.getClass().toString(),
                    "java.lang.String, org.oasis.ebxml.registry.bindings.rim.ObjectRefType, org.oasis.ebxml.registry.bindings.rim.RegistryObjectType" }));
        }
    }

    return id;
}

From source file:it.cnr.icar.eric.common.BindingUtility.java

/**
 * Set the id for an object that could either an ObjectRef or RegistryObject
 *//*from   w  ww  .  j  av a 2 s .c  om*/
public void setObjectId(Object obj, String id) throws JAXRException {
    if (obj != null) {
        if (obj instanceof ObjectRefType) {
            ((ObjectRefType) obj).setId(id);
        } else if (obj instanceof RegistryObjectType) {
            ((RegistryObjectType) obj).setId(id);
        } else {
            throw new JAXRException(resourceBundle.getString("message.unexpectedObjectType", new String[] {
                    obj.getClass().toString(),
                    "org.oasis.ebxml.registry.bindings.rim.ObjectRefType, org.oasis.ebxml.registry.bindings.rim.RegistryObjectType" }));
        }
    }
}