我有一个GWT客户端,它需要调用Spring Boot MicroService。我认为这可能类似于调用Rest Web服务,但是有更好的方法吗?
答案 0 :(得分:2)
您可能可以使用RequestBuilder
从GWT应用程序的客户端调用API:
import com.google.gwt.http.client.RequestBuilder;
// ....
try {
new RequestBuilder(
RequestBuilder.GET, // GET, POST, etc.
url // url of your microservice endpoint
).sendRequest(null, new RequestCallback() { // replace null with your req body if needed
@Override
public void onResponseReceived(Request req, Response resp) {
// Parse resp.getText() which is hopefully a JSON string
}
@Override
public void onError(Request res, Throwable throwable) {
// handle errors
}
});
} catch (RequestException e) {
// log, rethrow... the usual
}