Note that there are some explanatory texts on larger screens.

plurals
  1. POContent type check for downloading a pdf in java gone wrong
    primarykey
    data
    text
    <p>I'm trying to post a request to download a pdf file in java. I'm using - trying to fix cause the method is changed - someone else's code and, for what I've seen, before requesting the pdf file via a web service, a check for the content type is made. If the content-type requested is ok, then a call to the service to download the pdf file is made.</p> <p>This is the method that checks for the content type:</p> <pre><code>public boolean checkContentType(String serviceName, Map&lt;String, String&gt; params, String contentType) { params.put(PARAM_SERVICE, serviceName); if(log.isDebugEnabled()) { log.debug("checkContentType for serviceName: " + serviceName + " - Params: " + params + " - contentType: " + contentType); } HttpClient httpclient = new HttpClient(); GetMethod get = new GetMethod(basicUrl); get.setQueryString(ParameterUtil.getValuePairs(params)); log.info(get.getQueryString()); try { httpclient.executeMethod(get); if (get.getStatusCode() == HttpStatus.SC_OK) { String respContentType = get.getResponseHeader("Content-Type").getValue(); log.info("Request Content type [" +contentType + "] is not in response content type: [" + respContentType + "]"); log.info(String.valueOf(contentType != null)); log.info(String.valueOf(StringUtils.containsIgnoreCase(respContentType, contentType))); return contentType != null &amp;&amp; StringUtils.containsIgnoreCase(respContentType, contentType); } else { log.error("Response status code KO: [" + get.getStatusCode() +"] from url: " + basicUrl + " with querystring: " + get.getQueryString()); } } catch (Exception e) { log.error("Unable to get http response from url: " + basicUrl + " with querystring: " + get.getQueryString() + ". Ex Msg:" + e.getMessage()); } finally { get.releaseConnection(); } return false; } </code></pre> <p>When Content-type is 'pdf' I get false on the second condition, but how do I know what Content-type should be set? I get this log: <code>Request Content type [pdf] is not in response content type: [text/plain;charset=UTF-8]</code>. </p> <p>I've also tried to skip the content type check and go request the pdf immediately, but after waiting for some time I get a 16 kb pdf that I can't open. I've tried to set the content type to text/plain;charset=UTF-8 but I still get that log.</p> <p>Shouldn't it be PDF since I'm downloading a pdf, or should I set somewhere in the code that I expect a pdf content type?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload