Example usage for javax.xml.bind JAXBException getMessage

List of usage examples for javax.xml.bind JAXBException getMessage

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java

private OVFWrapper parse(String ovfXml) throws DRPOneException {
    OVFWrapper rv = null;//from  w  w w .j a va2 s.  c  om
    StringBuilder cause = new StringBuilder();

    try {
        rv = OVFWrapperFactory.parse(ovfXml);
    } catch (JAXBException e) {
        if (e instanceof PropertyException) {
            cause.append("Access to property failed: " + e.getErrorCode());
        } else if (e instanceof MarshalException) {
            cause.append("Marshalling failed: " + e.getLocalizedMessage());
        } else if (e instanceof UnmarshalException) {
            cause.append("Unmarshalling failed: " + e.getCause());
        } else if (e instanceof ValidationException) {
            cause.append("XML Validation failed: " + e.getErrorCode());
        } else {
            cause.append("Unespected " + e.getErrorCode());
            cause.append(e.getClass().getName());
            cause.append(": ");
        }

        cause.append(e.getMessage());
        log.error(cause.toString());
        if (log.isTraceEnabled()) {
            log.trace(cause, e);
        }
        throw new DRPOneException(cause.toString(), e, StatusCodes.XML_PROBLEM);
    } catch (OVFException e) {
        cause.append("Problems parsing OVF file: ");
        cause.append(e.getMessage());
        log.error(cause.toString());
        if (log.isTraceEnabled()) {
            log.trace(cause, e);
        }
        throw new DRPOneException(cause.toString(), e, StatusCodes.XML_PROBLEM);
    }
    return rv;
}

From source file:telecom.sudparis.eu.paas.core.server.ressources.manager.application.ApplicationManagerRessource.java

/**
 * {@inheritDoc}//from w  w  w  . j  ava 2s  . co  m
 */
@Override
public Response createApplication(String cloudApplicationDescriptor) {
    try {
        copyDeployedApps2Pool();
        if (cloudApplicationDescriptor != null && !cloudApplicationDescriptor.equals("")) {
            InputStream is = new ByteArrayInputStream(cloudApplicationDescriptor.getBytes());
            JAXBContext jaxbContext;
            PaasApplicationManifestType manifest = new PaasApplicationManifestType();
            try {
                jaxbContext = JAXBContext.newInstance("telecom.sudparis.eu.paas.core.server.xml.manifest");
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

                JAXBElement<PaasApplicationManifestType> root = jaxbUnmarshaller.unmarshal(new StreamSource(is),
                        PaasApplicationManifestType.class);
                manifest = root.getValue();

            } catch (JAXBException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // create the application object
            ApplicationType app = new ApplicationType();
            // retrieve appName
            String appName = manifest.getPaasApplication().getName();
            app.setAppName(appName);

            // retrieve app description

            String description = manifest.getPaasApplication().getDescription().toString();
            app.setDescription(description);

            // retrieve uris
            // List<String> uris = new ArrayList<String>();
            // uris.add(appName + "." + HOST_NAME);
            UrisType uris = new UrisType();
            uris.getUri().add(appName + "." + HOST_NAME);
            app.setUris(uris);

            // generate appID
            Long id = getNextId();
            app.setAppId((int) (long) id);

            // retrieve deployableName
            String deployableName = manifest.getPaasApplication().getPaasApplicationVersion()
                    .getPaasApplicationDeployable().getName();

            // retrieve deployableType
            String deployableType = manifest.getPaasApplication().getPaasApplicationVersion()
                    .getPaasApplicationDeployable().getContentType();

            // retrieve deployableDirectory or deployableId
            String deployableId = null;
            String deployableDirectory = manifest.getPaasApplication().getPaasApplicationVersion()
                    .getPaasApplicationDeployable().getLocation();
            // if the deployable is already in the DB we provide it's ID
            DeployableType dep = new DeployableType();
            if (!(deployableDirectory.contains("/") || deployableDirectory.contains("\\"))) {
                dep.setDeployableId(deployableDirectory);
            }
            // Define the deployable element
            else {

                dep.setDeployableDirectory(deployableDirectory);

            }
            dep.setDeployableName(deployableName);
            dep.setDeployableType(deployableType);
            app.setDeployable(dep);
            // retrieve ApplicationVersionInstance Names and number
            List<PaasApplicationVersionInstanceType> listOfInstances = manifest.getPaasApplication()
                    .getPaasApplicationVersion().getPaasApplicationVersionInstance();
            InstancesType listVI = new InstancesType();
            int nbInstances = 0;

            if (listOfInstances != null && listOfInstances.size() > 0)
                for (PaasApplicationVersionInstanceType p : listOfInstances) {
                    if (p != null) {
                        InstanceType vi = new InstanceType();
                        vi.setInstanceName(p.getName());
                        listVI.getInstance().add(vi);
                        nbInstances++;
                    }
                }

            // Update the Application object with the
            // Adequate LinkList
            LinksListType linksList = new LinksListType();
            linksList = ApplicationLinkGenerator.addDescribeAppLink(linksList, id.toString(), apiUrl);
            linksList = ApplicationLinkGenerator.addCreateAppLink(linksList, apiUrl);
            linksList = ApplicationLinkGenerator.addDestroyAppLink(linksList, id.toString(), apiUrl);
            linksList = ApplicationLinkGenerator.addFindAppsLink(linksList, apiUrl);
            linksList = ApplicationLinkGenerator.addUpdateAppLink(linksList, id.toString(), apiUrl);
            app.setLinksList(linksList);
            app.setInstances(listVI);
            app.setNbInstances(nbInstances);
            // app.setCheckExists(CHECK_EXISTS);
            app.setStatus("CREATED");

            ApplicationPool.INSTANCE.add(app);

            return Response.status(Response.Status.OK).entity(new GenericEntity<ApplicationType>(app) {
            }).type(MediaType.APPLICATION_XML_TYPE).build();
        } else {
            System.out.println("Failed to retrieve the cloud Application Descriptor");
            error.setValue("Failed to retrieve the cloud Application Descriptor.");
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
        }
    } catch (Exception e) {
        System.out.println("Failed to create the application: " + e.getMessage());
        e.printStackTrace();
        error.setValue("Failed to create the application: " + e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error)
                .type(MediaType.APPLICATION_XML_TYPE).build();
    }
}

From source file:nl.openweb.jcr.Importer.java

public Node createNodesFromXml(InputStream inputStream, String path, String intermediateNodeType) {
    try {//  ww w  . j  a v  a2  s .c o  m
        validate(inputStream);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Object unmarshaled = unmarshaller.unmarshal(inputStream);
        if (unmarshaled instanceof NodeBean) {
            return createNodeFromNodeBean(NodeBeanUtils.nodeBeanToMap((NodeBean) unmarshaled), path,
                    intermediateNodeType);
        } else {
            throw new JcrImporterException("The given XML file is not of the right format");
        }
    } catch (JAXBException e) {
        throw new JcrImporterException(e.getMessage(), e);
    }
}

From source file:org.alfresco.repo.publishing.JaxbHttpMessageConverter.java

/**
 * Creates a new {@link Marshaller} for the given class.
 * // w w w. ja  va  2  s.  com
 * @param clazz
 *            the class to create the marshaller for
 * @return the {@code Marshaller}
 * @throws HttpMessageConversionException
 *             in case of JAXB errors
 */
protected final Marshaller createMarshaller(Class<?> clazz) {
    try {
        JAXBContext jaxbContext = getJaxbContext(clazz);
        return jaxbContext.createMarshaller();
    } catch (JAXBException ex) {
        throw new HttpMessageConversionException(
                "Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
    }
}

From source file:org.alfresco.repo.publishing.JaxbHttpMessageConverter.java

/**
 * Creates a new {@link Unmarshaller} for the given class.
 * /* w ww.  j  a  va  2s.c  o m*/
 * @param clazz
 *            the class to create the unmarshaller for
 * @return the {@code Unmarshaller}
 * @throws HttpMessageConversionException
 *             in case of JAXB errors
 */
protected final Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException {
    try {
        JAXBContext jaxbContext = getJaxbContext(clazz);
        return jaxbContext.createUnmarshaller();
    } catch (JAXBException ex) {
        throw new HttpMessageConversionException(
                "Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
    }
}

From source file:org.alfresco.repo.publishing.JaxbHttpMessageConverter.java

/**
 * Returns a {@link JAXBContext} for the given class.
 * /*from ww w .j a  va 2 s  . c o m*/
 * @param clazz
 *            the class to return the context for
 * @return the {@code JAXBContext}
 * @throws HttpMessageConversionException
 *             in case of JAXB errors
 */
protected final JAXBContext getJaxbContext(Class<?> clazz) {
    Assert.notNull(clazz, "'clazz' must not be null");
    JAXBContext result = null;
    if (defaultJaxbContext != null) {
        result = defaultJaxbContext;
    } else {
        result = jaxbContexts.get(clazz);
        if (result == null) {
            try {
                result = JAXBContext.newInstance(clazz);
                jaxbContexts.putIfAbsent(clazz, result);
            } catch (JAXBException ex) {
                throw new HttpMessageConversionException(
                        "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex);
            }
        }
    }
    return result;
}

From source file:org.apache.axis2.jaxws.message.databinding.impl.JAXBBlockFactoryImpl.java

public Block createFrom(OMElement omElement, Object context, QName qName)
        throws XMLStreamException, WebServiceException {
    // The context for a JAXBFactory must be non-null and should be a JAXBBlockContext.
    if (context == null) {
        // JAXWS spec 4.3.4 conformance requires a WebServiceException whose cause is JAXBException
        throw ExceptionFactory.makeWebServiceException(
                new JAXBException(Messages.getMessage("JAXBBlockFactoryErr1", "null")));
    } else if (context instanceof JAXBBlockContext) {
        ;/*from   w ww  .j ava 2 s .c om*/
    } else {
        // JAXWS spec 4.3.4 conformance requires a WebServiceException whose cause is JAXBException
        throw ExceptionFactory.makeWebServiceException(
                new JAXBException(Messages.getMessage("JAXBBlockFactoryErr1", context.getClass().getName())));
    }
    if (qName == null) {
        qName = omElement.getQName();
    }

    if (omElement instanceof OMSourcedElement) {

        if (((OMSourcedElement) omElement).getDataSource() instanceof JAXBDataSource) {
            JAXBDataSource ds = (JAXBDataSource) ((OMSourcedElement) omElement).getDataSource();
            JAXBDSContext dsContext = ds.getContext();
            try {
                if (dsContext.getJAXBContext() == ((JAXBBlockContext) context).getJAXBContext()) {
                    // Shortcut, use existing JAXB object
                    Object jaxb = ds.getObject();
                    return new JAXBBlockImpl(jaxb, (JAXBBlockContext) context, qName, this);
                }
            } catch (JAXBException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Falling back to using normal unmarshalling approach. " + e.getMessage());
                }
            }
        } else if (((OMSourcedElement) omElement).getDataSource() instanceof JAXBBlockImpl) {
            JAXBBlockImpl block = (JAXBBlockImpl) ((OMSourcedElement) omElement).getDataSource();
            JAXBBlockContext blockContext = (JAXBBlockContext) block.getBusinessContext();
            try {
                if (blockContext.getJAXBContext() == ((JAXBBlockContext) context).getJAXBContext()) {
                    // Shortcut, use existing JAXB object
                    Object jaxb = block.getObject();
                    return new JAXBBlockImpl(jaxb, (JAXBBlockContext) context, qName, this);
                }
            } catch (JAXBException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Falling back to using normal unmarshalling approach. " + e.getMessage());
                }
            }
        }
    }

    return new JAXBBlockImpl(omElement, (JAXBBlockContext) context, qName, this);
}

From source file:org.apache.cxf.jaxbplus.io.DataWriterImpl.java

public Marshaller createMarshaller(Object elValue, MessagePartInfo part) {
    Class<?> cls = null;/*from   w w w .  j  a v  a  2 s .c  o m*/
    if (part != null) {
        cls = part.getTypeClass();
    }

    if (cls == null) {
        cls = null != elValue ? elValue.getClass() : null;
    }

    if (cls != null && cls.isArray() && elValue instanceof Collection) {
        Collection<?> col = (Collection<?>) elValue;
        elValue = col.toArray((Object[]) Array.newInstance(cls.getComponentType(), col.size()));
    }
    Marshaller marshaller;
    try {

        marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        marshaller.setListener(databinding.getMarshallerListener());
        if (databinding.getValidationEventHandler() != null) {
            marshaller.setEventHandler(databinding.getValidationEventHandler());
        }

        final Map<String, String> nspref = databinding.getDeclaredNamespaceMappings();
        if (nspref != null) {
            JAXBUtils.setNamespaceWrapper(nspref, marshaller);
        }
        if (databinding.getMarshallerProperties() != null) {
            for (Map.Entry<String, Object> propEntry : databinding.getMarshallerProperties().entrySet()) {
                try {
                    marshaller.setProperty(propEntry.getKey(), propEntry.getValue());
                } catch (PropertyException pe) {
                    LOG.log(Level.INFO, "PropertyException setting Marshaller properties", pe);
                }
            }
        }

        marshaller.setSchema(schema);
        AttachmentMarshaller atmarsh = getAttachmentMarshaller();
        marshaller.setAttachmentMarshaller(atmarsh);

        if (schema != null && atmarsh instanceof JAXBAttachmentMarshaller) {
            //we need a special even handler for XOP attachments 
            marshaller.setEventHandler(new MtomValidationHandler(marshaller.getEventHandler(),
                    (JAXBAttachmentMarshaller) atmarsh));
        }
    } catch (JAXBException ex) {
        if (ex instanceof javax.xml.bind.MarshalException) {
            javax.xml.bind.MarshalException marshalEx = (javax.xml.bind.MarshalException) ex;
            Message faultMessage = new Message("MARSHAL_ERROR", LOG,
                    marshalEx.getLinkedException().getMessage());
            throw new Fault(faultMessage, ex);
        } else {
            throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
        }
    }
    return marshaller;
}

From source file:org.apache.juddi.config.Install.java

protected static void install(Configuration config)
        throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException {

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();

    UddiEntityPublisher rootPublisher = null;

    try {// w ww.j  ava  2  s  . c om
        tx.begin();
        boolean seedAlways = config.getBoolean("juddi.seed.always", false);
        boolean alreadyInstalled = alreadyInstalled(config);
        if (!seedAlways && alreadyInstalled)
            new FatalErrorException(new ErrorMessage("errors.install.AlreadyInstalled"));

        String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
        String fileRootTModelKeygen = rootPublisherStr + FILE_TMODELKEYGEN;
        TModel rootTModelKeyGen = (TModel) buildInstallEntity(fileRootTModelKeygen, "org.uddi.api_v3", config);
        String fileRootBusinessEntity = rootPublisherStr + FILE_BUSINESSENTITY;
        org.uddi.api_v3.BusinessEntity rootBusinessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity(
                fileRootBusinessEntity, "org.uddi.api_v3", config);

        String rootPartition = getRootPartition(rootTModelKeyGen);
        String nodeId = getNodeId(rootBusinessEntity.getBusinessKey(), rootPartition);

        String fileRootPublisher = rootPublisherStr + FILE_PUBLISHER;
        if (!alreadyInstalled) {
            log.info("Loading the root Publisher from file " + fileRootPublisher);

            rootPublisher = installPublisher(em, fileRootPublisher, config);
            installRootPublisherKeyGen(em, rootTModelKeyGen, rootPartition, rootPublisher, nodeId);
            rootBusinessEntity.setBusinessKey(nodeId);
            installBusinessEntity(true, em, rootBusinessEntity, rootPublisher, rootPartition, config);
        } else {
            log.debug("juddi.seed.always reapplies all seed files except for the root data.");
        }

        List<String> juddiPublishers = getPublishers(config);
        for (String publisherStr : juddiPublishers) {
            String filePublisher = publisherStr + FILE_PUBLISHER;
            String fileTModelKeygen = publisherStr + FILE_TMODELKEYGEN;
            TModel tModelKeyGen = (TModel) buildInstallEntity(fileTModelKeygen, "org.uddi.api_v3", config);
            String fileBusinessEntity = publisherStr + FILE_BUSINESSENTITY;
            org.uddi.api_v3.BusinessEntity businessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity(
                    fileBusinessEntity, "org.uddi.api_v3", config);
            UddiEntityPublisher publisher = installPublisher(em, filePublisher, config);
            if (publisher == null) {
                throw new ConfigurationException("File " + filePublisher + " not found.");
            } else {
                if (tModelKeyGen != null)
                    installPublisherKeyGen(em, tModelKeyGen, publisher, nodeId);
                if (businessEntity != null)
                    installBusinessEntity(false, em, businessEntity, publisher, null, config);
                String fileTModels = publisherStr + FILE_TMODELS;
                installSaveTModel(em, fileTModels, publisher, nodeId, config);
            }
        }

        tx.commit();
    } catch (DispositionReportFaultMessage dr) {
        log.error(dr.getMessage(), dr);
        tx.rollback();
        throw dr;
    } catch (JAXBException je) {
        log.error(je.getMessage(), je);
        tx.rollback();
        throw je;
    } catch (IOException ie) {
        log.error(ie.getMessage(), ie);
        tx.rollback();
        throw ie;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

From source file:org.apache.juddi.jaxb.JAXBMarshaller.java

public static String marshallToString(Object object, String thePackage) {
    String rawObject = null;//from  w ww.j  a v a  2  s .  c  o m

    try {
        JAXBContext jc = getContext(thePackage);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        marshaller.marshal(object, baos);
        rawObject = baos.toString();
    } catch (JAXBException e) {
        logger.error(e.getMessage(), e);
    }

    return rawObject;
}