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:eu.seaclouds.platform.dashboard.resources.MonitorResource.java
@POST @Path("rules") public Response addMonitoringRules(String monitoringRules) { try {/*from w w w .j a va 2 s. com*/ String monitorResponse = new HttpPostRequestBuilder() .entity(new StringEntity(monitoringRules, ContentType.APPLICATION_XML)) .host(monitor.getEndpoint()).path("/v1/monitoring-rules").build(); return Response.ok().build(); } catch (IOException | URISyntaxException e) { return Response.status(Response.Status.NOT_FOUND).build(); } }
From source file:org.exist.http.urlrewrite.URLRewritingTest.java
@Test public void findsParentController() throws IOException { final XmldbURI nestedCollectionName = XmldbURI.create("nested"); final XmldbURI docName = XmldbURI.create("test.xml"); final String testDocument = "<hello>world</hello>"; final String storeDocUri = getRestUri() + TEST_COLLECTION.append(nestedCollectionName).append(docName); HttpResponse response = executor//from w ww .j a v a 2 s . c o m .execute(Request.Put(storeDocUri).bodyString(testDocument, ContentType.APPLICATION_XML)) .returnResponse(); assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode()); final String retrieveDocUri = getAppsUri() + "/" + TEST_COLLECTION_NAME.append(nestedCollectionName).append(docName); response = executor.execute(Request.Get(retrieveDocUri)).returnResponse(); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); final String responseBody; try (final FastByteArrayOutputStream baos = new FastByteArrayOutputStream( (int) response.getEntity().getContentLength())) { response.getEntity().writeTo(baos); responseBody = baos.toString(UTF_8); } assertTrue(responseBody.matches("<controller>.+</controller>")); }
From source file:com.msopentech.odatajclient.engine.communication.request.retrieve.ODataMetadataRequest.java
/** * Constructor.// www . j av a 2s .co m * * @param odataClient client instance getting this request * @param uri metadata URI. */ ODataMetadataRequest(final ODataClient odataClient, final URI uri) { super(odataClient, ODataPubFormat.class, uri); super.setAccept(ContentType.APPLICATION_XML.getMimeType()); super.setContentType(ContentType.APPLICATION_XML.getMimeType()); }
From source file:org.sonatype.nexus.repositories.metadata.Hc4RawTransport.java
@Override public void writeRawData(final String path, final byte[] bytes) throws IOException { final HttpPut put = new HttpPut(createUrlWithPath(path)); put.setEntity(new ByteArrayEntity(bytes, ContentType.APPLICATION_XML)); final HttpResponse response = httpClient.execute(put); try {//from w w w . ja va 2 s .com if (response.getStatusLine().getStatusCode() > 299) { throw new IOException("The response was not successful: " + response.getStatusLine()); } } finally { EntityUtils.consume(response.getEntity()); } }
From source file:org.wuspba.ctams.ui.server.ServerUtils.java
public static String post(URI uri, String xml) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); String ret;/*from ww w . j a v a 2 s .c o m*/ httpPost.setEntity(xmlEntity); try (CloseableHttpResponse response = httpclient.execute(httpPost)) { HttpEntity entity = response.getEntity(); ret = convertEntity(entity); EntityUtils.consume(entity); } return ret; }
From source file:org.exist.extensions.exquery.restxq.impl.IntegrationTest.java
@BeforeClass public static void storeResourceFunctions() throws IOException { executor = Executor.newInstance().auth(TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD) .authPreemptive("localhost"); HttpResponse response = null;//from ww w. ja va 2 s. c om response = executor.execute(Request .Put(getRestUri() + "/db/system/config" + TEST_COLLECTION + "/" + CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE) .bodyString(COLLECTION_CONFIG, ContentType.APPLICATION_XML)).returnResponse(); assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode()); response = executor.execute(Request.Put(getRestUri() + TEST_COLLECTION + "/" + XQUERY1_FILENAME) .bodyString(XQUERY1, XQUERY_CONTENT_TYPE)).returnResponse(); assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode()); response = executor.execute(Request.Get(getRestUri() + "/db/?_query=rest:resource-functions()")) .returnResponse(); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); System.out.println(asString(response.getEntity().getContent())); }
From source file:org.epics.archiverappliance.retrieval.channelarchiver.XMLRPCClient.java
/** * Call archiver.info on the Channel Archiver * @param serverURL The Server URL //from w w w .j a v a 2 s .c om * @param handler DefaultHandler * @throws IOException   * @throws SAXException   */ public static void archiverInfo(String serverURL, DefaultHandler handler) throws IOException, SAXException { logger.debug("Getting channel archiver info with URL " + serverURL); StringEntity archiverInfo = new StringEntity("<?xml version=\"1.0\"?>\n" + "<methodCall>\n" + "<methodName>archiver.info</methodName>\n" + "<params></params>\n" + "</methodCall>\n", ContentType.APPLICATION_XML); doHTTPPostAndCallSAXHandler(serverURL, handler, archiverInfo); }
From source file:org.opennms.protocols.http.HttpUrlConnectionIT.java
/** * Test the Servlet with a simple POST Request based on XML Data. * * @throws Exception the exception/*w w w.j a va2 s. c om*/ */ @Test @JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") }) public void testServlet() throws Exception { String xml = "<person><firstName>Alejandro</firstName></person>"; final HttpClientWrapper clientWrapper = HttpClientWrapper.create(); try { StringEntity entity = new StringEntity(xml, ContentType.APPLICATION_XML); HttpPost method = new HttpPost("http://localhost:10342/junit/test/sample"); method.setEntity(entity); CloseableHttpResponse response = clientWrapper.execute(method); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); Assert.assertEquals("OK!", EntityUtils.toString(response.getEntity())); } finally { IOUtils.closeQuietly(clientWrapper); } }
From source file:org.llorllale.youtrack.api.mock.http.response.MockOkResponse.java
/** * Uses {@code payload} as an {@link HttpEntity} with content type * {@link ContentType#APPLICATION_XML}./*from w ww . jav a 2 s. com*/ * @param payload the mock payload * @see #MockOkResponse(HttpEntity) * @since 0.4.0 */ public MockOkResponse(String payload) { this(new StringEntity(payload, ContentType.APPLICATION_XML)); }