@Test public void testNameFederationNotFound() throws IOException { mockWebServer.enqueue( new MockResponse() .setResponseCode(404) .setBody(notFoundResponse) ); try { FederationResponse response = server.resolveAddress("bob*stellar.org"); fail("Expected exception"); } catch (NotFoundException e) { } }
public FederationResponse resolveAddress(String address) { String[] tokens = address.split("\\*"); if (tokens.length != 2) { throw new MalformedAddressException(); } URL uri = HttpUrl.parse(serverUri.toString()).newBuilder() .addQueryParameter("type", "name") .addQueryParameter("q", address) .build().url(); TypeToken type = new TypeToken<FederationResponse>() { }; ResponseHandler<FederationResponse> responseHandler = new ResponseHandler<FederationResponse>(httpClient, type); Request request = new Request.Builder() .url(uri.toString()) .get() .build(); try { Response response = httpClient.newCall(request) .execute(); return responseHandler.handleResponse(response); } catch (HttpResponseException e) { if (e.getStatusCode() == 404) { throw new NotFoundException(); } else { throw new ServerErrorException(); } } catch (IOException e) { throw new ConnectionErrorException(); } }
FederationServer { public FederationResponse resolveAddress(String address) { String[] tokens = address.split("\\*"); if (tokens.length != 2) { throw new MalformedAddressException(); } URL uri = HttpUrl.parse(serverUri.toString()).newBuilder() .addQueryParameter("type", "name") .addQueryParameter("q", address) .build().url(); TypeToken type = new TypeToken<FederationResponse>() { }; ResponseHandler<FederationResponse> responseHandler = new ResponseHandler<FederationResponse>(httpClient, type); Request request = new Request.Builder() .url(uri.toString()) .get() .build(); try { Response response = httpClient.newCall(request) .execute(); return responseHandler.handleResponse(response); } catch (HttpResponseException e) { if (e.getStatusCode() == 404) { throw new NotFoundException(); } else { throw new ServerErrorException(); } } catch (IOException e) { throw new ConnectionErrorException(); } } }
FederationServer { public FederationResponse resolveAddress(String address) { String[] tokens = address.split("\\*"); if (tokens.length != 2) { throw new MalformedAddressException(); } URL uri = HttpUrl.parse(serverUri.toString()).newBuilder() .addQueryParameter("type", "name") .addQueryParameter("q", address) .build().url(); TypeToken type = new TypeToken<FederationResponse>() { }; ResponseHandler<FederationResponse> responseHandler = new ResponseHandler<FederationResponse>(httpClient, type); Request request = new Request.Builder() .url(uri.toString()) .get() .build(); try { Response response = httpClient.newCall(request) .execute(); return responseHandler.handleResponse(response); } catch (HttpResponseException e) { if (e.getStatusCode() == 404) { throw new NotFoundException(); } else { throw new ServerErrorException(); } } catch (IOException e) { throw new ConnectionErrorException(); } } FederationServer(URL serverUri, String domain);  FederationServer(String serverUri, String domain); }
FederationServer { public FederationResponse resolveAddress(String address) { String[] tokens = address.split("\\*"); if (tokens.length != 2) { throw new MalformedAddressException(); } URL uri = HttpUrl.parse(serverUri.toString()).newBuilder() .addQueryParameter("type", "name") .addQueryParameter("q", address) .build().url(); TypeToken type = new TypeToken<FederationResponse>() { }; ResponseHandler<FederationResponse> responseHandler = new ResponseHandler<FederationResponse>(httpClient, type); Request request = new Request.Builder() .url(uri.toString()) .get() .build(); try { Response response = httpClient.newCall(request) .execute(); return responseHandler.handleResponse(response); } catch (HttpResponseException e) { if (e.getStatusCode() == 404) { throw new NotFoundException(); } else { throw new ServerErrorException(); } } catch (IOException e) { throw new ConnectionErrorException(); } } FederationServer(URL serverUri, String domain);  FederationServer(String serverUri, String domain); static FederationServer createForDomain(String domain); FederationResponse resolveAddress(String address); URL getServerUri(); String getDomain(); }
FederationServer { public FederationResponse resolveAddress(String address) { String[] tokens = address.split("\\*"); if (tokens.length != 2) { throw new MalformedAddressException(); } URL uri = HttpUrl.parse(serverUri.toString()).newBuilder() .addQueryParameter("type", "name") .addQueryParameter("q", address) .build().url(); TypeToken type = new TypeToken<FederationResponse>() { }; ResponseHandler<FederationResponse> responseHandler = new ResponseHandler<FederationResponse>(httpClient, type); Request request = new Request.Builder() .url(uri.toString()) .get() .build(); try { Response response = httpClient.newCall(request) .execute(); return responseHandler.handleResponse(response); } catch (HttpResponseException e) { if (e.getStatusCode() == 404) { throw new NotFoundException(); } else { throw new ServerErrorException(); } } catch (IOException e) { throw new ConnectionErrorException(); } } FederationServer(URL serverUri, String domain);  FederationServer(String serverUri, String domain); static FederationServer createForDomain(String domain); FederationResponse resolveAddress(String address); URL getServerUri(); String getDomain();  }