Pergunta

(Aparentemente) simples método estático que invoca um bom serviço web.

Serviço retorna HTTP 500 / Erro Interno do Servidor se um registro correspondente não é encontrado, mas a recuperação do bloco de invokation nunca é executado.

Estou perdendo o óbvio, ou fazendo algo descaradamente estúpido?

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;
                }
              }
            );
}
Foi útil?

Solução

recover ajuda a recuperar a partir de uncaught exceções.Neste caso, um HTTP 500 resposta não resultar em uma não identificada Throwable

Presumivelmente, 500 significa que o bloco a seguir irá lançar um erro

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

No entanto, você tem esta envolto em um bloco catch tente já.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top