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.LifeCycleManagerImpl.java

/**
 * Create an object for the specified objectType Add to JAXR 2.0
 *///from   w w w. jav  a 2s . co  m
public Object createObject(Concept objectTypeConcept)
        throws JAXRException, InvalidRequestException, UnsupportedCapabilityException {

    Object obj = null;
    String path = objectTypeConcept.getPath();
    if (path == null) {
        throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.error.Concept.path.null",
                new Object[] { objectTypeConcept.getKey().getId() }));
    }
    if (path.startsWith("/" + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
            + "/RegistryObject/ExtrinsicObject")) {
        obj = createExtrinsicObject(objectTypeConcept);
    } else if (path.startsWith("" + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_AssociationType + "/")
            || path.startsWith("/" + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
                    + "/RegistryObject/Association")) {
        obj = createAssociation(objectTypeConcept);
    } else {
        String className = getJAXRClassNameFromObjectType(objectTypeConcept);
        obj = createObject(className);
    }

    return obj;
}

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

/**
 * Execute a query as specified by query and parameters paramater.
 *
 * <p><DL><DT><B>Capability Level: 0 (optional) </B></DL>
 *
 * @param query/*from www  .j  a  v  a 2s.  c  o  m*/
 *   A javax.xml.registry.Query object containing the query. This parameter
 *   is required.
 * @param queryParams
 *   A java.util.Map of query parameters. This parameter is optional.
 * @param iterativeParams
 *   A IterativeQueryParams instance that holds parameters used in making
 *   iterative queriesClientContext
 * @throws JAXRException
 *   This exception is thrown if there is a problem with a JAXB marshall,
 *   a problem with the Registry and other JAXR provider errors
 * @throws NullPointerException
 *   This is thrown if the query parameter is null
 */
@SuppressWarnings("static-access")
public BulkResponse executeQuery(ClientRequestContext context, Map<String, String> queryParams,
        IterativeQueryParams iterativeParams) throws JAXRException {
    try {
        AdhocQueryRequest ebAdhocQueryRequest = (AdhocQueryRequest) context.getCurrentRegistryRequest();
        Connection connection = ((RegistryServiceImpl) getRegistryService()).getConnection();
        JAXRUtility.addCreateSessionSlot(ebAdhocQueryRequest, connection);

        // If parameter Map is not null, set parameters on the AdhocQuery object as a
        // slot list
        if (queryParams != null) {
            ResponseOptionType responseOption = ebAdhocQueryRequest.getResponseOption();

            //Extract (remove) transient Slots from slotsMap if specified
            String responseOptionReturnComposedObjectSlotValue = queryParams
                    .remove(this.CANONICAL_SLOT_RESPONSEOPTION_RETURN_COMPOSED_OBJECTS);
            String responseOptionReturnTypeSlotValue = queryParams
                    .remove(this.CANONICAL_SLOT_RESPONSEOPTION_RETURN_TYPE);

            if (responseOptionReturnTypeSlotValue != null) {
                if (responseOptionReturnTypeSlotValue.equals("OBJECT_REF"))
                    responseOptionReturnTypeSlotValue = "ObjectRef";
                else if (responseOptionReturnTypeSlotValue.equals("REGISTRY_OBJECT"))
                    responseOptionReturnTypeSlotValue = "RegistryObject";
                else if (responseOptionReturnTypeSlotValue.equals("LEAF_CLASS"))
                    responseOptionReturnTypeSlotValue = "LeafClass";
                else if (responseOptionReturnTypeSlotValue.equals("LEAF_CLASS_WITH_REPOSITORY_ITEM"))
                    responseOptionReturnTypeSlotValue = "LeafClassWithRepositoryItem";

                ReturnType returnType = ReturnType.fromValue(responseOptionReturnTypeSlotValue);
                responseOption.setReturnType(returnType);
            }
            if (responseOptionReturnComposedObjectSlotValue != null) {
                boolean returnComposedObjects = Boolean.valueOf(responseOptionReturnComposedObjectSlotValue)
                        .booleanValue();
                responseOption.setReturnComposedObjects(returnComposedObjects);
            }

            bu.addSlotsToRequest(ebAdhocQueryRequest, queryParams);
        }
        // Add iterative query parameters to request
        ebAdhocQueryRequest.setStartIndex(new BigInteger(String.valueOf(iterativeParams.startIndex)));
        ebAdhocQueryRequest.setMaxResults(new BigInteger(String.valueOf(iterativeParams.maxResults)));

        AdhocQueryResponse ebAdhocQueryResponse = serverQMProxy.submitAdhocQuery(context);
        BulkResponse br = new BulkResponseImpl(lcm, ebAdhocQueryResponse, context.getRepositoryItemsMap());
        return br;
    } catch (JAXBException e) {
        throw new JAXRException(e);
    }
}

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

public CredentialInfo getCredentialInfo() throws JAXRException {

    // enable support for SAML v2 assertion
    if (assertion != null) {
        return new CredentialInfo(null, null, null, null, assertion);
    }/*from ww  w .  j av  a  2  s  .com*/

    // if no rea creds, but certificate was set, return it.
    if (x500Cred == null && x509Cert != null) {
        return new CredentialInfo(null, x509Cert, null, null, null);
    }

    if (x500Cred == null) {
        return null;
    }
    if (x500Cred.isDestroyed()) {
        throw new JAXRException(
                JAXRResourceBundle.getInstance().getString("message.error.credential.destroyed"));
    }

    X509Certificate cert = x500Cred.getCertificate();
    if (cert == null) {
        throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.error.no.X509Certificate"));
    }

    PrivateKey privateKey = x500Cred.getPrivateKey();
    if (privateKey == null) {
        throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.error.no.PrivateKey"));
    }

    Certificate[] certChain = su.getCertificateChain(cert);
    return new CredentialInfo(x500Cred.getAlias(), cert, certChain, privateKey, null);

}

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

/**
 * Gets the size in bytes of repositoryItem associated with this objects (if any). 
 *
 * Add to JAXR 2.0//from  w w  w . j a  va  2 s. co m
 *
 * @return if object has repositoryItem return its size in bytes.
 *  if object has no repositoryItem return 0
 */
public long getRepositoryItemSize() throws JAXRException {
    long size = 0;

    InputStream is = null;
    try {
        DataHandler dh = getRepositoryItem();

        if (dh != null) {
            is = dh.getInputStream();

            while (is.read() != -1) {
                size++;
            }
        }
    } catch (IOException e) {
        throw new JAXRException(e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (Exception e) {
            log.error(e, e);
        }
    }

    return size;
}

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

/**
 * This method is used to get the CallbackHandler from the bundled
 * properties file.  It reads the/*ww w  .  ja v  a2 s. c o m*/
 * jaxr-ebxml.security.jaas.callbackHandlerClassName property.
 * If this file or property does not exist, it defaults to
 * com.sun.xml.registry.client.jaas.DialogAuthenticationCallbackHandler.
 *
 * @return
 *  An instance of the CallbackHandler interface
 */
public CallbackHandler getCallbackHandler() throws JAXRException {
    log.trace("start getting CallbackHandler name");

    if (callbackHandler == null) {
        Properties properties = JAXRUtility.getBundledClientProperties();
        String callbackHandlerClassName = properties
                .getProperty(ROOT_PROPERTY_NAME + ".security.jaas.callbackHandlerClassName");

        // over ride with system properties. The system property is used
        // by the thick client. The file property is used by the thin client
        String callbackHandlerClassNameFromSystem = System
                .getProperty(ROOT_PROPERTY_NAME + ".security.jaas.callbackHandlerClassName");

        if (callbackHandlerClassNameFromSystem != null) {
            callbackHandlerClassName = callbackHandlerClassNameFromSystem;
        }

        if (callbackHandlerClassName != null) {
            Class<?> clazz = null;

            try {
                clazz = Class.forName(callbackHandlerClassName);
            } catch (ClassNotFoundException ex) {
                log.error(ex);
                throw new JAXRException(JAXRResourceBundle.getInstance().getString(
                        "message.error.not.instantiate.CallbackHandler",
                        new Object[] { callbackHandlerClassName }));
            }

            Class<?>[] clazzes = new Class[1];
            clazzes[0] = java.awt.Frame.class;

            Constructor<?> constructor = null;

            try {
                constructor = clazz.getDeclaredConstructor(clazzes);

                Object[] objs = new Object[1];
                Frame frame = getParentFrame();
                if (frame != null) {
                    objs[0] = frame;
                }
                callbackHandler = (CallbackHandler) constructor.newInstance(objs);
            } catch (NoSuchMethodException ex) {
                log.debug("Could not find constructor that takes a Frame "
                        + "parameter. Trying default constructor");

                // use default constructor instead
                try {
                    callbackHandler = (CallbackHandler) Class.forName(callbackHandlerClassName).newInstance();
                } catch (Throwable t) {
                    log.error(t);
                    throw new JAXRException(JAXRResourceBundle.getInstance().getString(
                            "message.error.not.instantiate.CallbackHandler.classpath",
                            new Object[] { callbackHandlerClassName }));
                }
            } catch (Throwable t) {
                log.error(t.getMessage());
                throw new JAXRException(JAXRResourceBundle.getInstance().getString(
                        "message.error.not.instantiate.CallbackHandler",
                        new Object[] { callbackHandlerClassName }));
            }
        }
        if (callbackHandler == null) {
            log.info(JAXRResourceBundle.getInstance().getString("message.UsingDefaultCallbackHandler"));

            // If set, user default CallbackHandler provided by user
            if (defaultCallbackHandler != null) {
                callbackHandler = defaultCallbackHandler;
            } else // Use default CallbackHandler that loads credentials
                   // from client-side keystore file.
            {
                callbackHandler = new ThinClientCallbackHandler();
            }
        }

        log.info(JAXRResourceBundle.getInstance().getString("message.CallbackHandlerName",
                new Object[] { callbackHandler.getClass().getName() }));
    }

    log.trace("finish getting CallbackHandler name");

    return callbackHandler;
}

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

public String getObjectTypeId(String rimClassName) throws JAXRException {
    String objectTypeId = null;/*w  w  w .  jav  a 2s .co  m*/

    try {
        Class<? extends BindingUtility> clazz = this.getClass();
        Field field = clazz.getField("CANONICAL_OBJECT_TYPE_ID_" + rimClassName);
        Object obj = field.get(this);
        objectTypeId = (String) obj;
    } catch (NoSuchFieldException e) {
        throw new JAXRException(e);
    } catch (SecurityException e) {
        throw new JAXRException(e);
    } catch (IllegalAccessException e) {
        throw new JAXRException(e);
    }

    return objectTypeId;
}

From source file:it.cnr.icar.eric.client.admin.function.AddUser.java

public void execute(AdminFunctionContext context, String args) throws Exception {
    this.context = context;

    if (context.getDebug()) {
        Iterator<String> paramNameIter = paramNames.keySet().iterator();

        while (paramNameIter.hasNext()) {
            String paramName = paramNameIter.next();
            context.printMessage(paramName + "=" + paramNames.get(paramName));
        }/*from  w  w  w.  java2 s.c o m*/
    }

    Properties userProps = new Properties();

    if (args == null) {
        context.printMessage(format(rb, "argumentRequired"));

        return;
    }

    String[] tokens = args.split("\\s+");

    boolean parsedOkay = parseArgs(tokens, userProps);

    if (!parsedOkay) {
        return;
    }

    if (useEditor) {
        userProps = editProperties(userProps);
    }

    ConnectionImpl connection = ((RegistryServiceImpl) (context.getService().getLCM().getRegistryService()))
            .getConnection();

    // Use Swing-client's model so can use model's validate() method.
    UserModel userModel = new UserModel(context.getService().getLCM().createUser());
    updateUserModel(userModel, userProps);

    userModel.validate();
    KeyModel userRegInfo = userModel.getUserRegistrationInfo();
    String alias = userRegInfo.getAlias();
    char[] keypass = userRegInfo.getKeyPassword();

    //Would have liked to have used RegistryFacade.registerUser() here to avoid code duplication but 
    //That would mean messing with existing admintool framework. Defer that for now.
    //Instead copy paste code for now from RegistryFacade.registerUser()
    try {
        //Do equivalent of RegistryFacade.logoff()
        connection.logoff();

        userRegInfo.setAlias(alias);
        userRegInfo.setKeyPassword(keypass);
        char[] storepass = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storepass")
                .toCharArray();
        if (!CertificateUtil.certificateExists(alias, storepass)) {
            CertificateUtil.generateRegistryIssuedCertificate(userRegInfo);
        }

        //Do equivalent of RegistryFacaqde.logon() using new cert first
        HashSet<X500PrivateCredential> creds = new HashSet<X500PrivateCredential>();
        @SuppressWarnings("unused")
        String str = keypass.toString();
        creds.add(SecurityUtil.getInstance().aliasToX500PrivateCredential(alias, new String(keypass)));
        connection.setCredentials(creds);

        // Now save the User
        ArrayList<User> objects = new ArrayList<User>();
        objects.add(userRegInfo.getUser());
        ((BusinessLifeCycleManagerImpl) (context.getService().getLCM())).saveObjects(objects,
                dontVersionSlotsMap);
    } catch (Exception e) {
        // Remove the self-signed certificate from the keystore, if one
        // was created during the self-registration process
        try {
            if (alias != null) {
                CertificateUtil.removeCertificate(alias, userRegInfo.getStorePassword());
            }
        } catch (Exception removeCertException) {
            log.warn(removeCertException);
        }

        if (e instanceof JAXRException) {
            throw (JAXRException) e;
        } else {
            throw new JAXRException(e);
        }
    } finally {
        File tmpFile = new File(userRegInfo.getP12File());
        if (tmpFile.exists()) {
            tmpFile.delete();
        }
    }
}

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

/**
 * Publishes a repositoryItem and the metadata that describes it.    
 *
 * @param repositoryItem the URL to the repositoryItem being published.
 * @param metadata describing the repositoryItem
 *
 * @return the ExtrinsicObject published as metadata.
 * @see it.cnr.icar.eric.common.CanonicalConstants for constants that may be used to identify keys in metadaat HashMap 
 *///from  w  w  w  .  j a va 2  s . com
@SuppressWarnings("static-access")
public ExtrinsicObject publish(URL repositoryItem, Map<?, ?> metadata) throws JAXRException {
    ExtrinsicObjectImpl eo = null;

    if (lcm == null) {
        throw new JAXRException("setEndpoint MUST be called before setCredentials is called.");
    }

    javax.activation.DataSource ds = new javax.activation.URLDataSource(repositoryItem);
    javax.activation.DataHandler dh = new javax.activation.DataHandler(ds);

    eo = (ExtrinsicObjectImpl) lcm.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);
    String mimeType = (String) metadata.remove(bu.CANONICAL_SLOT_EXTRINSIC_OBJECT_MIMETYPE);

    //If id is specified then use it.
    if (id != null) {
        eo.setKey(lcm.createKey(id));
        eo.setLid(id);
    }

    @SuppressWarnings("unused")
    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 }));
    }

    if (mimeType == null) {
        throw new InvalidRequestException(JAXRResourceBundle.getInstance().getString(
                "message.error.missingMetadata", new Object[] { bu.CANONICAL_SLOT_EXTRINSIC_OBJECT_MIMETYPE }));
    }

    eo.setMimeType(mimeType);
    eo.setObjectTypeRef(new RegistryObjectRef(lcm, objectType));

    //Set any remaining metadata properties as Slots
    JAXRUtility.addSlotsToRegistryObject(eo, metadata);

    ArrayList<RegistryObject> objects = new ArrayList<RegistryObject>();
    objects.add(eo);

    BulkResponse br = lcm.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.");
    }

    return eo;
}

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

private void loadRegistryObjectsRegistryPackage(RegistryObjectNode parentNode) throws JAXRException {
    if (roPkg == null) {
        // TODO: load into db using minDB target
        String localizedROsLabel = WebUIResourceBundle.getInstance().getString("registryObjects");
        try {//w w  w  .  ja  v a  2  s . com
            roPkg = RegistryBrowser.getBLCM().createRegistryPackage(localizedROsLabel);

            Key key = RegistryBrowser.getBLCM()
                    .createKey("urn:oasis:names:tc:ebxml-regrep:RegistryPackage:RegistryObject");
            (roPkg).setKey(key);

        } catch (Exception ex) {
            throw new JAXRException(ex);
        }

    }
    Concept roClassNode = null;
    try {
        roClassNode = (Concept) RegistryBrowser.getDQM().getRegistryObject(
                "urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject", "ClassificationNode");
    } catch (Exception ex) {
        throw new JAXRException(ex);
    }
    RegistryObjectNode childNode = new RegistryObjectNode(roPkg, roClassNode);
    childNode.setHasChild(true);
    parentNode.addChild(childNode);
}

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

private void loadClassificationSchemesRegistryPackage(RegistryObjectNode parentNode) throws JAXRException {
    if (csPkg == null) {
        // TODO: load into db using minDB target?
        String localizedCSLabel = WebUIResourceBundle.getInstance().getString("ClassificationSchemes");
        try {/*from  w  w w.ja  v a  2  s. c  om*/
            csPkg = RegistryBrowser.getBLCM().createRegistryPackage(localizedCSLabel);

            Key key = RegistryBrowser.getBLCM()
                    .createKey("urn:oasis:names:tc:ebxml-regrep:RegistryPackage:ClassificationSchemes");
            (csPkg).setKey(key);
        } catch (Exception ex) {
            throw new JAXRException(ex);
        }
    }
    RegistryObjectNode childNode = new RegistryObjectNode(csPkg);
    childNode.setHasChild(true);
    parentNode.addChild(childNode);
    if (childNode.getPath().equalsIgnoreCase(pathOfSelectedNode)) {
        childNode.setSelected(true);
    }
}