List of usage examples for org.apache.http.entity ContentType equals
public boolean equals(Object obj)
From source file:interoperabilite.webservice.fluent.FluentResponseHandling.java
public static void main(String[] args) throws Exception { Document result = Request.Get("http://somehost/content").execute() .handleResponse(new ResponseHandler<Document>() { @Override/* w w w. j av a2 s .c o m*/ public Document handleResponse(final HttpResponse response) throws IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } if (entity == null) { throw new ClientProtocolException("Response contains no content"); } DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); try { DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); ContentType contentType = ContentType.getOrDefault(entity); if (!contentType.equals(ContentType.APPLICATION_XML)) { throw new ClientProtocolException("Unexpected content type:" + contentType); } Charset charset = contentType.getCharset(); if (charset == null) { charset = Consts.ISO_8859_1; } return docBuilder.parse(entity.getContent(), charset.name()); } catch (ParserConfigurationException ex) { throw new IllegalStateException(ex); } catch (SAXException ex) { throw new ClientProtocolException("Malformed XML document", ex); } } }); // Do something useful with the result System.out.println(result); }
From source file:io.aos.protocol.http.httpcommon.FluentResponseHandling.java
public static void main(String... args) throws Exception { Document result = Request.Get("http://somehost/content").execute() .handleResponse(new ResponseHandler<Document>() { public Document handleResponse(final HttpResponse response) throws IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }/*w ww. jav a 2s .c om*/ if (entity == null) { throw new ClientProtocolException("Response contains no content"); } DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); try { DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); ContentType contentType = ContentType.getOrDefault(entity); if (!contentType.equals(ContentType.APPLICATION_XML)) { throw new ClientProtocolException("Unexpected content type:" + contentType); } Charset charset = contentType.getCharset(); if (charset == null) { charset = HTTP.DEF_CONTENT_CHARSET; } return docBuilder.parse(entity.getContent(), charset.name()); } catch (ParserConfigurationException ex) { throw new IllegalStateException(ex); } catch (SAXException ex) { throw new ClientProtocolException("Malformed XML document", ex); } } }); // Do something useful with the result System.out.println(result); }
From source file:eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingUploader.java
private byte[] writeContent(String mappingFileName, ContentType contentType, ProgressIndicator progress, IOReporter reporter) throws IOException { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { if (contentType.equals(DataStoreFile.ZIP_CONTENT_TYPE)) { try (ZipOutputStream zos = new ZipOutputStream(bos)) { if (includeTargetSchema) { // add target schema to zip addTargetSchemaToZip(zos, null, progress, reporter); }//from w ww . j a v a2 s. co m // main mapping configuration file zos.putNextEntry(new ZipEntry(mappingFileName + ".appschema")); generator.writeMappingConf(zos); zos.closeEntry(); if (generator.getGeneratedMapping().requiresMultipleFiles()) { zos.putNextEntry(new ZipEntry(AppSchemaIO.INCLUDED_TYPES_MAPPING_FILE)); generator.writeIncludedTypesMappingConf(zos); zos.closeEntry(); } } } else { generator.writeMappingConf(bos); } return bos.toByteArray(); } }