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.geosdi.geoplatform.connector.server.request.WFSRequest.java
@Override protected HttpEntity preparePostEntity() throws IllegalParameterFault, JAXBException, UnsupportedEncodingException { Marshaller marshaller = this.getMarshaller(); Object request = this.createRequest(); StringWriter writer = new StringWriter(); marshaller.marshal(request, writer); return new StringEntity(writer.toString(), ContentType.APPLICATION_XML); }
From source file:org.n52.youngs.harvest.PoxCswSource.java
@Override public Collection<SourceRecord> getRecords(long startPosition, long maxRecords, Report report) { log.debug("Requesting {} records from catalog starting at {}", maxRecords, startPosition); Collection<SourceRecord> records = Lists.newArrayList(); HttpEntity entity = createRequest(startPosition, maxRecords); try {//from ww w . j a va 2 s. co m log.debug("GetRecords request: {}", EntityUtils.toString(entity)); String response = Request.Post(getEndpoint().toString()).body(entity) .addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_XML.getMimeType()) .addHeader(HttpHeaders.ACCEPT_CHARSET, Charsets.UTF_8.name()).execute().returnContent() .asString(Charsets.UTF_8); log.trace("Response: {}", response); JAXBElement<GetRecordsResponseType> jaxb_response = unmarshaller .unmarshal(new StreamSource(new StringReader(response)), GetRecordsResponseType.class); BigInteger numberOfRecordsReturned = jaxb_response.getValue().getSearchResults() .getNumberOfRecordsReturned(); log.debug("Got response with {} records", numberOfRecordsReturned); List<Object> nodes = jaxb_response.getValue().getSearchResults().getAny(); if (!nodes.isEmpty()) { log.debug("Found {} \"any\" nodes.", nodes.size()); nodes.stream().filter(n -> n instanceof Node).map(n -> (Node) n).map(n -> new NodeSourceRecord(n)) .forEach(records::add); } List<JAXBElement<? extends AbstractRecordType>> jaxb_records = jaxb_response.getValue() .getSearchResults().getAbstractRecord(); if (!jaxb_records.isEmpty()) { log.debug("Found {} \"AbstractRecordType\" records.", jaxb_records.size()); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); jaxb_records.stream().map(type -> { return getNode(type, context, db); }).filter(Objects::nonNull).map(n -> new NodeSourceRecord(n)).forEach(records::add); } } catch (IOException | JAXBException | ParserConfigurationException e) { log.error("Could not retrieve records from endpoint {}", getEndpoint(), e); report.addMessage(String.format("Error retrieving record from endpoint %s: %s", this, e)); } log.debug("Decoded {} records", records.size()); return records; }
From source file:org.geosdi.geoplatform.connector.server.request.CatalogCSWRequest.java
@Override protected HttpEntity preparePostEntity() throws IllegalParameterFault, JAXBException, UnsupportedEncodingException { Marshaller marshaller = getMarshaller(); Object request = this.createRequest(); StringWriter writer = new StringWriter(); marshaller.marshal(request, writer); return new StringEntity(writer.toString(), ContentType.APPLICATION_XML); }
From source file:com.emc.vipr.ribbon.test.ViPRDataServicesServerListTest.java
@Test public void testXmlParse() throws Exception { String rawXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + " <ListDataNode xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n" + " <DataNodes> 10.247.102.239</DataNodes>\n" + " <DataNodes>10.247.102.240</DataNodes>\n" + " <DataNodes>10.247.102.241 </DataNodes>\n" + " <VersionInfo>vipr-2.0.0.0.r2b3e482</VersionInfo>\n" + " </ListDataNode>"; HttpResponse testResponse = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); testResponse.setEntity(new StringEntity(rawXml, ContentType.APPLICATION_XML)); ParserTester tester = new ParserTester(); List<String> hosts = tester.testParse(testResponse); Assert.assertEquals("wrong number of hosts", 3, hosts.size()); Assert.assertEquals("wrong 1st host", "10.247.102.239", hosts.get(0)); Assert.assertEquals("wrong 2nd host", "10.247.102.240", hosts.get(1)); Assert.assertEquals("wrong 3rd host", "10.247.102.241", hosts.get(2)); }
From source file:org.epics.archiverappliance.retrieval.channelarchiver.XMLRPCClient.java
/** * Call archiver.archives on the Channel Archiver * @param serverURL The Server URL //w w w . j a v a 2 s. co m * @param handler DefaultHandler * @throws IOException   * @throws SAXException   */ public static void archiverArchives(String serverURL, DefaultHandler handler) throws IOException, SAXException { logger.debug("Getting channel archiver archives with URL " + serverURL); StringEntity archiverInfo = new StringEntity("<?xml version=\"1.0\"?>\n" + "<methodCall>\n" + "<methodName>archiver.archives</methodName>\n" + "<params></params>\n" + "</methodCall>\n", ContentType.APPLICATION_XML); doHTTPPostAndCallSAXHandler(serverURL, handler, archiverInfo); }
From source file:com.hp.mqm.clt.RestClientTest.java
@Test public void testPostTestResult() throws IOException, URISyntaxException, InterruptedException, ValidationException { RestClient client = new RestClient(testClientSettings); long timestamp = System.currentTimeMillis(); // invalid payload final File testResultsInvalidPayload = new File(this.getClass().getResource("TestResult.xmlx").toURI()); try {// ww w. j a v a2 s . c om client.postTestResult(new FileEntity(testResultsInvalidPayload, ContentType.APPLICATION_XML)); Assert.fail(); } catch (RuntimeException e) { Assert.assertNotNull(e); } finally { client.release(); } // test "file does not exist" final File nonExistingFile = new File("abcdefghchijklmn.xml"); try { client.postTestResult(new FileEntity(nonExistingFile, ContentType.APPLICATION_XML)); Assert.fail(); } catch (FileNotFoundException e) { Assert.assertNotNull(e); } finally { client.release(); } String testResultXml = ResourceUtils.readContent("TestResult.xml").replaceAll("%%%TIMESTAMP%%%", String.valueOf(timestamp)); final File testResult = temporaryFolder.newFile(); FileUtils.write(testResult, testResultXml); try { long id = client.postTestResult(new FileEntity(testResult, ContentType.APPLICATION_XML)); assertPublishResult(id, "success"); } finally { client.release(); } PagedList<TestRun> pagedList = testSupportClient.queryTestRuns("testOne" + timestamp, 0, 50); Assert.assertEquals(1, pagedList.getItems().size()); Assert.assertEquals("testOne" + timestamp, pagedList.getItems().get(0).getName()); }
From source file:org.jvoicexml.callmanager.mmi.http.HttpETLProtocolAdapter.java
@Override public void sendMMIEvent(Object channel, Mmi mmi) throws IOException { try {/* w w w. ja v a 2s. co m*/ final URI source = server.getURI(); final LifeCycleEvent event = mmi.getLifeCycleEvent(); event.setSource(source.toString()); final String target = event.getTarget(); if (target == null) { LOGGER.error("unable to send MMI event '" + mmi + "'. No target."); return; } final JAXBContext ctx = JAXBContext.newInstance(Mmi.class); final Marshaller marshaller = ctx.createMarshaller(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.marshal(mmi, out); final URI uri = new URI(target); final HttpClient client = new DefaultHttpClient(); final HttpPost post = new HttpPost(uri); final HttpEntity entity = new StringEntity(out.toString(), ContentType.APPLICATION_XML); post.setEntity(entity); client.execute(post); LOGGER.info("sending " + mmi + " to '" + uri + "'"); } catch (JAXBException e) { throw new IOException(e.getMessage(), e); } catch (URISyntaxException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.jvoicexml.demo.mmi.simpledemo.SimpleMmiDemo.java
public void send(final Mmi mmi, final URI target) throws JAXBException, IOException { final JAXBContext ctx = JAXBContext.newInstance(Mmi.class); final Marshaller marshaller = ctx.createMarshaller(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.marshal(mmi, out);/*from ww w .ja v a2 s.c om*/ final HttpClient client = new DefaultHttpClient(); final HttpPost post = new HttpPost(target); final HttpEntity entity = new StringEntity(out.toString(), ContentType.APPLICATION_XML); post.setEntity(entity); client.execute(post); LOGGER.info("sending " + mmi + " to '" + target + "'"); }
From source file:com.cognifide.aet.common.TestSuiteRunner.java
private SuiteExecutionResult startSuiteExecution(File testSuite) throws IOException { MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create().addBinaryBody("suite", testSuite, ContentType.APPLICATION_XML, testSuite.getName()); if (domain != null) { entityBuilder.addTextBody("domain", domain); }//from w ww . ja va 2 s. c o m HttpEntity entity = entityBuilder.build(); return Request.Post(getSuiteUrl()).body(entity).connectTimeout(timeout).socketTimeout(timeout).execute() .handleResponse(suiteExecutionResponseHandler); }
From source file:org.epics.archiverappliance.retrieval.channelarchiver.XMLRPCClient.java
/** * Call archiver.names on the Channel Archiver - note this call can take a loooong time. * @param serverURL The Server URL //w ww . ja v a 2 s.c o m * @param key   * @param handler DefaultHandler * @throws IOException   * @throws SAXException   */ public static void archiverNames(String serverURL, String key, DefaultHandler handler) throws IOException, SAXException { logger.debug("Getting channel archiver archives with URL " + serverURL); StringEntity archiverInfo = new StringEntity( "<?xml version=\"1.0\"?>\n" + "<methodCall>\n" + "<methodName>archiver.names</methodName>\n" + "<params>\n" + "<param><value><i4>" + key + "</i4></value></param>\n" + "<param><value><string></string></value></param>" + "</params>\n" + "</methodCall>\n", ContentType.APPLICATION_XML); doHTTPPostAndCallSAXHandler(serverURL, handler, archiverInfo); }