use of javax.xml.bind.Unmarshaller in project camel by apache.
the class DefaultBulkApiClient method unmarshalResponse.
private <T> T unmarshalResponse(InputStream response, Request request, Class<T> resultClass) throws SalesforceException {
try {
Unmarshaller unmarshaller = context.createUnmarshaller();
JAXBElement<T> result = unmarshaller.unmarshal(new StreamSource(response), resultClass);
return result.getValue();
} catch (JAXBException e) {
throw new SalesforceException(String.format("Error unmarshaling response {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
} catch (IllegalArgumentException e) {
throw new SalesforceException(String.format("Error unmarshaling response for {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
}
}
use of javax.xml.bind.Unmarshaller in project camel by apache.
the class RouteInfoCommand method executeOnRoute.
@Override
public void executeOnRoute(CamelController camelController, String contextName, String routeId, PrintStream out, PrintStream err) throws Exception {
out.println(stringEscape.unescapeJava("[1mCamel Route " + routeId + "[0m"));
out.println(stringEscape.unescapeJava("\tCamel Context: " + contextName));
String xml = camelController.getRouteStatsAsXml(routeId, contextName, true, false);
if (xml != null) {
JAXBContext context = JAXBContext.newInstance(RouteStatDump.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
RouteStatDump route = (RouteStatDump) unmarshaller.unmarshal(new StringReader(xml));
out.println(stringEscape.unescapeJava("\tState: " + route.getState()));
out.println(stringEscape.unescapeJava("\tState: " + route.getState()));
out.println("");
out.println("");
out.println(stringEscape.unescapeJava("[1mStatistics[0m"));
long total = route.getExchangesCompleted() + route.getExchangesFailed();
out.println(stringEscape.unescapeJava("\tExchanges Total: " + total));
out.println(stringEscape.unescapeJava("\tExchanges Completed: " + route.getExchangesCompleted()));
out.println(stringEscape.unescapeJava("\tExchanges Failed: " + route.getExchangesFailed()));
out.println(stringEscape.unescapeJava("\tExchanges Inflight: " + route.getExchangesInflight()));
out.println(stringEscape.unescapeJava("\tMin Processing Time: " + route.getMinProcessingTime() + " ms"));
out.println(stringEscape.unescapeJava("\tMax Processing Time: " + route.getMaxProcessingTime() + " ms"));
out.println(stringEscape.unescapeJava("\tMean Processing Time: " + route.getMeanProcessingTime() + " ms"));
out.println(stringEscape.unescapeJava("\tTotal Processing Time: " + route.getTotalProcessingTime() + " ms"));
out.println(stringEscape.unescapeJava("\tLast Processing Time: " + route.getLastProcessingTime() + " ms"));
out.println(stringEscape.unescapeJava("\tDelta Processing Time: " + route.getDeltaProcessingTime() + " ms"));
if (isEmpty(route.getStartTimestamp())) {
// Print an empty value for scripting
out.println(stringEscape.unescapeJava("\tStart Statistics Date:"));
} else {
Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getStartTimestamp());
String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
out.println(stringEscape.unescapeJava("\tStart Statistics Date: " + text));
}
// Test for null to see if a any exchanges have been processed first to avoid NPE
if (isEmpty(route.getResetTimestamp())) {
// Print an empty value for scripting
out.println(stringEscape.unescapeJava("\tReset Statistics Date:"));
} else {
Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getResetTimestamp());
String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
out.println(stringEscape.unescapeJava("\tReset Statistics Date: " + text));
}
// Test for null to see if a any exchanges have been processed first to avoid NPE
if (isEmpty(route.getFirstExchangeCompletedTimestamp())) {
// Print an empty value for scripting
out.println(stringEscape.unescapeJava("\tFirst Exchange Date:"));
} else {
Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getFirstExchangeCompletedTimestamp());
String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
out.println(stringEscape.unescapeJava("\tFirst Exchange Date: " + text));
}
// Test for null to see if a any exchanges have been processed first to avoid NPE
if (isEmpty(route.getLastExchangeCompletedTimestamp())) {
// Print an empty value for scripting
out.println(stringEscape.unescapeJava("\tLast Exchange Date:"));
} else {
Date date = new SimpleDateFormat(XML_TIMESTAMP_FORMAT).parse(route.getLastExchangeCompletedTimestamp());
String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
out.println(stringEscape.unescapeJava("\tLast Exchange Date: " + text));
}
}
}
use of javax.xml.bind.Unmarshaller in project midpoint by Evolveum.
the class ModelClientUtil method unmarshallResource.
public static <O> O unmarshallResource(String path) throws JAXBException, FileNotFoundException {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
InputStream is = null;
JAXBElement<O> element = null;
try {
is = ModelClientUtil.class.getClassLoader().getResourceAsStream(path);
if (is == null) {
throw new FileNotFoundException("System resource " + path + " was not found");
}
element = (JAXBElement<O>) unmarshaller.unmarshal(is);
} finally {
if (is != null) {
IOUtils.closeQuietly(is);
}
}
if (element == null) {
return null;
}
return element.getValue();
}
use of javax.xml.bind.Unmarshaller in project midpoint by Evolveum.
the class DescriptorLoader method loadData.
public void loadData(MidPointApplication application) {
LOGGER.debug("Loading data from descriptor files.");
try (InputStream baseInput = application.getServletContext().getResourceAsStream(baseFileName);
InputStream customInput = application.getServletContext().getResourceAsStream(customFileName)) {
if (baseInput == null) {
LOGGER.error("Couldn't find " + baseFileName + " file, can't load application menu and other stuff.");
}
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
JAXBElement<DescriptorType> element = (JAXBElement) unmarshaller.unmarshal(baseInput);
DescriptorType descriptor = element.getValue();
LOGGER.debug("Loading menu bar from " + baseFileName + " .");
DescriptorType customDescriptor = null;
if (customInput != null) {
element = (JAXBElement) unmarshaller.unmarshal(customInput);
customDescriptor = element.getValue();
}
scanPackagesForPages(descriptor.getPackagesToScan(), application);
if (customDescriptor != null) {
scanPackagesForPages(customDescriptor.getPackagesToScan(), application);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("loaded:\n{}", debugDump(1));
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't process application descriptor", ex);
}
}
use of javax.xml.bind.Unmarshaller in project jdk8u_jdk by JetBrains.
the class UnmarshalTest method unmarshalUnexpectedNsTest.
@Test
public void unmarshalUnexpectedNsTest() throws Exception {
JAXBContext context;
Unmarshaller unm;
// Create JAXB context from testTypes package
context = JAXBContext.newInstance("testTypes");
// Create unmarshaller from JAXB context
unm = context.createUnmarshaller();
// Unmarshall xml document with unqualified dtime element
Root r = (Root) unm.unmarshal(new InputSource(new StringReader(DOC)));
// Print dtime value and check if it is null
System.out.println("dtime is:" + r.getWhen().getDtime());
assertNull(r.getWhen().getDtime());
}
Aggregations