【发布时间】:2016-12-14 11:38:02
【问题描述】:
我正在尝试将 Google 的 Firebase 消息传递平台绑定到我的应用程序中,并且我正在尝试使用 Spring 内置的 RestTemplate REST 抽象来简化它。
我目前正在尝试:
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", "key=" + Constants.FIREBASE_SERVER_KEY);
headers.add("Content-Type", "application/json");
HttpEntity<FireBasePost> entity = new HttpEntity<>(fbp, headers);
URI uri;
uri = new URI(firebaseApi);
FireBaseResponse fbr = restTemplate.postForObject(uri, entity, FireBaseResponse.class);
FireBasePost 对象仅包含 POST 消息 API 的必需字段:Firebase API - 我已通过使用 String.class 发布验证了请求实体是否有效,因此响应是未编组的 JSON。
但是,在尝试将 marshall 的响应直接发送到 FireBaseResponse 对象时,对 postForObject 的调用会挂起并且永远不会返回。
@JsonIgnoreProperties(ignoreUnknown = true)
public class FireBaseResponse {
public Integer multicast_id;
public Integer success;
public Integer failure;
public Integer canonical_ids;
public FireBaseResponse() {}
}
我无法理解为什么这个调用永远不会完成。我希望能够将响应直接放入对象中。
【问题讨论】:
-
我相信
FireBaseResponse属性名称不符合正确的约定。尝试使用骆驼案例名称(multicastId、canonicalIds等:.)。您能否发布您的 Firebase 回复? -
您能否处理在客户端收到的这些通知?例如,在
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> ())委托中? -
你可以查看这个答案stackoverflow.com/a/51172021/3073945
标签: java spring spring-boot resttemplate firebase-cloud-messaging