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 - Apache HttpClient not being used for loadbalanced clients #2550
Comments
i see the issue #2462 and @ryanjbaxter you say use the ribbon would use the jdk httpclient?can i use use the ribbon with the apachehttpclient ? i need the client support the patch request method! |
We no longer support Camden, please use Dalston.SR4 or Edgware.RELEASE. When using Feign or Ribbon you can use either the Apache HTTP Client (default) or the OK HTTP Client. |
thinks ! |
@ryanjbaxter I wrote a demo project ,the pom.xml like that: <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
and the properties file like that:
the main class like that: @SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class DemoApplication {
@Bean
RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
} and the feign client like that: @FeignClient(name="wallet")
public interface IWalletClient {
@RequestMapping(value = "/walletbase/alterBalanceByUserId", method = RequestMethod.PATCH)
Object test(@RequestParam("userid") int i, @RequestParam("balance") double d, @RequestParam("balanceCode") String s);
} but it also throw an Exception: feign.RetryableException: Invalid HTTP method: PATCH executing PATCH http://192.168.5.179:7807/walletbase/alterBalanceByUserId?userid=24771&balance=8525.19&balanceCode=2525F8F3F72
at feign.FeignException.errorExecuting(FeignException.java:67)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:104)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
at com.sun.proxy.$Proxy84.test(Unknown Source)
at com.xxx.demo.rest.client.IWalletClientTest.test1(IWalletClientTest.java:21)
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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
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: java.net.ProtocolException: Invalid HTTP method: PATCH
at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:440)
at sun.net.www.protocol.http.HttpURLConnection.setRequestMethod(HttpURLConnection.java:552)
at feign.Client$Default.convertAndSend(Client.java:94)
at feign.Client$Default.execute(Client.java:73)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97)
... 32 more you say Apache HTTP Client as default client,but it doesn't....what wrong with me ? |
It would be better if you provided an actual project with the source code rather than paste it in the issue. Do you see the Apache HTTP Client jar on your classpath?
|
I had add the above denpendency as
|
|
thanks again,I upload the demo on https://github.com/rainplus/spring-cloud-fegin-demo.git |
I had to remove Zookeeper from the sample and instead set |
I appreciate your giving me so much of your time. it mean when I use the zookeeper,i can't use fegin with ribbon and other http client? |
No I am not saying that. I was just stating that I removed it to make your sample easier to run. Zookeeper should have no effect on the problem you are describing it is just providing the service information. |
the problem is must to set @Configuration
@ConditionalOnDependenciesPassed
@ConditionalOnZookeeperEnabled
@ConditionalOnProperty(value = "spring.cloud.zookeeper.dependency.headers.enabled", matchIfMissing = true)
@ConditionalOnClass({ Client.class, LoadBalancerFeignClient.class })
@AutoConfigureAfter({ RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class })
public class DependencyFeignClientAutoConfiguration {
@Autowired(required = false) private LoadBalancerFeignClient ribbonClient;
@Autowired private ZookeeperDependencies zookeeperDependencies;
@Autowired private CachingSpringLoadBalancerFactory loadBalancerFactory;
@Autowired private SpringClientFactory springClientFactory;
@Bean
@Primary
Client dependencyBasedFeignClient() {
return new LoadBalancerFeignClient(
new Client.Default(null, null), this.loadBalancerFactory, this.springClientFactory) {
@Override
public Response execute(Request request, Request.Options options)
throws IOException {
URI asUri = URI.create(request.url());
String clientName = asUri.getHost();
ZookeeperDependency dependencyForAlias =
DependencyFeignClientAutoConfiguration.this.zookeeperDependencies
.getDependencyForAlias(clientName);
Map<String, Collection<String>> headers = getUpdatedHeadersIfPossible(
request, dependencyForAlias);
if (DependencyFeignClientAutoConfiguration.this.ribbonClient != null) {
return DependencyFeignClientAutoConfiguration.this.ribbonClient.execute(
request(request, headers), options);
}
return super.execute(request(request, headers), options);
}
private Request request(Request request,
Map<String, Collection<String>> headers) {
return Request.create(request.method(), request.url(), headers,
request.body(), request.charset());
}
private Map<String, Collection<String>> getUpdatedHeadersIfPossible(
Request request, ZookeeperDependency dependencyForAlias) {
if (dependencyForAlias != null) {
return Collections.unmodifiableMap(new HashMap<>(
dependencyForAlias.getUpdatedHeaders(request.headers())));
}
return request.headers();
}
};
}
} I appreciate your giving me so much of your time,again! @ryanjbaxter |
I had import the httpcompent-client 4.5.2 pom.xml and had wirted the LoadBalancer like that:
and i had set the properties
feign.httpclient.enabled=true
i used the spring-boot 1.4.1 and spring-cloud Camden.SR7 and import the feign like that:
the maven dependency like that:
however,it throw expection like that:
The text was updated successfully, but these errors were encountered: