0
我正在尝试使用JAX -WS来执行Web应用程序。我的问题似乎很简单,但我不明白如何解决它。我有我需要在GET和POST请求中使用的类变量。例如,我在GET方法中启动“响应”,然后我需要在POST方法中使用它,但是当我从js调用POST api/conversation时,我收到一个错误,因为'响应'仍然为空。我如何保存变量的值?这里是我的代码在JAX-WS请求之间使用变量
import javax.ws.rs.*;
@ApplicationPath("api")
@Path("conversation")
public class Conversation {
private final String conversationWorkspace = "myworkspace";
private final static String CONVERSATION_ID = "myid";
private final static String CONVERSATION_PASS = "mypass";
private MessageRequest request;
private MessageResponse response;
private ConversationService service;
@GET
@Produces("application/text")
public String getInitiatePhrase(){
service = new ConversationService("2017-05-26", CONVERSATION_ID, CONVERSATION_PASS);
response = service.message(conversationWorkspace, null).execute(); //here response gets its value
return response.getText().get(0);
}
@POST
@Produces("application/text")
@Consumes("application/text")
public String getBotAnswer(String userText){
System.out.println("response " + response);
request = new MessageRequest.Builder().inputText(userText).context(response.getContext()).build(); //response must not be null
response = service.message(conversationWorkspace, request).execute();
return response.getText().get(0);
}
}
我使用了1种方法,它工作。谢谢! – Tanya