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:org.openrepose.common.auth.ResponseUnmarshaller.java

public <T> T unmarshall(final InputStream data, final Class<T> expectedType) throws AuthServiceException {
    Object rtn = null;//from   w  ww. j  a v  a2  s  . co m
    Unmarshaller pooledObject;
    try {
        pooledObject = objectPool.borrowObject();
        try {
            final Object unmarshalledObject = pooledObject.unmarshal(new InputStreamReader(data, "UTF8"));
            if (unmarshalledObject instanceof JAXBElement) {
                rtn = ((JAXBElement) unmarshalledObject).getValue();
            } else {
                rtn = unmarshalledObject;
            }
        } catch (UnsupportedEncodingException e) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            LOG.error("Error reading Response stream in Response Unmarshaller", e);
        } catch (JAXBException jaxbe) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            throw new AuthServiceException(
                    "Failed to unmarshall response body. Body output is in debug. Reason: "
                            + jaxbe.getMessage(),
                    jaxbe);
        } catch (Exception e) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            LOG.error("Error reading Response stream in Response Unmarshaller", e);
        } finally {
            if (pooledObject != null) {
                objectPool.returnObject(pooledObject);
            }
        }
    } catch (AuthServiceException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Error obtaining Response Unmarshaller", e);
    }
    if (!expectedType.isInstance(rtn)) {
        throw new AuthServiceException(
                "Failed to unmarshall response body. Unexpected element encountered. Body output is in debug.");
    }
    return expectedType.cast(rtn);
}

From source file:org.openrepose.commons.utils.transform.jaxb.AbstractJaxbTransform.java

public AbstractJaxbTransform(JAXBContext ctx) {
    jaxbContext = ctx;//from   ww w  .j  av  a  2 s .c  om

    marshallerPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Marshaller>() {
        @Override
        public Marshaller makeObject() {
            try {
                return jaxbContext.createMarshaller();
            } catch (JAXBException jaxbe) {
                throw new ResourceConstructionException(jaxbe.getMessage(), jaxbe);
            }
        }
    });

    unmarshallerPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Unmarshaller>() {
        @Override
        public Unmarshaller makeObject() {
            try {
                return jaxbContext.createUnmarshaller();
            } catch (JAXBException jaxbe) {
                throw new ResourceConstructionException(jaxbe.getMessage(), jaxbe);
            }
        }
    });
}

From source file:org.openrepose.commons.utils.transform.jaxb.JaxbEntityToXml.java

@Override
public String transform(final JAXBElement source) {
    String rtn = null;//from  w w w . j  a  v  a 2  s.  com
    Marshaller pooledObject;
    final ObjectPool<Marshaller> objectPool = getMarshallerPool();
    try {
        pooledObject = objectPool.borrowObject();
        try {
            final StringWriter w = new StringWriter();
            pooledObject.marshal(source, w);
            rtn = w.getBuffer().toString();
        } catch (JAXBException jaxbe) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            throw new ResourceConstructionException(jaxbe.getMessage(), jaxbe);
        } catch (Exception e) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            LOG.error("Failed to utilize the Marshaller. Reason: {}", e.getLocalizedMessage());
            LOG.trace("", e);
        } finally {
            if (pooledObject != null) {
                objectPool.returnObject(pooledObject);
            }
        }
    } catch (ResourceConstructionException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to obtain a Marshaller. Reason: {}", e.getLocalizedMessage());
        LOG.trace("", e);
    }
    return rtn;
}

From source file:org.openrepose.commons.utils.transform.jaxb.JaxbToStreamTransform.java

@Override
public void transform(final JAXBElement source, final T target) {
    Marshaller pooledObject;/*w ww  .  j a va  2s.c om*/
    final ObjectPool<Marshaller> objectPool = getMarshallerPool();
    try {
        pooledObject = objectPool.borrowObject();
        try {
            pooledObject.marshal(source, target);
        } catch (JAXBException jaxbe) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            throw new ResourceContextException(jaxbe.getMessage(), jaxbe);
        } catch (Exception e) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            LOG.error("Failed to utilize the Marshaller. Reason: {}", e.getLocalizedMessage());
            LOG.trace("", e);
        } finally {
            if (pooledObject != null) {
                objectPool.returnObject(pooledObject);
            }
        }
    } catch (ResourceContextException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to obtain a Marshaller. Reason: {}", e.getLocalizedMessage());
        LOG.trace("", e);
    }
}

From source file:org.openrepose.commons.utils.transform.jaxb.StreamToJaxbTransform.java

@Override
public JAXBElement<T> transform(final InputStream source) {
    JAXBElement<T> rtn = null;
    Unmarshaller pooledObject;//from  w w w  .  java 2s. c  o m
    final ObjectPool<Unmarshaller> objectPool = getUnmarshallerPool();
    try {
        pooledObject = objectPool.borrowObject();
        try {
            rtn = (JAXBElement<T>) pooledObject.unmarshal(source);
        } catch (JAXBException jbe) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            throw new ResourceContextException(jbe.getMessage(), jbe);
        } catch (Exception e) {
            objectPool.invalidateObject(pooledObject);
            pooledObject = null;
            LOG.error("Failed to utilize the Marshaller. Reason: {}", e.getLocalizedMessage());
            LOG.trace("", e);
        } finally {
            if (pooledObject != null) {
                objectPool.returnObject(pooledObject);
            }
        }
    } catch (ResourceContextException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to obtain a Marshaller. Reason: {}", e.getLocalizedMessage());
        LOG.trace("", e);
    }
    return rtn;
}

From source file:org.phenotips.xliff12.XLIFFResourceBundleControl.java

/**
 * Hidden default constructor, to prevent initialization. Use {@link #INSTANCE} to access an instance of this
 * resouce bundle loading controller./*from ww w  .j  a  v a 2s . c  o  m*/
 */
private XLIFFResourceBundleControl() {
    try {
        this.jaxbContext = JAXBContext.newInstance(Xliff.class);
    } catch (JAXBException ex) {
        LOGGER.error("Failed to initialize JAXB: {}", ex.getMessage(), ex);
    }
}

From source file:org.plasma.platform.sdo.DynamicSDOModelTest.java

private void processModel(Query query, final String targetNamespaceURI, String prefix, File loadFile)
        throws Exception {

    validate(query, prefix);//from   ww w.  ja  v a 2s . co  m

    ProvisioningModelAssembler stagingAssembler = new ProvisioningModelAssembler(query, targetNamespaceURI,
            "ex");
    Model model = stagingAssembler.getModel();
    ProvisioningModelDataBinding binding = new ProvisioningModelDataBinding(
            new DefaultValidationEventHandler());
    OutputStream provos = new FileOutputStream(new File(targetDir, prefix + "-provisioning.xml"));
    binding.marshal(model, provos);
    provos.flush();
    provos.close();

    SchemaModelAssembler xsdAssembler = new SchemaModelAssembler(model, targetNamespaceURI, "ex");
    xsdAssembler.setCreateNonContainmentReferenceTypes(true);
    OutputStream provXsdos = new FileOutputStream(new File(targetDir, prefix + "-provisioning.xsd"));
    try {
        SchemaDataBinding xsdBinding = new SchemaDataBinding(new DefaultValidationEventHandler());
        xsdBinding.marshal(xsdAssembler.getSchema(), provXsdos);
    } catch (JAXBException e) {
        log.error(e.getMessage(), e);
        throw new PlasmaRuntimeException(e);
    } catch (SAXException e) {
        log.error(e.getMessage(), e);
        throw new PlasmaRuntimeException(e);
    } finally {
        provXsdos.flush();
        provXsdos.close();
    }

    log.info("generating query XSD");
    File schemaFile = new File(targetDir, prefix + ".xsd");
    OutputStream xsdos = new FileOutputStream(schemaFile);
    PlasmaXSDHelper.INSTANCE.generate(query, targetNamespaceURI, "ex", null, xsdos);
    xsdos.flush();
    xsdos.close();

    log.info("generating query XMI");
    OutputStream xmios = new FileOutputStream(new File(targetDir, prefix + ".mdxml"));
    UMLModelAssembler assembler = new UMLModelAssembler(query, targetNamespaceURI, "tns");
    XMLOutputter outputer = new XMLOutputter();
    outputer.getFormat().setIndent("    ");
    outputer.output(assembler.getDocument(), xmios);
    xmios.flush();
    xmios.close();

    // if not loaded via config, define on the fly
    log.info("defining XSD so new export-specific types are known");
    FileInputStream xsdis = new FileInputStream(new File(targetDir, prefix + "-provisioning.xsd"));
    PlasmaXSDHelper.INSTANCE.define(xsdis, targetDir);

    log.info("loading data");
    DefaultOptions options = new DefaultOptions(targetNamespaceURI);
    options.setRootNamespacePrefix("xyz");
    options.setValidate(true);
    options.setFailOnValidationError(false);

    InputStream xmlloadis = new FileInputStream(loadFile);
    XMLDocument doc = PlasmaXMLHelper.INSTANCE.load(xmlloadis, schemaFile.toURI().toString(), options);
    doc.setSchemaLocation(options.getRootElementNamespaceURI() + " " + prefix + ".xsd");
    DataFixUpVisitor fixUp = new DataFixUpVisitor();
    ((PlasmaDataObject) doc.getRootObject()).accept(fixUp);
    //log.info(((PlasmaDataObject)doc.getRootObject()).dump());

    File loadOutFile = new File(targetDir,
            loadFile.getName().substring(0, loadFile.getName().indexOf(".")) + "-save.xml");
    OutputStream loadOutos = new FileOutputStream(loadOutFile);
    PlasmaXMLHelper.INSTANCE.save(doc, loadOutos, options);
    loadOutos.flush();
    loadOutos.close();

    // now reload what we just saved/generated
    options.setValidate(true);
    xmlloadis = new FileInputStream(loadOutFile);
    doc = PlasmaXMLHelper.INSTANCE.load(xmlloadis, schemaFile.toURI().toString(), options);
    log.info(((PlasmaDataObject) doc.getRootObject()).dump());

    //PlasmaDataGraphVisitor visitor = new DataFixUpVisitor();
    //((PlasmaDataGraph)doc.getRootObject().getDataGraph()).accept(visitor);

    // Note; what is not being addressed here is that part of a graph
    // may be "reference/lookup" data. In which case if the
    // lookup data is already populated, we'll bomb
    log.info("commiting...");
    service.commit(doc.getRootObject().getDataGraph(), "me");

    log.info("executing query");
    //query.getFromClause().getEntity().setNamespaceURI(targetNamespaceURI);
    DataGraph[] results = service.find(query);
    log.info("processing " + results.length + " results");
    /*        
            for (int i = 0; i < results.length; i++) {
               PlasmaDataObject dataObject = (PlasmaDataObject)results[i].getRootObject();
               Long id = dataObject.getLong("seqId");
               File file = new File(targetDir, 
          prefix + "-" + String.valueOf(id) + ".xml");
               log.info("writing file " + file.getName());
    OutputStream xmlos = new FileOutputStream(file);
    PlasmaXMLHelper.INSTANCE.save(dataObject, 
          targetNamespaceURI, null, xmlos);        
    xmlos.flush();
    xmlos.close();
            } 
                     
            // FIXME: getting circular reference error here 
            for (int i = 0; i < results.length; i++) {
               results[i].getRootObject().delete();
    service.commit(results[i], "me");       
            }
                    
            // FIXME getting java.lang.IllegalArgumentException: found unexpected DELETED 
            //data-object (42ac2509-2bc3-4800-b69f-2237dc3ddc2f) of 
            // type http://plasma.org/test/sdo/export/taxonomy#Category
                    
            log.info(((PlasmaDataObject)doc.getRootObject()).dump());
            log.info("commiting delete...");
            log.info(doc.getRootObject().getDataGraph().getChangeSummary().toString());
            doc.getRootObject().delete();
            service.commit(doc.getRootObject().getDataGraph(), "me");       
                    
    */
}

From source file:org.plasma.platform.sdo.DynamicSDOModelTest.java

private void validate(Query query, String prefix) {
    try {//from  w w w  .  j  a va  2  s.  c o  m
        PlasmaQueryDataBinding binding = new PlasmaQueryDataBinding(new DefaultValidationEventHandler());
        log.info("marshaling query: " + query.getName());
        OutputStream qryos = new FileOutputStream(new File(targetDir, prefix + "-query.xml"));
        binding.marshal(query, qryos);
        qryos.flush();
        qryos.close();
        String xml = binding.marshal(query);
        query = (Query) binding.validate(xml);
        log.info("validated marshaled query: " + query.getName());
    } catch (JAXBException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    } catch (SAXException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }

}

From source file:org.plasma.platform.sdo.ProfileTest.java

public void testProfileQuery() throws Exception {
    log.info("testProfileQuery()");

    int num = 1;/*from www.j a  va 2s . com*/
    long before = System.currentTimeMillis();

    Query query = ProfileQuery.createProfileQuery("skippy");
    try {
        PlasmaQueryDataBinding binding = new PlasmaQueryDataBinding(new DefaultValidationEventHandler());
        String xml = binding.marshal(query.getModel());
        log.info("query: " + xml);
        query = (Query) binding.validate(xml);
    } catch (JAXBException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (SAXException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    }

    DataGraph[] results = service.find(query);
    for (int i = 0; i < results.length; i++) {
        PlasmaDataObject dataObject = (PlasmaDataObject) results[i].getRootObject();
        log.info(dataObject.dump());
    }
    long after = System.currentTimeMillis();
    float totalSeconds = (after - before) / 1000;
    float averageSecondsPerGraph = ((float) (after - before) / num) / 1000;
    log.info("total seconds: " + totalSeconds + " average seconds per graph: " + averageSecondsPerGraph);
}

From source file:org.plasma.provisioning.cli.XSDTool.java

private static void writeSchemaStagingModel(Model stagingModel, String location, String fileName) {
    try {/*w ww . j a va2s . com*/
        BindingValidationEventHandler debugHandler = new BindingValidationEventHandler() {
            public int getErrorCount() {
                return 0;
            }

            public boolean handleEvent(ValidationEvent ve) {
                ValidationEventLocator vel = ve.getLocator();

                String message = "Line:Col:Offset[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + ":"
                        + String.valueOf(vel.getOffset()) + "] - " + ve.getMessage();

                switch (ve.getSeverity()) {
                default:
                    //log.debug(message);
                }
                return true;
            }
        };
        ProvisioningModelDataBinding binding = new ProvisioningModelDataBinding(debugHandler);
        String xml = binding.marshal(stagingModel);
        binding.validate(xml);

        File provDebugFile = null;
        if (location != null)
            provDebugFile = new File(location, fileName);
        else
            provDebugFile = File.createTempFile(fileName, "");
        FileOutputStream provDebugos = new FileOutputStream(provDebugFile);
        log.debug("Writing provisioning model to: " + provDebugFile.getAbsolutePath());
        binding.marshal(stagingModel, provDebugos);
    } catch (JAXBException e) {
        log.debug(e.getMessage(), e);
    } catch (SAXException e) {
        log.debug(e.getMessage(), e);
    } catch (IOException e) {
        log.debug(e.getMessage(), e);
    }

}