Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feign REST Client - Converts GET requests to POST #36

Closed
ph0bos opened this issue Oct 20, 2014 · 5 comments
Closed

Feign REST Client - Converts GET requests to POST #36

ph0bos opened this issue Oct 20, 2014 · 5 comments

Comments

@ph0bos
Copy link

ph0bos commented Oct 20, 2014

When implementing a Feign client as per (http://projects.spring.io/spring-cloud/spring-cloud.html#_declarative_rest_client_feign) using the following interface all GET requests to "getStore" are actually being attempted as POST requests resulting in an Unsupported Operation exception being thrown.

The listPlatforms call is executed as a GET request and works as expected.

Interface;

public interface PlatformClient {
    @RequestMapping(method = RequestMethod.GET, value = "/platforms")
    List getPlatforms();

    @RequestMapping(method = RequestMethod.GET, value = "/platforms/{platformId}")
    Platform getStore(@PathVariable("platformId") String platformId);
}

Exception;
Caused by: feign.FeignException: status 405 reading PlatformRestClient#getPlatform(String); content:

@spencergibb
Copy link
Member

@ph0bos I hadn't added support for parameter annotations yet. So your @PathVariable was ignored and the String was passed as the body, and when there is a body it assumes POST. I've added support for @PathVariable, @RequestParam and @RequestHeader

@viktor-coreteka
Copy link

@spencergibb in witch version?
RequestHeader doesnt work for me
I'm using springCloudVersion = 'Edgware.SR5'

@rohitdec01
Copy link

I am not able to pass body in Get request while using Feign. If I am doing so it is still converting get request to post.
Do we have any work around on this. I just want to separate my header and body while calling the get method.

@rohitdec01
Copy link

@spencergibb in witch version?
RequestHeader doesnt work for me
I'm using springCloudVersion = 'Edgware.SR5'

Try this ..............

@component
public class AdapterRequestInterceptor implements RequestInterceptor {

/* (non-Javadoc)
 * @see feign.RequestInterceptor#apply(feign.RequestTemplate)
 */
@Override
public void apply(RequestTemplate requestTemplate) {
	HttpHeaders headers = new HttpHeaders();
	headers.setAccept(Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON }));
	headers.setContentType(MediaType.APPLICATION_JSON);
	// Other header values -- from a dynamic function.
	

	addHeadersToRequest(headers, requestTemplate);
	System.out.println("Test");
}

/**
 * @param headerParams
 * @param requestBuilder
 */
private void addHeadersToRequest(HttpHeaders headerParams, RequestTemplate requestBuilder) {
	for (Map.Entry<String, List<String>> entry : headerParams.entrySet()) {
		String headerName = entry.getKey();
		for (String headerValue : entry.getValue()) {
			requestBuilder.header(headerName, headerValue);
		}
	}
}

}

@rohitdec01
Copy link

@ph0bos I hadn't added support for parameter annotations yet. So your @PathVariable was ignored and the String was passed as the body, and when there is a body it assumes POST. I've added support for @PathVariable, @RequestParam and @RequestHeader

I am not able to pass body in Get request while using Feign. If I am doing so it is still converting get request to post.
Do we have any work around on this? I just want to separate my header and body while calling the get method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants