0

I am just trying to make a simple REST request like below

    @Test
    public void retcall() {

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE));
        headers.set(HttpHeaders.ACCEPT, "*/*");
        headers.set("X-IBM-Client-id", CLIENT_ID);
        headers.set(HEADER_AUTHORIZATION_KEY, "Bearer " + tokenInfo);
        HttpEntity<String> entity = new HttpEntity<>(headers);
        String url = VALIDATION_HTTP_PREFIX + SCF_SB + VALIDATION_HTTP_SUFFIX;
        RestTemplate restTemplate = new RestTemplate();
        List<? extends HttpMessageConverter<?>> httpMessageConverters = Collections.singletonList(new MappingJackson2HttpMessageConverter());
        restTemplate.setMessageConverters((List<HttpMessageConverter<?>>) httpMessageConverters);
        log.info("checking authentication {}", entity);
        ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
        System.out.println(exchange);

    }

However I get:

org.springframework.http.InvalidMediaTypeException: Invalid mime type "unknown": does not contain '/'

    at org.springframework.http.MediaType.parseMediaType(MediaType.java:462)
    at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:759)
    at org.springframework.web.client.DefaultResponseErrorHandler.getCharset(DefaultResponseErrorHandler.java:163)
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:108)
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:708)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:661)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:621)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:539)
    at com.inditex.otec.wscnfsvp.test.ChinoTest.retcall(ChinoTest.java:80)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.util.InvalidMimeTypeException: Invalid mime type "unknown": does not contain '/'
    at org.springframework.util.MimeTypeUtils.parseMimeType(MimeTypeUtils.java:257)
    at org.springframework.http.MediaType.parseMediaType(MediaType.java:459)
    ... 30 more

I have already tried everything as for example is said in Invalid mime type in spring rest template? but still not working...

In spite of this 'unknown' Content-Type comes from the response; with Postman I'm able to get the body response...

Do you have any ideas?

Thanks in advance!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
nAtxO Pi
  • 21
  • 6
  • Can you also share your endpoint code that you are trying to test? – Yash Aug 01 '19 at 13:31
  • Possible duplicate of [Invalid mime type in spring rest template?](https://stackoverflow.com/questions/48799409/invalid-mime-type-in-spring-rest-template) – Yash Aug 01 '19 at 13:32
  • I wish I could share you the link but is the token validation of a private entity and they could get mad if I do. I can tell you that the Content-Type in the response is 'unknown' and calling it from Spring RestTemplate throws exception :/ . For your second comment, I know that this issue seems very similar to https://stackoverflow.com/questions/48799409/invalid-mime-type-in-spring-rest-template but nothing saying there works in this case. Thanks for your help. – nAtxO Pi Aug 02 '19 at 06:55
  • But if 'I can tell you that the Content-Type in the response is 'unknown' ' then the other app is the problem, or do you need to run anyway with that 'broken' application? – Martin van Wingerden Sep 05 '19 at 18:19
  • Why are you specifying the Content Type of a GET request where you send no content? – takendarkk Sep 05 '19 at 18:21

1 Answers1

0

Try replacing

headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE));

with

headers.setContentType(MediaType.APPLICATION_JSON);