List of usage examples for org.apache.http.entity ContentType APPLICATION_XML
ContentType APPLICATION_XML
To view the source code for org.apache.http.entity ContentType APPLICATION_XML.
Click Source Link
From source file:org.wuspba.ctams.ws.ITJudgeController.java
private static void add(Judge j) throws Exception { CTAMSDocument doc = new CTAMSDocument(); doc.getPeople().add(j.getPerson());//from www. j a va 2 s . co m doc.getJudgeQualifications().addAll(j.getQualifications()); doc.getJudges().add(j); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); j.setId(doc.getJudges().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:de.dtag.tlabs.cbclient.CBClient.java
/** * Is called by the polling Timer/* ww w . ja v a 2s . c o m*/ */ private void performPolling() { HttpHost targetHost = new HttpHost(contextBrokerIPAddr, contextBrokerPort, "http"); HttpClientContext context = HttpClientContext.create(); // HttpGetWithEntity httpGet = new HttpGetWithEntity(contextBrokerRequestLine); //httpGet.setHeader("Content-Type", "application/xml"); HttpPost httpPostContext = new HttpPost(contextBrokerRequestLine); String getXMLInfo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<queryContextRequest>" + "<entityIdList>" + "<entityId type=\"User_Context\" isPattern=\"false\">" + "<id>User1</id>" + "</entityId>" + "</entityIdList>" + "<attributeList/>" + "</queryContextRequest>"; StringEntity getEntity = new StringEntity(getXMLInfo, ContentType.APPLICATION_XML); httpPostContext.setEntity(getEntity); try { CloseableHttpResponse response = httpClient.execute(targetHost, httpPostContext, context); HttpEntity entity = response.getEntity(); // System.out.println("Response: " + response.getStatusLine().toString()); // System.out.println("Response Body-Type: " + entity.getContentType()); StringWriter writer = new StringWriter(); InputStream is = entity.getContent(); IOUtils.copy(is, writer); String responseContent = writer.toString(); System.out.println(responseContent); checkForHandOver(responseContent); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.wuspba.ctams.ws.ITSoloResultController.java
private static void add() throws Exception { ITSoloContestController.add();/* www. j a v a2 s .c o m*/ CTAMSDocument doc = new CTAMSDocument(); doc.getPeople().add(TestFixture.INSTANCE.elaine); doc.getVenues().add(TestFixture.INSTANCE.venue); doc.getJudges().add(TestFixture.INSTANCE.judgeAndy); doc.getJudges().add(TestFixture.INSTANCE.judgeJamie); doc.getJudges().add(TestFixture.INSTANCE.judgeBob); doc.getResults().add(TestFixture.INSTANCE.result5); doc.getSoloContests().add(TestFixture.INSTANCE.soloContest); doc.getSoloContestResults().add(TestFixture.INSTANCE.soloResult); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.soloResult.setId(doc.getSoloContestResults().get(0).getId()); for (Result r : doc.getSoloContestResults().get(0).getResults()) { if (r.getPoints() == TestFixture.INSTANCE.result1.getPoints()) { TestFixture.INSTANCE.result1.setId(r.getId()); } else if (r.getPoints() == TestFixture.INSTANCE.result2.getPoints()) { TestFixture.INSTANCE.result2.setId(r.getId()); } else if (r.getPoints() == TestFixture.INSTANCE.result3.getPoints()) { TestFixture.INSTANCE.result3.setId(r.getId()); } else if (r.getPoints() == TestFixture.INSTANCE.result4.getPoints()) { TestFixture.INSTANCE.result4.setId(r.getId()); } else if (r.getPoints() == TestFixture.INSTANCE.result5.getPoints()) { TestFixture.INSTANCE.result5.setId(r.getId()); } } EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:com.cloud.network.brocade.BrocadeVcsApi.java
protected <T> boolean executeUpdateObject(T newObject, String uri) throws BrocadeVcsApiException { boolean result = true; if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) {//from w ww .j a v a 2 s.com throw new BrocadeVcsApiException("Hostname/credentials are null or empty"); } HttpPatch pm = (HttpPatch) createMethod("patch", uri); pm.setHeader("Accept", "application/vnd.configuration.resource+xml"); pm.setEntity(new StringEntity(convertToString(newObject), ContentType.APPLICATION_XML)); HttpResponse response = executeMethod(pm); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage; try { errorMessage = responseToErrorMessage(response); } catch (IOException e) { s_logger.error("Failed to update object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to update object : " + e.getMessage()); } pm.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new BrocadeVcsApiException("Failed to update object : " + errorMessage); } pm.releaseConnection(); return result; }
From source file:org.wuspba.ctams.ws.ITBandController.java
private static void add(Band band) throws Exception { CTAMSDocument doc = new CTAMSDocument(); doc.getBands().add(band);//from w w w . j a v a 2 s . c o m String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.skye.setId(doc.getBands().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:org.wuspba.ctams.ws.ITBandContestController.java
protected static void add() throws Exception { ITVenueController.add();/*www. j av a2 s . co m*/ ITJudgeController.add(); ITHiredJudgeController.add(); CTAMSDocument doc = new CTAMSDocument(); doc.getVenues().add(TestFixture.INSTANCE.venue); doc.getJudges().add(TestFixture.INSTANCE.judgeAndy); doc.getJudges().add(TestFixture.INSTANCE.judgeJamie); doc.getJudges().add(TestFixture.INSTANCE.judgeBob); doc.getJudges().add(TestFixture.INSTANCE.judgeEoin); doc.getBandContests().add(TestFixture.INSTANCE.bandContest); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(ITVenueController.PATH) .build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.bandContest.setId(doc.getBandContests().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(ITJudgeController.PATH) .build(); httpPost = new HttpPost(uri); xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); httpPost = new HttpPost(uri); xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.bandContest.setId(doc.getBandContests().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:org.wuspba.ctams.ws.ITBandResultController.java
private static void add() throws Exception { ITBandController.add();/*from w w w .java2 s .c o m*/ ITBandContestController.add(); CTAMSDocument doc = new CTAMSDocument(); doc.getBands().add(TestFixture.INSTANCE.skye); doc.getVenues().add(TestFixture.INSTANCE.venue); doc.getJudges().add(TestFixture.INSTANCE.judgeAndy); doc.getJudges().add(TestFixture.INSTANCE.judgeJamie); doc.getJudges().add(TestFixture.INSTANCE.judgeBob); doc.getJudges().add(TestFixture.INSTANCE.judgeEoin); doc.getResults().add(TestFixture.INSTANCE.result1); doc.getResults().add(TestFixture.INSTANCE.result2); doc.getResults().add(TestFixture.INSTANCE.result3); doc.getResults().add(TestFixture.INSTANCE.result4); doc.getBandContests().add(TestFixture.INSTANCE.bandContest); doc.getBandContestResults().add(TestFixture.INSTANCE.bandResult); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.bandResult.setId(doc.getBandContestResults().get(0).getId()); for (Result r : doc.getBandContestResults().get(0).getResults()) { if (r.getPoints() == TestFixture.INSTANCE.result1.getPoints()) { TestFixture.INSTANCE.result1.setId(r.getId()); } else if (r.getPoints() == TestFixture.INSTANCE.result2.getPoints()) { TestFixture.INSTANCE.result2.setId(r.getId()); } else if (r.getPoints() == TestFixture.INSTANCE.result3.getPoints()) { TestFixture.INSTANCE.result3.setId(r.getId()); } else if (r.getPoints() == TestFixture.INSTANCE.result4.getPoints()) { TestFixture.INSTANCE.result4.setId(r.getId()); } } EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:com.cloud.network.brocade.BrocadeVcsApi.java
protected <T> boolean executeCreateObject(T newObject, String uri) throws BrocadeVcsApiException { if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) {// w w w.j av a2s . com throw new BrocadeVcsApiException("Hostname/credentials are null or empty"); } boolean result = true; HttpPost pm = (HttpPost) createMethod("post", uri); pm.setHeader("Accept", "application/vnd.configuration.resource+xml"); pm.setEntity(new StringEntity(convertToString(newObject), ContentType.APPLICATION_XML)); HttpResponse response = executeMethod(pm); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) { String errorMessage; try { errorMessage = responseToErrorMessage(response); } catch (IOException e) { s_logger.error("Failed to create object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to create object : " + e.getMessage()); } pm.releaseConnection(); s_logger.error("Failed to create object : " + errorMessage); throw new BrocadeVcsApiException("Failed to create object : " + errorMessage); } pm.releaseConnection(); return result; }
From source file:org.wuspba.ctams.ws.ITSoloContestController.java
protected static void add() throws Exception { ITVenueController.add();//from w w w.j av a 2 s . c om ITHiredJudgeController.add(); ITJudgeController.add(); CTAMSDocument doc = new CTAMSDocument(); doc.getVenues().add(TestFixture.INSTANCE.venue); doc.getPeople().add(TestFixture.INSTANCE.andy); doc.getPeople().add(TestFixture.INSTANCE.jamie); doc.getPeople().add(TestFixture.INSTANCE.bob); doc.getPeople().add(TestFixture.INSTANCE.eoin); doc.getJudges().add(TestFixture.INSTANCE.judgeAndy); doc.getJudges().add(TestFixture.INSTANCE.judgeJamie); doc.getJudges().add(TestFixture.INSTANCE.judgeBob); doc.getJudges().add(TestFixture.INSTANCE.judgeEoin); doc.getHiredJudges().add(TestFixture.INSTANCE.hiredJudgeAndy); doc.getHiredJudges().add(TestFixture.INSTANCE.hiredJudgeJamie); doc.getHiredJudges().add(TestFixture.INSTANCE.hiredJudgeBob); doc.getHiredJudges().add(TestFixture.INSTANCE.hiredJudgeEoin); doc.getSoloContests().add(TestFixture.INSTANCE.soloContest); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(ITVenueController.PATH) .build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.soloContest.setId(doc.getSoloContests().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(ITJudgeController.PATH) .build(); httpPost = new HttpPost(uri); xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); httpPost = new HttpPost(uri); xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.soloContest.setId(doc.getSoloContests().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }