use of com.google.api.client.http.HttpResponseException in project providence by morimekta.
the class HttpClientHandlerNetworkTest method testBrokenPipe_NetHttpTransport.
@Test
public void testBrokenPipe_NetHttpTransport() throws Failure {
HttpRequestFactory factory = new NetHttpTransport().createRequestFactory();
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint, factory, provider));
try {
// The request must be larger than the socket read buffer, to force it to fail the write to socket.
client.test(new Request(Strings.times("request ", 1024 * 1024)));
fail("No exception");
} catch (HttpResponseException e) {
fail("When did this become a HttpResponseException?");
} catch (IOException ex) {
// TODO: This should be a HttpResponseException
assertThat(ex.getMessage(), is("Error writing request body to server"));
}
}
use of com.google.api.client.http.HttpResponseException in project providence by morimekta.
the class HttpClientHandlerTest method testSimpleRequest_404_notFound.
@Test
public void testSimpleRequest_404_notFound() throws IOException, Failure, TException {
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::notfound, factory(), provider, instrumentation));
try {
client.test(new Request("request"));
fail("No exception");
} catch (HttpResponseException ex) {
assertThat(ex.getStatusCode(), is(404));
assertThat(ex.getStatusMessage(), is("Not Found"));
}
verify(instrumentation).onTransportException(any(HttpResponseException.class), anyDouble(), any(PServiceCall.class), isNull());
verifyNoMoreInteractions(impl, instrumentation);
}
use of com.google.api.client.http.HttpResponseException in project providence by morimekta.
the class HttpClientHandlerTest method testSimpleRequest_405_notSupported.
@Test
public void testSimpleRequest_405_notSupported() throws IOException, Failure, TException {
GenericUrl url = endpoint();
url.setRawPath("/does_not_exists");
TestService.Iface client = new TestService.Client(new HttpClientHandler(() -> url, factory(), provider, instrumentation));
try {
client.test(new Request("request"));
fail("No exception");
} catch (HttpResponseException ex) {
assertThat(ex.getStatusCode(), is(405));
assertThat(ex.getStatusMessage(), is("HTTP method POST is not supported by this URL"));
}
verify(instrumentation).onTransportException(any(HttpResponseException.class), anyDouble(), any(PServiceCall.class), isNull());
verifyNoMoreInteractions(impl, instrumentation);
}
use of com.google.api.client.http.HttpResponseException in project providence by morimekta.
the class RPC method run.
@SuppressWarnings("unchecked")
void run(String... args) {
try {
ArgumentParser cli = options.getArgumentParser("pvdrpc", "Providence RPC Tool");
try {
cli.parse(args);
if (options.showHelp()) {
System.out.println("Providence RPC Tool - " + getVersionString());
System.out.println("Usage: " + cli.getSingleLineUsage());
System.out.println();
System.out.println("Example code to run:");
System.out.println("$ cat call.json | pvdrpc -I thrift/ -s cal.Calculator http://localhost:8080/service");
System.out.println("$ pvdrpc -i binary,file:my.data -f json_protocol -I thrift/ -s cal.Calculator http://localhost:8080/service");
System.out.println();
cli.printUsage(System.out);
System.out.println();
System.out.println("Available formats are:");
for (Format format : Format.values()) {
System.out.println(String.format(" - %-20s : %s", format.name(), format.desc));
}
return;
} else if (options.showVersion()) {
System.out.println("Providence RPC Tool - " + getVersionString());
return;
}
cli.validate();
MessageReader in = options.getInput();
MessageWriter out = options.getOutput();
PService service = options.getDefinition();
PServiceCallHandler handler = options.getHandler();
PServiceCall call = in.read(service);
in.close();
PServiceCall resp = handler.handleCall(call, service);
out.write(resp);
out.separator();
out.close();
if (options.out.base64mime && options.out.file == null) {
System.out.println();
}
return;
} catch (ConnectException e) {
System.out.flush();
System.err.format("Unable to connect to %s: %s%n", options.endpoint, e.getMessage());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (HttpResponseException e) {
System.out.flush();
System.err.println("Received " + e.getStatusCode() + " " + e.getStatusMessage());
System.err.println(" - from: " + options.endpoint);
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (ArgumentException e) {
System.out.flush();
System.err.println(e.getMessage());
System.err.println("Usage: " + cli.getSingleLineUsage());
System.err.println();
System.err.println("Run $ pvdrpc --help # for available options.");
} catch (SerializerException e) {
System.out.flush();
System.err.println("Serializer error: " + e.asString());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (UncheckedIOException | IOException e) {
System.out.flush();
System.err.println("I/O error: " + e.getMessage());
if (options.verbose()) {
System.out.flush();
e.printStackTrace();
}
} catch (IllegalArgumentException e) {
System.out.flush();
System.err.println("Internal Error: " + e.getMessage());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
}
} catch (RuntimeException | IOException e) {
System.out.flush();
System.err.println("Unchecked exception: " + e.getMessage());
if (options.verbose()) {
System.out.flush();
e.printStackTrace();
}
}
System.err.flush();
exit(1);
}
use of com.google.api.client.http.HttpResponseException in project google-api-java-client by google.
the class MediaHttpDownloaderTest method testDownloadClientError.
public void testDownloadClientError() throws Exception {
int contentLength = MediaHttpDownloader.MAXIMUM_CHUNK_SIZE * 2;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
MediaTransport fakeTransport = new MediaTransport(contentLength);
fakeTransport.testClientError = true;
MediaHttpDownloader downloader = new MediaHttpDownloader(fakeTransport, null);
try {
downloader.download(new GenericUrl(TEST_REQUEST_URL), outputStream);
fail("Expected " + HttpResponseException.class);
} catch (HttpResponseException e) {
// Expected
}
// There should be only 1 call made: 1 download request that returned a 404.
assertEquals(1, fakeTransport.lowLevelExecCalls);
}
Aggregations