Domanda

(apparentemente) Metodo statico semplice che richiama un buon servizio web noto.

Servizio restituisce l'errore del server HTTP 500 / interno se non viene trovato un record corrispondente, ma il blocco di recupero dell'invocazione non viene mai eseguito.

Mi manca l'ovvio o facendo qualcosa di pallamente stupido?

public static Promise<Property> ByPhone(String phone) {
  return WS.url("http://localhost:9000/data/property/" + phone)
           .get ()
           .map (
              new Function<WS.Response, Property>() {
                public Property apply (WS.Response response) {
                  System.out.println("got here: " + response.getStatusText());
                  Property property = null;
                  try {
                    property = _mapper.readValue(response.getBody(), Property.class);
                  } catch (Throwable t) {
                    t.printStackTrace();
                  }
                  return property;
                }
              }
            ).recover (
              new Function<Throwable, Property>() {
                public Property apply (Throwable t) {
                  System.out.println("never get here");
                  t.printStackTrace();
                  return null;
                }
              }
            );
}
.

È stato utile?

Soluzione

recover aiuta a recuperare le eccezioni non rilevate.In questo caso, una risposta HTTP 500 non comporta un Throwable non rilevato

Presumibilmente, 500 significa che il seguente blocco lancerà un errore

property = _mapper.readValue(response.getBody(), Property.class);
.

Tuttavia, hai già questo avvolto in un blocco Try Catch.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top