我有一个使用Apache CXF库的简单REST客户端。以下是代码段:
val wc = WebClient.create(address(host, port) + "/" + resource).`type`("text/plain")
requestParam match {
case Some(reqParams) => reqParams.foreach((param: (String, String)) => {
wc.query(param._1, param._2)
})
case None => wc
}
println("Acturl url is " + wc.getCurrentURI)
wc.get(classOf[String])
}
我尝试获取的是一个名为test.txt的简单文件。我想将它渲染为一个普通的字符串,这就是我在上面代码片段的最后一行所做的。但是我收到以下错误:
javax.ws.rs.NotAuthorizedException was thrown.
javax.ws.rs.NotAuthorizedException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.cxf.jaxrs.client.AbstractClient.convertToWebApplicationException(AbstractClient.java:462)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:860)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:831)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:394)
at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:573)
如何将调用作为普通字符串返回给GET端点?
答案 0 :(得分:0)
我有点傻。我的原始代码实际上工作并返回了我想要的字符串!
wc.get(classOf[String])