程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Kumuluzee microprofile rest 客户端 - 无法在错误响应中获取响应正文大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Kumuluzee microprofile rest 客户端 - 无法在错误响应中获取响应正文?

开发过程中遇到Kumuluzee microprofile rest 客户端 - 无法在错误响应中获取响应正文的问题如何解决?下面主要结合日常开发的经验,给出你关于Kumuluzee microprofile rest 客户端 - 无法在错误响应中获取响应正文的解决方法建议,希望对你解决Kumuluzee microprofile rest 客户端 - 无法在错误响应中获取响应正文有所启发或帮助;

我正在尝试在 @R_685_4044@ 3.9.0 上运行的 java 应用程序中获取错误响应正文。我不知道,为什么无法从 http 状态为 4xx 的响应中获得响应。我试图通过将实体转换为 inputStream 并在循环中读取字节来获取响应正文,但没有返回任何字节。 IDE 调试器显示包含 byteArrayinputStrem 的实体。

感谢您的帮助。

@Path("/rest")
public interface MyClIEnt {

    @GET
    @Path("/{value}")
    @Consumes(MediaType.APPliCATION_JsON)
    MyResponse getValue(@PathParam("value") @R_674_10495@ng value);
@ApplicationScoped
public class MyRestClIEnt {
    
    private MyClIEnt clIEnt;

    @postconstruct
    public voID init() throws Exception{
        try {
            URI uri = new URI("http://localhost:8080/myservice/");
            
            clIEnt = RestClIEntBuilder.newBuilder()
                    .baseUri(uri)
                    .build(MyClIEnt.class);
            
        }catch(Exception E){
            log.error("",E);
            throw e;
        }
    }

    public @R_674_10495@ng getValue(@R_674_10495@ng data) {
        try {
            MyResponse myResponse = clIEnt.getMyResponse(@R_674_10495@ng data);
            if (myResponse != null) {
                return myResponse.getValue();  //this works perfectly
            }
        } catch(WebApplicationException E){
            Response response =  e.getResponse();  //in case of 4xx responses I cAnnot get response body

            if(response.hasEntity()){ //always return false,but response body is there 
                log.error("response body: " + response.getEntity());
            }
            Object entity = response.getEntity(); //IDE deBUG shows entity with bytearray in,but not able to read bytes programatically
            @R_674_10495@ng body = new BufferedReader(new inputStreamReader((FilterinputStream) e.getResponse().getEntity()))
                    .lines().collect(Collectors.joining("\n")); //does not work,returns empty @R_674_10495@ng
            @R_674_10495@ng body2 = response.readEntity(@R_674_10495@ng.class) //even this does not work
            log.error("Unable to response..",E);
        }catch (Exception E) {
            log.error("Unable to get response.",E);
        }
        return null;
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的Kumuluzee microprofile rest 客户端 - 无法在错误响应中获取响应正文全部内容,希望文章能够帮你解决Kumuluzee microprofile rest 客户端 - 无法在错误响应中获取响应正文所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。