Example usage for javax.xml.bind JAXB unmarshal

List of usage examples for javax.xml.bind JAXB unmarshal

Introduction

In this page you can find the example usage for javax.xml.bind JAXB unmarshal.

Prototype

public static <T> T unmarshal(Source xml, Class<T> type) 

Source Link

Document

Reads in a Java object tree from the given XML input.

Usage

From source file:org.apache.juddi.v3.tck.UDDI_160_RESTIntergrationTest.java

@Test
public void InquiryREST_GET_Business() throws Exception {
    Assume.assumeTrue(TckPublisher.isEnabled());
    Assume.assumeTrue(TckPublisher.isInquiryRestEnabled());
    FindBusiness fb = new FindBusiness();
    fb.setMaxRows(1);//  w ww .j a  v  a2 s .  c  om
    fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
    fb.setFindQualifiers(new FindQualifiers());
    fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
    BusinessList findBusiness = inquiry.findBusiness(fb);
    Assume.assumeTrue(findBusiness != null);
    Assume.assumeTrue(findBusiness.getBusinessInfos() != null);
    Assume.assumeTrue(!findBusiness.getBusinessInfos().getBusinessInfo().isEmpty());

    String url = manager.getClientConfig().getHomeNode().getInquiry_REST_Url();

    Assume.assumeNotNull(url);
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(
            url + "?businessKey=" + findBusiness.getBusinessInfos().getBusinessInfo().get(0).getBusinessKey());
    logger.info("Fetching " + httpGet.getURI());
    HttpResponse response = client.execute(httpGet);

    Assert.assertTrue(response.getStatusLine().getStatusCode() == 200);
    logger.info("Response content: " + response.getEntity().getContent());
    BusinessEntity unmarshal = JAXB.unmarshal(response.getEntity().getContent(), BusinessEntity.class);
    client.getConnectionManager().shutdown();
    Assert.assertNotNull(unmarshal);
    Assert.assertEquals(unmarshal.getBusinessKey(),
            findBusiness.getBusinessInfos().getBusinessInfo().get(0).getBusinessKey());

}

From source file:it.geosolutions.unredd.stats.model.config.ConfigTest.java

public void _testRunClassSmall() throws IOException {

    File file = ctx.getResource("classpath:classStatSmall.xml").getFile();
    assertNotNull("test file not found", file);

    StatisticConfiguration cfg = JAXB.unmarshal(file, StatisticConfiguration.class);
    assertNotNull("Error unmarshalling file", cfg);

    boolean check = StatisticChecker.check(cfg);
    assertTrue("Configuration is not valid", check);

    StatsRunner sr = new StatsRunner(cfg);
    sr.run();//from   w  w  w.  j a v a  2 s. c o m
}

From source file:com.hp.mercury.ci.jenkins.plugins.oo.core.OOAccessibilityLayer.java

public static OORunResponse run(OORunRequest request) throws IOException, URISyntaxException {

    String urlString = StringUtils.slashify(request.getServer().getUrl()) + REST_SERVICES_URL_PATH
            + RUN_OPERATION_URL_PATH + StringUtils.unslashifyPrefix(request.getFlow().getId());

    final URI uri = OOBuildStep.URI(urlString);
    final HttpPost httpPost = new HttpPost(uri);
    httpPost.setEntity(new JaxbEntity(request));
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml");
    //        if (OOBuildStep.getEncodedCredentials()!=null) {
    //            httpPost.addHeader("Authorization", "Basic " + new String(OOBuildStep.getEncodedCredentials()));
    //        }//w  w  w  . j a va 2 s  .c  o m

    HttpResponse response;

    response = client.execute(httpPost);
    final int statusCode = response.getStatusLine().getStatusCode();
    final HttpEntity entity = response.getEntity();

    try {
        if (statusCode == HttpStatus.SC_OK) {

            return JAXB.unmarshal(entity.getContent(), OORunResponse.class);

        } else {

            throw new RuntimeException("unable to get run result from " + uri + ", response code: " + statusCode
                    + "(" + HttpStatus.getStatusText(statusCode) + ")");
        }
    } finally {
        EntityUtils.consume(entity);
    }
}

From source file:com.vmware.vchs.publicapi.samples.HttpUtils.java

/**
 * This method will unmarshal the passed in entity using the passed in class type
 * //w  w  w .  ja va2  s  .com
 * @param entity
 *            the entity to unmarshal
 * @param clazz
 *            the class type to base the unmarshal from
 * @return unmarshal an instance of the provided class type
 */
public static <T> T unmarshal(HttpEntity entity, Class<T> clazz) {
    InputStream is = null;

    try {
        String s = EntityUtils.toString(entity);
        // Uncomment this to print out all the XML responses to the console, useful for
        // debugging
        //System.out.println(s);
        is = new ByteArrayInputStream(s.getBytes());
        return JAXB.unmarshal(is, clazz);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            if (null != is) {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:edu.cmu.cs.diamond.pathfind.DjangoAnnotationStore.java

@Override
public String getDescription(String quickhash1) throws IOException {
    String description = null;/*from   ww  w  .j a  v  a 2s .  c  om*/

    try {
        URI u = new URI(uriPrefix + quickhash1 + "/");
        System.out.println(u);

        GetMethod g = new GetMethod(u.toString());
        try {
            InputStream in = getBody(g);
            if (in != null) {
                RegionList rl = JAXB.unmarshal(in, RegionList.class);
                description = rl.getDescription();
            }
        } finally {
            g.releaseConnection();
        }
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }

    return description;
}

From source file:it.geosolutions.unredd.stats.model.config.ConfigTest.java

public void _testRunClassNormal() throws IOException {

    File file = ctx.getResource("classpath:classStat.xml").getFile();
    assertNotNull("test file not found", file);

    StatisticConfiguration cfg = JAXB.unmarshal(file, StatisticConfiguration.class);
    assertNotNull("Error unmarshalling file", cfg);

    boolean check = StatisticChecker.check(cfg);
    assertTrue("Configuration is not valid", check);

    StatsRunner sr = new StatsRunner(cfg);
    sr.run();//  w  ww  . ja  v  a  2  s.  co m
}

From source file:ch.puzzle.itc.mobiliar.business.shakedown.control.ShakedownTestRunner.java

/**
 * @param sts//w ww  .j a  va 2  s .  c o  m
 * @return
 */
public TestSet executeShakedownTest(STS sts) {
    TestSet resultSet;
    String strcsv = getStrCsv();
    ArrayList<Test> otherTests = new ArrayList<Test>();
    String bundle;
    try {
        bundle = bundleSTM(strcsv, sts.getShakedowntestsAsCSV(), sts);
        try {
            List<String> missingSTPs = copySTMtoRemoteServerAndGetMissingSTPs(bundle, sts);
            if (missingSTPs != null && !missingSTPs.isEmpty()) {
                for (String missingSTP : missingSTPs) {
                    try {
                        copySTPtoRemoteServer(missingSTP, sts);
                    } catch (ShakedownTestException e) {
                        Test t = new Test();
                        t.setName(missingSTP);
                        t.setTestStatus(OverallStatus.failed.name());
                        t.setStdErr(e.getMessage());
                        log.log(Level.WARNING, "Was not able to copy STP " + missingSTP + " to remote server",
                                e);
                        otherTests.add(t);
                    }
                }
            }
            try {
                launchTests(bundle, sts);
            } catch (ShakedownTestException e) {
                Test launchTestFailure = new Test();
                launchTestFailure.setName("General Test Execution");
                launchTestFailure.setTestStatus(OverallStatus.failed.name());
                launchTestFailure.setStdErr(e.getMessage());
                log.log(Level.WARNING, "General Test Execution failed", e);
                otherTests.add(launchTestFailure);
            }
        } catch (ShakedownTestException e1) {
            Test copySTMFailure = new Test();
            copySTMFailure.setName("General Test Execution");
            copySTMFailure.setTestStatus(OverallStatus.failed.name());
            copySTMFailure.setStdErr(e1.getMessage());
            log.log(Level.WARNING, "Was not able to copy STM to remote server", e1);
            otherTests.add(copySTMFailure);
        }

    } catch (ShakedownTestException e) {
        Test bundleFailure = new Test();
        bundleFailure.setName("General Test Execution");
        bundleFailure.setTestStatus(OverallStatus.failed.name());
        bundleFailure.setStdErr(e.getMessage());
        otherTests.add(bundleFailure);
        log.log(Level.WARNING, "Was not able to bundle STM", e);
    }
    String result = null;
    try {
        result = analyzeResult(sts);
    } catch (ShakedownTestException e) {
        Test resultAnalyzeFailure = new Test();
        resultAnalyzeFailure.setName("General Test Execution");
        resultAnalyzeFailure.setTestStatus(OverallStatus.failed.name());
        resultAnalyzeFailure.setStdErr(e.getMessage());
        otherTests.add(resultAnalyzeFailure);
        log.log(Level.WARNING, "Was not able to analyze results", e);
    }
    if (result != null) {
        resultSet = JAXB.unmarshal(new StringReader(result), TestSet.class);
    } else {
        resultSet = new TestSet();
    }
    if (resultSet.getTests() == null) {
        resultSet.setTests(otherTests);
    } else {
        resultSet.getTests().addAll(otherTests);
    }
    return resultSet;

}

From source file:com.fujitsu.dc.test.jersey.box.ServiceSchmaTest.java

() {

    TResponse res = Http.request("box/$metadata-$metadata-get.txt")
            .with("path", "\\$metadata\\?\\$format=atomsvc")
            .with("col", "setodata")
            .with("accept", "application/xml")
            .with("token", DcCoreConfig.getMasterToken())
            .returns()// w w w.j  a  v a  2 s  .c  om
            .statusCode(HttpStatus.SC_OK)
            .debug();

    // ???
    String str = res.getBody();

    Service service = JAXB.unmarshal(new StringReader(str), Service.class);

    Service rightService = new Service();
    rightService.workspace = new Workspace("Default",
            new HashSet<Collection>(Arrays.asList(new Collection("ComplexType", "ComplexType"),
                    new Collection("ComplexTypeProperty", "ComplexTypeProperty"),
                    new Collection("AssociationEnd", "AssociationEnd"),
                    new Collection("EntityType", "EntityType"),
                    new Collection("Property", "Property"))));
    assertTrue(rightService.isEqualTo(service));
}

From source file:io.personium.test.jersey.box.ServiceSchmaTest.java

() {

    TResponse res = Http.request("box/$metadata-$metadata-get.txt")
            .with("path", "\\$metadata\\?\\$format=atomsvc")
            .with("col", "setodata")
            .with("accept", "application/xml")
            .with("token", PersoniumUnitConfig.getMasterToken())
            .returns()//from w  w w. ja v a  2s. co  m
            .statusCode(HttpStatus.SC_OK)
            .debug();

    // ???
    String str = res.getBody();

    Service service = JAXB.unmarshal(new StringReader(str), Service.class);

    Service rightService = new Service();
    rightService.workspace = new Workspace("Default",
            new HashSet<Collection>(Arrays.asList(new Collection("ComplexType", "ComplexType"),
                    new Collection("ComplexTypeProperty", "ComplexTypeProperty"),
                    new Collection("AssociationEnd", "AssociationEnd"),
                    new Collection("EntityType", "EntityType"),
                    new Collection("Property", "Property"))));
    assertTrue(rightService.isEqualTo(service));
}

From source file:it.geosolutions.geobatch.destination.ingestion.gate.GateIngestionMemoryTest.java

/**
 * Check if the data inserted its correct
 * //from w  ww.j ava2s .co  m
 * @param ids of the inserted data
 * @param file used to execute the process
 * @throws Exception 
 */
private void checkData(List<Long> ids, File file) throws Exception {
    // the number of inserts it's OK
    assertEquals(ids.size(), (int) numberOrTransits);
    // check one by one
    int index = 0;
    ExportData exportedData = JAXB.unmarshal(file, ExportData.class);
    for (Transit transit : exportedData.getTransits().get(0).getTransit()) {
        checkData(ids.get(index++), transit);
    }
}