List of usage examples for javax.xml.bind JAXB unmarshal
public static <T> T unmarshal(Source xml, Class<T> type)
From source file:org.opennms.web.rest.v1.GroupRestServiceIT.java
@Test public void testCategories() throws Exception { createGroup("testGroup"); String xml = sendRequest(GET, "/groups/testGroup/categories", 200); assertNotNull(xml);//from www . j ava2s .c o m OnmsCategoryCollection categories = JAXB.unmarshal(new StringReader(xml), OnmsCategoryCollection.class); assertNotNull(categories); assertTrue(categories.getCategories().isEmpty()); // add category to group sendRequest(PUT, "/groups/testGroup/categories/testCategory", 400); // fails, because Category is not there createCategory("testCategory"); // create category sendRequest(PUT, "/groups/testGroup/categories/testCategory", 204); // should not fail, because Category is now there xml = sendRequest(GET, "/groups/testGroup/categories/testCategory", 200); // get data assertNotNull(xml); OnmsCategory category = JAXB.unmarshal(new StringReader(xml), OnmsCategory.class); assertNotNull(category); assertEquals("testCategory", category.getName()); // add again (fails) sendRequest(PUT, "/groups/testGroup/categories/testCategory", 400); // should fail, because Category is already there // remove category from group sendRequest(DELETE, "/groups/testGroup/categories/testCategory", 204); // should not fail sendRequest(DELETE, "/groups/testGroup/categories/testCategory", 400); // should fail, because category is already removed // test that all categories for group "testGroup" have been removed xml = sendRequest(GET, "/groups/testGroup/categories", 200); assertNotNull(xml); categories = JaxbUtils.unmarshal(OnmsCategoryCollection.class, xml); assertNotNull(categories); assertTrue(categories.getCategories().isEmpty()); }
From source file:org.perfrepo.client.PerfRepoClient.java
/** * Get test by id./* w w w . j a v a2 s.c o m*/ * * @param id * @return The test * @throws Exception */ public Test getTest(Long id) throws Exception { HttpGet get = createBasicGet("test/id/%s", id); HttpResponse resp = httpClient.execute(get); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Test obj = JAXB.unmarshal(resp.getEntity().getContent(), Test.class); EntityUtils.consume(resp.getEntity()); return obj; } else if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { EntityUtils.consume(resp.getEntity()); return null; } else { logHttpError("Error while getting test", get, resp); EntityUtils.consume(resp.getEntity()); return null; } }
From source file:org.perfrepo.client.PerfRepoClient.java
/** * Get test by uid.//from www.j ava 2 s . co m * * @param uid * @return The test * @throws Exception */ public Test getTestByUid(String uid) throws Exception { HttpGet get = createBasicGet("test/uid/%s", uid); HttpResponse resp = httpClient.execute(get); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Test obj = JAXB.unmarshal(resp.getEntity().getContent(), Test.class); EntityUtils.consume(resp.getEntity()); return obj; } else if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { EntityUtils.consume(resp.getEntity()); return null; } else { logHttpError("Error while getting test", get, resp); EntityUtils.consume(resp.getEntity()); return null; } }
From source file:org.perfrepo.client.PerfRepoClient.java
/** * Get test execution by id.//w ww . j av a2 s.c o m * * @param id * @return Test execution * @throws Exception */ public TestExecution getTestExecution(Long id) throws Exception { HttpGet get = createBasicGet("testExecution/%s", id); HttpResponse resp = httpClient.execute(get); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { TestExecution obj = JAXB.unmarshal(resp.getEntity().getContent(), TestExecution.class); EntityUtils.consume(resp.getEntity()); return obj; } else if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { EntityUtils.consume(resp.getEntity()); return null; } else { logHttpError("Error while getting test execution", get, resp); EntityUtils.consume(resp.getEntity()); return null; } }
From source file:org.perfrepo.client.PerfRepoClient.java
/** * Get report by id./*from w w w.j a v a2s . co m*/ * * @param id * @return The report * @throws Exception */ public Report getReport(Long id) throws Exception { HttpGet get = createBasicGet("report/id/%s", id); HttpResponse resp = httpClient.execute(get); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Report obj = JAXB.unmarshal(resp.getEntity().getContent(), Report.class); EntityUtils.consume(resp.getEntity()); return obj; } else if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { EntityUtils.consume(resp.getEntity()); return null; } else { logHttpError("Error while getting report.", get, resp); EntityUtils.consume(resp.getEntity()); return null; } }
From source file:sernet.verinice.service.sync.VeriniceArchive.java
@Override public Risk getSyncRiskAnalysis() { if (isRiskAnalysis() && riskData == null) { riskData = JAXB.unmarshal(new ByteArrayInputStream(getRiskAnalysisXml()), Risk.class); }//from w w w . j a va 2s.c om return riskData; }