Java 回调外部的Spring WS客户端更新变量
我正在从WebServiceMessageCallback提取HTTP响应,但是当我尝试更新回调外部的变量时,我得到:不能在另一个方法中定义的内部类中引用非最终变量rawResponseJava 回调外部的Spring WS客户端更新变量,java,spring,soap,callback,spring-ws,Java,Spring,Soap,Callback,Spring Ws,我正在从WebServiceMessageCallback提取HTTP响应,但是当我尝试更新回调外部的变量时,我得到:不能在另一个方法中定义的内部类中引用非最终变量rawResponse String rawResponse=null; try { this.webserviceTemplate.sendSourceAndReceiveToResult(source, new WebServiceMessageCallback() { @
String rawResponse=null;
try {
this.webserviceTemplate.sendSourceAndReceiveToResult(source,
new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message)
throws IOException, TransformerException {
TransportContext context = TransportContextHolder.getTransportContext();
CommonsHttpConnection connection = (CommonsHttpConnection )context.getConnection();
context.getConnection();
rawResponse = connection.getPostMethod().getResponseBodyAsString();*/
您真的应该使用final变量来完成。AtomicReference是为您准备的:
final AtimicReference<String> rawResponse = new AtimicReference<String>();
try {
this.webserviceTemplate.sendSourceAndReceiveToResult(source,
new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message)
throws IOException, TransformerException {
...
rawResponse.set(connection.getPostMethod().getResponseBodyAsString());