0

Ok first of all code (its mega simple):

@Controller
@RequestMapping("/")

public class HelloController {

private final static Logger logger = Logger.getLogger(HelloController.class);
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {

    logger.info("ELO ELO");
    model.addAttribute("message", "Hello world!");

    RestTemplate restTemplate = new RestTemplate();

    String url = "http://192.168.0.200:8000/GPIO/11/function/in";
    //String url = "http://192.168.0.200:8000/GPIO/11/function";
    //restTemplate.getForObject(url, String.class);
    String test = "";

    restTemplate.postForObject(url, null, String.class);



    logger.info(test);
    return "hello";
}

Next example that I'm not a crazy man here is response from postman (chrome):

enter image description here

And at the end full error log:

type Exception report

message Request processing failed; nested exception is java.lang.IllegalArgumentException: "None" does not contain '/'

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: "None" does not contain '/' org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) javax.servlet.http.HttpServlet.service(HttpServlet.java:618) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause

java.lang.IllegalArgumentException: "None" does not contain '/' org.springframework.http.MediaType.parseMediaType(MediaType.java:697) org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:305) org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:113) org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:84) org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:492) org.springframework.web.client.RestTemplate.execute(RestTemplate.java:447) org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:295) pl.piquarium.mvc.HelloController.printWelcome(HelloController.java:35) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:439) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:427) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) javax.servlet.http.HttpServlet.service(HttpServlet.java:618) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) note The full stack trace of the root cause is available in the Apache Tomcat/8.0.3 logs.

Request headers:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:__utma=212787668.2094541430.1400264829.1400264829.1400268775.2; __utmz=212787668.1400264829.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Host:192.168.0.200:8000
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36

Response Headers:

Cache-Control:no-cache
Content-Length:2
Content-Type:None
Date:Fri, 16 May 2014 22:37:16 GMT
Server:WebIOPi/0.7.0/Python3.2
4
  • Where's your view named hello? Did you intend to make this a RestController or use @ResponseBody? Commented May 16, 2014 at 21:15
  • My view is ok if I comment lane with restTemplate.post it load without problem Commented May 16, 2014 at 21:35
  • Post the entire response headers from that GPIO endpoint (Raspberry Pi?). I suspect that service is sending back no or a bogus content type. Commented May 16, 2014 at 21:36
  • dl.dropboxusercontent.com/u/16887656/head.txt Here is head Commented May 16, 2014 at 22:37

2 Answers 2

0

Did you try setting headers like below,

 HttpHeaders headers = new HttpHeaders();
 headers.setContentType(MediaType.MULTIPART_FORM_DATA);//or any other required
 HttpEntity request = new HttpEntity(null, headers);
 RestTemplate restTemplate = new RestTemplate();
 String url = "http://192.168.0.200:8000/GPIO/11/function/in";
 String response = restTemplate.postForObject(url,request,String.class);
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is that the server is returning an invalid content type of None instead of something like text/plain, and Spring REST is choking on it. You will need to add a custom message converter for the None type, not use a typed query and parse the response object yourself, or get the Pi people to fix their broken Web server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.