Feign客户端内部服务器异常(RestTemplate也不起作用)

huangapple go评论61阅读模式
英文:

feign client internal server exception (rest template didnt work either)

问题

上次我发布时出现了访问令牌错误。我还尝试过使用RestTemplate,但仍然出现相同的错误。

"timestamp": 1597323995055,
"status": 500,
"error": "Internal Server Error",
"message": "请求访问令牌时出错。",
"path": "/api/dashboard"
}

我的代码如下:

Controller.class

@RestController
@RequestMapping("/api/dashboard")
@AllArgsConstructor
public class LexcorpIntegrationController {
  private final TestServicee testServicee;

  @GetMapping
  public List<IncidentTasksResponse> getIT() {
    return testServicee.getFeign();
  }
}

这是Service.class

@Service
@AllArgsConstructor
public class TestServicee {
  private final LexcorpProxy proxy;
  private final RestTemplate restTemplate;

  public List<IncidentTasksResponse> getIT() {
    DateFilter dto = new DateFilter();
    dto.setDate(null);

    WrapperEntity wrapperEntity =
        restTemplate.getForObject(
            "http://im-sure-url-is-correct",
            WrapperEntity.class,
            dto);
    List<IncidentTasksResponse> tasks = wrapperEntity.getList();
    return tasks;
  }

  public List<IncidentTasksResponse> getFeign() {
    DateFilter filter = new DateFilter();
    filter.setDate(null);
    return proxy.getAllIncidentTasks(filter);
  }
}

Client.interface

@Component
@FeignClient(name = "lexcorp", url = "url-is-correct")
public interface LexcorpProxy {
  @PostMapping("/IncidentTasks")
  List<IncidentTasksResponse> getAllIncidentTasks(DateFilter date);
}

我想说的第一件事是,我使用第三方VPN来访问数据。但我写的另一段代码(2)可以正常工作,所以这不是问题所在。

1- 这是Spring Cloud,所以它从另一个微服务获取依赖项等。后来,我无论如何都在pom.xml中添加了依赖项。仍然没有起作用。

2- 尝试在我的本地创建一个简单的Feign应用程序(另一个应用程序也在我的本地)。它可以工作,我可以从API获取数据。

3- 我在客户端方法内部写的参数是正确的。

对所有答案表示感谢。我是否遗漏了什么?即使有一点解释也会帮助我。

英文:

The last time i've posted i got an accessing token error. I also tried with rest template ; still the same error.

&quot;timestamp&quot;: 1597323995055,
&quot;status&quot;: 500,
&quot;error&quot;: &quot;Internal Server Error&quot;,
&quot;message&quot;: &quot;Error requesting access token.&quot;,
&quot;path&quot;: &quot;/api/dashboard&quot;

}

My code looks like this;

Controller.class

@RestController
@RequestMapping(&quot;/api/dashboard&quot;)
@AllArgsConstructor
public class LexcorpIntegrationController {
  private final TestServicee testServicee;

  @GetMapping
  public List&lt;IncidentTasksResponse&gt; getIT() {
    return testServicee.getFeign();
  }

  /*

This is Service.class

@Service
@AllArgsConstructor
public class TestServicee {

  private final LexcorpProxy proxy;

  private final RestTemplate restTemplate;

  public List&lt;IncidentTasksResponse&gt; getIT() {
    DateFilter dto = new DateFilter();
    dto.setDate(null);

    WrapperEntity wrapperEntity =
        restTemplate.getForObject(
            &quot;http://im-sure-url-is-correct&quot;,
            WrapperEntity.class,
            dto);
    List&lt;IncidentTasksResponse&gt; tasks = wrapperEntity.getList();
    return tasks;
  }

  public List&lt;IncidentTasksResponse&gt; getFeign() {
    DateFilter filter = new DateFilter();
    filter.setDate(null);
    return proxy.getAllIncidentTasks(filter);
  }
}

Client.interface

@Component
@FeignClient(name = &quot;lexcorp&quot;, url = &quot;url-is-correct&quot;)
public interface LexcorpProxy {

  @PostMapping(&quot;/IncidentTasks&quot;)
  List&lt;IncidentTasksResponse&gt; getAllIncidentTasks(DateFilter date);
}

The first thing i wanna say is ; i use a 3rdPartyVpn to access data. But another code that i wrote (2)
worked so , thats not the case here.

1- This is Spring Cloud, so it gets dependencies from another microservice etc. Later , i added dependencies in pom.xml anyways.Still didnt work.

2- Try to create simple feign application in my local. (other one is also in my local anyways) It worked. I can get data from the api.

3- The parameter that i wrote inside the client method is correct.

All answers will be appreciated. Am i missing something? Even a lil explanation would help me.

答案1

得分: 0

我尝试了一切,但没有解决问题。我使用了我的其他应用程序。

英文:

I tried everything and didnt solve the problem. I used my other application instead.

huangapple
  • 本文由 发表于 2020年8月18日 16:32:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/63464771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定