我正在从WebServiceMessageCallback中提取HTTP响应,但是当我尝试更新回调之外的变量时,我得到:不能引用在另一个方法中定义的内部类中的非final变量rawResponse“
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();*/
答案 0 :(得分:0)
你真的应该使用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());