Example #1
0
        /// <summary>
        ///Annotates a single document and returns an {@link InputStream} from
        /// which the contents of the serialized annotated document can be read
        /// </summary>
        /// <param name="documentText">the contents of the document which will be annotated</param>
        /// <param name="documentMimeType">the MIME type of the file which will be annotated</param>
        /// <param name="serializationFormat">the format which will be used for serialization of the annotated document</param>
        /// <returns>an {@link InputStream} from which the serialization of the annotated document can be read</returns>
        public Stream annotateDocumentAsStream(String documentText,
                                               SupportedMimeType documentMimeType, ResponseFormat serializationFormat)
        {
            ServiceRequest rq =
                new ServiceRequest(documentText, documentMimeType, null);
            WebHeaderCollection headers = new WebHeaderCollection();

            headers.Add("Accept", serializationFormat.ToStringValue());
            try
            {
                return(client.requestForStream("", "POST", rq, headers));
            }
            catch (HttpClientException e)
            {
                JsonObject response = e.getResponse();
                if (response == null)
                {
                    throw new S4ServiceClientException(e.Message);
                }
                String msg = response.ToString();
                throw new S4ServiceClientException(msg == null ? e.Message : msg.ToString());
            }
        }
Example #2
0
        protected Dictionary <String, String> constructHeaders(ResponseFormat serializationFormat)
        {
            Dictionary <String, String> headers = Parameters.newInstance().withValue("Accept", serializationFormat.ToStringValue());

            if (requestCompression)
            {
                headers.Add("Accept-Encoding", "gzip");
            }
            return(headers);
        }