问题
I have deployed my 2 Spring Boot applications in PCF and an Eureka Server for discovery. I have @EnableEurekaClient in the Applications and they can be seen in the Eureka Server in PCF
When I hit the the other application using FeignClient I am getting a error
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] feign.FeignException: status 302 reading MyService#dummy(); content:
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at feign.FeignException.errorStatus(FeignException.java:62)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:91)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:138)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at com.sun.proxy.$Proxy140.dummy(Unknown Source)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at com.c2m.sigma.rest.controller.MyController.sendNotification(MyController.java:70)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at java.lang.reflect.Method.invoke(Method.java:498)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
2017-11-23T16:54:19.745+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
2017-11-23T16:54:19.746+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
2017-11-23T16:54:19.747+05:30 [RTR/1] [OUT] com.apps.np.sdppcf.com - [2017-11-23T11:24:19.486+0000] "POST /my-rest-services/api/Launch/SendNotification HTTP/1.1" 200 1235 197 "-" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" "10.192.230.112:47060" "10.192.225.14:61138" x_forwarded_for:"10.111.136.194" x_forwarded_proto:"https" vcap_request_id:"38c0d6e1-4431-4a68-604f-5330a48a53bd" response_time:0.25981493 app_id:"8d2a0aba-8378-441f-9ecd-5f6904bcdf65" app_index:"0" x_b3_traceid:"aafdb180106cebde" x_b3_spanid:"aafdb180106cebde" x_b3_parentspanid:"-"
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
2017-11-23T16:54:19.747+05:30 [APP/PROC/WEB/0] [ERR] at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106)
My feignClient is as follows. I have re-named the services while posting here
@FeignClient(name = "my-feign-services")
public interface MyService {
@RequestMapping(value = "/updateValues", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public String updateValues(@RequestBody ModelWrapper odelWrapper);
@RequestMapping(value = "/dummy", method = RequestMethod.GET)
public String dummy();
}
I also have Spring Security enabled and it allows anonymous requests also .
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable().authorizeRequests()
.antMatchers("/my-feign-services/**").anonymous()
.and()
.authorizeRequests().anyRequest()
.authenticated().and().csrf().disable();
}
Any reason why the FeignClient is not working in PCF. In localhost it works fine and I am able to communicate between the 2 services easily but the same is failing in PCF
I enabled the Feign Logging using the FeignLogger in a configuration class and adding in the Feign Client. The location is coming correctly in the logs but failing with the Error 302 and :content.
Update :
After adding the URL in the configuration class it worked . It is a stop gap arrangement till the platform team gets Spring Cloud services in Cloud Foundry.
回答1:
A 302 error is indicative of a redirect. Can you attempt to see what the Location
header is on the response? Chances are you don’t have feign configured to follow redirects.
回答2:
I tried debugging by adding a new Dummy service also and it was also failing with the same FeignException . Looks like there is some problem with the Service registry in PCF. I had a backup code and I migrated my other code to this and tested and it worked fine . I was able to do MS - MS communication with no errors and response was also received.
来源:https://stackoverflow.com/questions/47454753/feignexception-status-302-reading-myservicedummy-content