I am trying to execute a RESTful web service, however, when I submit a request, an HttpClientErrorException occurs with the message "415 Unsupported Media Type".
This is the code to call the service:
MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(); request.add(val1, "xxxxx"); request.add(val2, "************"); request.add(val3, "xxx"); request.add("type", "AUTHENTICATE"); String response = restTemplate.postForObject(url, request, String.class); System.out.println(response.toString());
RestTemplate is connected from applicationContext.xml using FormHttpMessageConverter as its MessageConverter.
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> <constructor-arg name="requestFactory" ref="httpClientFactory"/> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.FormHttpMessageConverter"/> </list> </property> </bean> <bean id="httpClientFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory"> <constructor-arg ref="httpClient"/> </bean> <bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams"> <property name="authenticationPreemptive" value="true"/> <property name="connectionManagerClass" value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"/> </bean> <bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"> <constructor-arg ref="httpClientParams"/> </bean>
This is an exception:
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 415 Unsupported Media Type at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76) at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:486) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:443) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401) at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:279) at ph.com.smart.drawbridge.commons.diameter.DiameterClient.post(DiameterClient.java:21)
Any ideas?
source share