@Test public void testConnectionThrowsUnexpected() throws Exception { Call call = mock(Call.class); when(httpClientMock.newCall(any())).thenReturn(call); when(call.execute()).thenThrow(new IOException("hey a penny")); expectedException.expect(LinkException.class); expectedException.expectMessage("hey a penny"); link.testConnection(); }
public void testConnection() { try { final Request okHttpRequest = this.constructSendPacketRequest(UNFULFILLABLE_PACKET); try (Response response = okHttpClient.newCall(okHttpRequest).execute()) { if (response.isSuccessful()) { boolean responseHasOctetStreamContentType = response.headers(CONTENT_TYPE).stream() .findFirst() .filter(OCTET_STREAM_STRING::equals) .isPresent(); if (responseHasOctetStreamContentType) { logger.info("Remote peer-link supports ILP-over-HTTP. url={} responseHeaders={}", outgoingUrl, response ); } else { logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. url={} " + "response={}", outgoingUrl, response ); } } else { if (response.code() == 406 || response.code() == 415) { throw new LinkException( String.format("Remote peer-link DOES NOT support ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } else { throw new LinkException( String.format("Unable to connect to ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } } } } catch (IOException e) { throw new LinkException(e.getMessage(), e, getLinkId()); } }
IlpOverHttpLink extends AbstractLink<IlpOverHttpLinkSettings> implements Link<IlpOverHttpLinkSettings> { public void testConnection() { try { final Request okHttpRequest = this.constructSendPacketRequest(UNFULFILLABLE_PACKET); try (Response response = okHttpClient.newCall(okHttpRequest).execute()) { if (response.isSuccessful()) { boolean responseHasOctetStreamContentType = response.headers(CONTENT_TYPE).stream() .findFirst() .filter(OCTET_STREAM_STRING::equals) .isPresent(); if (responseHasOctetStreamContentType) { logger.info("Remote peer-link supports ILP-over-HTTP. url={} responseHeaders={}", outgoingUrl, response ); } else { logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. url={} " + "response={}", outgoingUrl, response ); } } else { if (response.code() == 406 || response.code() == 415) { throw new LinkException( String.format("Remote peer-link DOES NOT support ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } else { throw new LinkException( String.format("Unable to connect to ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } } } } catch (IOException e) { throw new LinkException(e.getMessage(), e, getLinkId()); } } }
IlpOverHttpLink extends AbstractLink<IlpOverHttpLinkSettings> implements Link<IlpOverHttpLinkSettings> { public void testConnection() { try { final Request okHttpRequest = this.constructSendPacketRequest(UNFULFILLABLE_PACKET); try (Response response = okHttpClient.newCall(okHttpRequest).execute()) { if (response.isSuccessful()) { boolean responseHasOctetStreamContentType = response.headers(CONTENT_TYPE).stream() .findFirst() .filter(OCTET_STREAM_STRING::equals) .isPresent(); if (responseHasOctetStreamContentType) { logger.info("Remote peer-link supports ILP-over-HTTP. url={} responseHeaders={}", outgoingUrl, response ); } else { logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. url={} " + "response={}", outgoingUrl, response ); } } else { if (response.code() == 406 || response.code() == 415) { throw new LinkException( String.format("Remote peer-link DOES NOT support ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } else { throw new LinkException( String.format("Unable to connect to ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } } } } catch (IOException e) { throw new LinkException(e.getMessage(), e, getLinkId()); } } IlpOverHttpLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final HttpUrl outgoingUrl,
      final OkHttpClient okHttpClient,
      final ObjectMapper objectMapper,
      final CodecContext ilpCodecContext,
      final BearerTokenSupplier bearerTokenSupplier
  ); }
IlpOverHttpLink extends AbstractLink<IlpOverHttpLinkSettings> implements Link<IlpOverHttpLinkSettings> { public void testConnection() { try { final Request okHttpRequest = this.constructSendPacketRequest(UNFULFILLABLE_PACKET); try (Response response = okHttpClient.newCall(okHttpRequest).execute()) { if (response.isSuccessful()) { boolean responseHasOctetStreamContentType = response.headers(CONTENT_TYPE).stream() .findFirst() .filter(OCTET_STREAM_STRING::equals) .isPresent(); if (responseHasOctetStreamContentType) { logger.info("Remote peer-link supports ILP-over-HTTP. url={} responseHeaders={}", outgoingUrl, response ); } else { logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. url={} " + "response={}", outgoingUrl, response ); } } else { if (response.code() == 406 || response.code() == 415) { throw new LinkException( String.format("Remote peer-link DOES NOT support ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } else { throw new LinkException( String.format("Unable to connect to ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } } } } catch (IOException e) { throw new LinkException(e.getMessage(), e, getLinkId()); } } IlpOverHttpLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final HttpUrl outgoingUrl,
      final OkHttpClient okHttpClient,
      final ObjectMapper objectMapper,
      final CodecContext ilpCodecContext,
      final BearerTokenSupplier bearerTokenSupplier
  ); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); void testConnection(); @Override String toString(); HttpUrl getOutgoingUrl(); }
IlpOverHttpLink extends AbstractLink<IlpOverHttpLinkSettings> implements Link<IlpOverHttpLinkSettings> { public void testConnection() { try { final Request okHttpRequest = this.constructSendPacketRequest(UNFULFILLABLE_PACKET); try (Response response = okHttpClient.newCall(okHttpRequest).execute()) { if (response.isSuccessful()) { boolean responseHasOctetStreamContentType = response.headers(CONTENT_TYPE).stream() .findFirst() .filter(OCTET_STREAM_STRING::equals) .isPresent(); if (responseHasOctetStreamContentType) { logger.info("Remote peer-link supports ILP-over-HTTP. url={} responseHeaders={}", outgoingUrl, response ); } else { logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. url={} " + "response={}", outgoingUrl, response ); } } else { if (response.code() == 406 || response.code() == 415) { throw new LinkException( String.format("Remote peer-link DOES NOT support ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } else { throw new LinkException( String.format("Unable to connect to ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } } } } catch (IOException e) { throw new LinkException(e.getMessage(), e, getLinkId()); } } IlpOverHttpLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final HttpUrl outgoingUrl,
      final OkHttpClient okHttpClient,
      final ObjectMapper objectMapper,
      final CodecContext ilpCodecContext,
      final BearerTokenSupplier bearerTokenSupplier
  ); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); void testConnection(); @Override String toString(); HttpUrl getOutgoingUrl(); static final String LINK_TYPE_STRING; static final LinkType LINK_TYPE; }