Java 传输另一个Api响应的Api

Java 传输另一个Api响应的Api,java,xml,spring,api,unmarshalling,Java,Xml,Spring,Api,Unmarshalling,我和我的团队正在使用GWT2.4(JDK1.6.0_45)开发一些古老但相当大的应用程序 我们目前面临一个使用HTTP协议的问题。他们最近切换到HTTPS,而Java6(免费版本)并没有很好地使用HTTPS 我有多种解决方案: 升级到可维护但不是免费的Java 6版本(我们希望避免付费) 升级到Java 8(GWT 2.4与Java 8不兼容,因此我们还必须升级到GWT 2.8,考虑到应用程序的大小,这需要一些时间) 开发一个小Api来捕获这个公共Api的响应,并使用HTTP协议将其发送回我的

我和我的团队正在使用GWT2.4(JDK1.6.0_45)开发一些古老但相当大的应用程序

我们目前面临一个使用HTTP协议的问题。他们最近切换到HTTPS,而Java6(免费版本)并没有很好地使用HTTPS

我有多种解决方案:

  • 升级到可维护但不是免费的Java 6版本(我们希望避免付费)
  • 升级到Java 8(GWT 2.4与Java 8不兼容,因此我们还必须升级到GWT 2.8,考虑到应用程序的大小,这需要一些时间)
  • 开发一个小Api来捕获这个公共Api的响应,并使用HTTP协议将其发送回我的应用程序
我启动了第三个解决方案,但在对收到的响应(xml)进行解组时遇到了一些问题

以下是我到目前为止所做的:

调用公共API的My API方法:

@Override
public ResponseEntity<WorkMetadataType> lookupWithFilter(String authorization, String filter, String id, Optional<String> accept, Optional<String> xISANAuthorization, Optional<String> idtype) {
    WorkMetadataType res = isanApi.lookupWithFilter(authorization, filter, id, accept.orElse(null), xISANAuthorization.orElse(null), idtype.orElse(null));
    if (res == null) {
        throw new WorkNotFoundException();
    }
    return ResponseEntity.ok(res);
}
@覆盖
public ResponseEntity lookupWithFilter(字符串授权、字符串筛选器、字符串id、可选接受、可选xISANAuthorization、可选idtype){
WorkMetadataType res=isanApi.lookupWithFilter(授权、筛选器、id、accept.orElse(null)、xISANAuthorization.orElse(null)、idtype.orElse(null));
如果(res==null){
抛出新的WorkNotFoundException();
}
返回响应度ok(res);
}
调用公共API的方法

public WorkMetadataType lookupWithFilter(String authorization, String filter, String id, String accept, String xISANAuthorization, String idtype) {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(getHttpClient()));
    try {
        CustomMarshallingHttpMessageConverter converter;
        converter = new CustomMarshallingHttpMessageConverter(JAXBContext.newInstance(ISANDataType.class));
        converter.setDefaultCharset(StandardCharsets.UTF_8);
        restTemplate.getMessageConverters().add(converter);
    } catch (JAXBException e) {
        logger.error("Erreur lors de la définition du marshaller", e);
    }
    HttpEntity<String> entity = new HttpEntity<>(null, getHeaders(authorization, accept, xISANAuthorization));

    return restTemplate.exchange(getRequestUri(id, idtype, filter), HttpMethod.GET, entity, WorkMetadataType.class).getBody();
}
public WorkMetadataType lookupWithFilter(字符串授权、字符串筛选器、字符串id、字符串接受、字符串XISA授权、字符串idtype){
RestTemplate RestTemplate=新RestTemplate();
setRequestFactory(新的HttpComponentsClientHttpRequestFactory(getHttpClient());
试一试{
自定义MarshallingHttpMessageConverter转换器;
converter=新的CustomMarshallingHttpMessageConverter(JAXBContext.newInstance(isAndAtType.class));
converter.setDefaultCharset(StandardCharsets.UTF_8);
restemplate.getMessageConverters().add(converter);
}捕获(JAXBEException e){
错误(“马歇尔定义错误”,e);
}
HttpEntity实体=新的HttpEntity(null,getHeaders(授权、接受、xISANAuthorization));
返回restemplate.exchange(getRequestUri(id,idtype,filter),HttpMethod.GET,entity,WorkMetadataType.class);
}
如您所见,我正在使用Spring和他的RestTemplate类。问题是,您需要指定响应的性质,因为我的解组问题,我希望避免这种性质


我的问题是:当我的API接收到响应时,是否可以在不使用它的情况下将该公共API的响应传输到我的应用程序?(简单地说,复制/粘贴它)

我最终使用了一个HttpCliendBuilder来构建我的请求,并获得一个InputStream作为响应。
通过这种方式,我可以将其转换为字符串并使用它创建响应。

与您的问题没有直接关系,但如果您将授权或其他敏感数据传递给api,您可能真的想升级到https。哪个Java 6(免费版本)令人遗憾的是…如果您使用
资源
作为请求的目标类,那么它有一个
getInputStream()
方法(如果它
isReadable()
),您可以使用该方法直接向上传输接收到的数据(假设您在
restemplate
上注册了
ResourceHttpMessageConverter
)。在应用程序(ngix,apache httpd)前面放置一些东西,它可以处理SSL/HTTPS内容,并在内部使用http。@M.Deinum,它确实可以快得多。我从来没有使用过它们,所以我会朝这个方向挖掘一点,thx。