use of javax.xml.bind.Unmarshaller in project camel by apache.
the class LinkedInExceptionResponseFilter method filter.
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
if (responseContext.getStatus() != Response.Status.OK.getStatusCode() && responseContext.hasEntity()) {
try {
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
final Error error = (Error) unmarshaller.unmarshal(responseContext.getEntityStream());
final Response.ResponseBuilder builder = Response.status(responseContext.getStatusInfo());
builder.entity(error);
// copy response headers
for (Map.Entry<String, List<String>> header : responseContext.getHeaders().entrySet()) {
builder.header(header.getKey(), header.getValue());
}
throw new LinkedInException(error, builder.build());
} catch (JAXBException e) {
// log and ignore
LOG.warn("Unable to parse LinkedIn error: " + e.getMessage(), e);
}
}
}
use of javax.xml.bind.Unmarshaller in project hbase by apache.
the class TestTableScan method testReversed.
@Test
public void testReversed() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aay");
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
Unmarshaller ush = ctx.createUnmarshaller();
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(24, count);
List<RowModel> rowModels = model.getRows().subList(1, count);
//reversed
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_START_ROW + "=aay");
builder.append("&");
builder.append(Constants.SCAN_END_ROW + "=aaa");
builder.append("&");
builder.append(Constants.SCAN_REVERSED + "=true");
response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
model = (CellSetModel) ush.unmarshal(response.getStream());
count = TestScannerResource.countCellSet(model);
assertEquals(24, count);
List<RowModel> reversedRowModels = model.getRows().subList(1, count);
Collections.reverse(reversedRowModels);
assertEquals(rowModels.size(), reversedRowModels.size());
for (int i = 0; i < rowModels.size(); i++) {
RowModel rowModel = rowModels.get(i);
RowModel reversedRowModel = reversedRowModels.get(i);
assertEquals(new String(rowModel.getKey(), "UTF-8"), new String(reversedRowModel.getKey(), "UTF-8"));
assertEquals(new String(rowModel.getCells().get(0).getValue(), "UTF-8"), new String(reversedRowModel.getCells().get(0).getValue(), "UTF-8"));
}
}
use of javax.xml.bind.Unmarshaller in project hbase by apache.
the class TestTableScan method testCompoundFilter.
@Test
public void testCompoundFilter() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder = new StringBuilder();
builder.append("/*");
builder.append("?");
builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("PrefixFilter('abc') AND QualifierFilter(=,'binary:1')", "UTF-8"));
Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
Unmarshaller ush = ctx.createUnmarshaller();
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
assertEquals(1, count);
assertEquals("abc", new String(model.getRows().get(0).getCells().get(0).getValue()));
}
use of javax.xml.bind.Unmarshaller in project buck by facebook.
the class FatJar method load.
/**
* @return the {@link FatJar} object deserialized from the resource name via {@code loader}.
*/
public static FatJar load(ClassLoader loader) throws XMLStreamException, JAXBException, IOException {
InputStream inputStream = loader.getResourceAsStream(FAT_JAR_INFO_RESOURCE);
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
try {
XMLEventReader xmlEventReader = XMLInputFactory.newFactory().createXMLEventReader(bufferedInputStream);
JAXBContext context = JAXBContext.newInstance(FatJar.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
JAXBElement<FatJar> jaxbElementA = unmarshaller.unmarshal(xmlEventReader, FatJar.class);
return jaxbElementA.getValue();
} finally {
bufferedInputStream.close();
}
} finally {
inputStream.close();
}
}
use of javax.xml.bind.Unmarshaller in project malmo by Microsoft.
the class SchemaHelper method deserialiseObject.
/** Attempt to construct the specified object from this XML string
* @param xml the XML string to parse
* @param xsdFile the name of the XSD schema that defines the object
* @param objclass the class of the object requested
* @return if successful, an instance of class objclass that captures the data in the XML string
*/
public static Object deserialiseObject(String xml, String xsdFile, Class<?> objclass) throws JAXBException, SAXException, XMLStreamException {
Object obj = null;
JAXBContext jaxbContext = getJAXBContext(objclass);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final String schemaResourceFilename = new String(xsdFile);
URL schemaURL = MalmoMod.class.getClassLoader().getResource(schemaResourceFilename);
Schema schema = schemaFactory.newSchema(schemaURL);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setSchema(schema);
StringReader stringReader = new StringReader(xml);
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader XMLreader = xif.createXMLStreamReader(stringReader);
obj = jaxbUnmarshaller.unmarshal(XMLreader);
return obj;
}
Aggregations