Search in sources :

Example 6 with JAXBContext

use of javax.xml.bind.JAXBContext in project hadoop by apache.

the class TestRMWebServicesDelegationTokenAuthentication method getMarshalledAppInfo.

static String getMarshalledAppInfo(ApplicationSubmissionContextInfo appInfo) throws Exception {
    StringWriter writer = new StringWriter();
    JAXBContext context = JAXBContext.newInstance(ApplicationSubmissionContextInfo.class);
    Marshaller m = context.createMarshaller();
    m.marshal(appInfo, writer);
    return writer.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext)

Example 7 with JAXBContext

use of javax.xml.bind.JAXBContext 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"));
    }
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) JAXBContext(javax.xml.bind.JAXBContext) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 8 with JAXBContext

use of javax.xml.bind.JAXBContext 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()));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 9 with JAXBContext

use of javax.xml.bind.JAXBContext 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();
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) XMLEventReader(javax.xml.stream.XMLEventReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 10 with JAXBContext

use of javax.xml.bind.JAXBContext 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;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) Schema(javax.xml.validation.Schema) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) MalmoMod(com.microsoft.Malmo.MalmoMod) URL(java.net.URL) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)442 Unmarshaller (javax.xml.bind.Unmarshaller)240 Marshaller (javax.xml.bind.Marshaller)129 JAXBException (javax.xml.bind.JAXBException)128 Test (org.junit.Test)92 InputStream (java.io.InputStream)84 File (java.io.File)50 StringWriter (java.io.StringWriter)47 BaseTest (org.orcid.core.BaseTest)39 V2Convertible (org.orcid.core.version.V2Convertible)39 StringReader (java.io.StringReader)27 IOException (java.io.IOException)26 InputSource (org.xml.sax.InputSource)21 ArrayList (java.util.ArrayList)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)19 JAXBElement (javax.xml.bind.JAXBElement)19 FileOutputStream (java.io.FileOutputStream)18 Schema (javax.xml.validation.Schema)18 SchemaFactory (javax.xml.validation.SchemaFactory)17 SAXSource (javax.xml.transform.sax.SAXSource)14