从gwt调用Spring MicroService

时间:2018-10-31 08:00:16

标签: spring gwt microservices

我有一个GWT客户端,它需要调用Spring Boot MicroService。我认为这可能类似于调用Rest Web服务,但是有更好的方法吗?

1 个答案:

答案 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
}