![](/img/trans.png)
[英]CXF web service works correctly, but I can't get its wsdl from the cxf web site
[英]Can't read or parse Plain String Response from CXF REST Web Service in Java
REST服务已在SpringMVC中正确实现,部署并返回正确的结果字符串,
@RestController
public class RESTServiceController {
@GET
@Produces("application/json")
@RequestMapping("/restUrl")
public String getResult() {
JSONObject json = new JSONObject();
json.put("result", Boolean.TRUE);
}
}
测试此Web服务时,我得到正确的输出,
{"result":true}
问题是调用者通过CXF获取Response对象,但是我不知道如何解析Response。 我不需要自定义对象。 我需要的只是直接字符串,我只想查看我的输出字符串。
String restServiceURI = "http://www.asite.com/restUrl";
WebClient client = WebClient.create(restServiceURI,true);
Response resp = client.get();
//String entity = (String)resp.getEntity; <-- Also tried this to cast to a string
问题是,响应长度为0,状态为EmptyInputStream
getEntity InputStream
根据调试器显示的内容带回EmptyInputStream
。
Response对象没有我可以在调试器中看到的任何信息。
我怎样才能找回我的直接字符串? 有例子吗?
您正在尝试混合使用Spring Rest和CxF rest。 使用Spring Rest或CXF Rest。
如果您想使用Spring Rest,如下所示
@Service
public class RESTServiceController {
@RequestMapping("/restUrl")
public @ResponseBody MyClass getResult() {
return myClass;
}
}
或CXF,如下所示。
@Service
public class RESTServiceController {
@GET
@Produces("application/json")
public MyClass getResult() {
return myClass;
}
}
注意:您无需显式使用json转换,Spring Rest和CXF都必须具有将对象转换为json字符串的功能。
但是,您的问题并不仅限于此,我相信您已启用spring-security,该安全性通过登录页面发送redirect(302)响应。 您可以通过启用客户端登录来验证来自服务器的响应。
WebClient.getConfig(client).getInInterceptors().add(new LoggingInInterceptor());
WebClient.getConfig(client).getOutInterceptors().add(new LoggingOutInterceptor());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.