首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Jersey2.25.1在post方法中设置ByteArrayInputStream

使用Jersey2.25.1在post方法中设置ByteArrayInputStream
EN

Stack Overflow用户
提问于 2017-03-31 14:32:17
回答 1查看 357关注 0票数 0

我一直试图使用jersey2.25.1编写以下代码,但我不知道在实体中传递什么。有人能帮我弄清楚这一点吗?因为没有实体,在球衣2.25.1中,post方法考虑实体,考虑哪个实体和媒体类型。

使用jersey 1.13的现有代码

代码语言:javascript
复制
WebResource resourceGetToken = client.createResource( ESignatureSpringUtil.getMessage( KeyConstants.ALSB_DOCUSIGN_ADDRESS )
                            + ESignatureSpringUtil.getMessage( KeyConstants.REST_GET_TOKEN_ADDRESS) );

                    ClientResponse tokenResponse = resourceGetToken
                        .header( KeyConstants.REST_URI_APPENDERS, tokenSb )
                        .header( DocusignRESTContants.CONTENT_TYPE, DocusignRESTContants.APPLICATION_XML )
                        .header( DocusignRESTContants.X_DOCUSIGN_AUTHENTICATION, getDocusignAuthHeader( cu ) )
                        .accept( MediaType.APPLICATION_XML )
                        .post( ClientResponse.class, new ByteArrayInputStream( tokenStream.toString().getBytes() ) );

                    if ( tokenResponse.getStatus() == 200 ) {
                        RetrieveTokenResponse tokenResp = (RetrieveTokenResponse) tokenResponse.getEntity(RetrieveTokenResponse.class);

泽西岛2.25.1

代码语言:javascript
复制
WebTarget resourceGetToken = client.createResource( ESignatureSpringUtil.getMessage( KeyConstants.ALSB_DOCUSIGN_ADDRESS )
                            + ESignatureSpringUtil.getMessage( KeyConstants.REST_GET_TOKEN_ADDRESS) );

                    Invocation.Builder invcocationBuilder = resourceGetToken.request()
                            .header( KeyConstants.REST_URI_APPENDERS, tokenSb )
                            .header( DocusignRESTContants.CONTENT_TYPE, DocusignRESTContants.APPLICATION_XML )
                            .header( DocusignRESTContants.X_DOCUSIGN_AUTHENTICATION, getDocusignAuthHeader( cu ) )
                            .accept( MediaType.APPLICATION_XML );

                    Response tokenResponse = invcocationBuilder.post( Entity.entity(entity, mediaType));

我需要获得字节流,重载的post方法不允许我这样做。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-31 17:26:22

我就是这样做的。

代码语言:javascript
复制
Response response = builder.put( Entity.entity( new ByteArrayInputStream( jsonObj.toString().getBytes() ), MediaType.APPLICATION_XML ), Response.class );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43143274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档