@Test public void submit() throws Exception { JsonObject result = new JsonObject(); result.addProperty("status", "waiting"); result.addProperty("jrid", "testing"); JsonHandler handler = new JsonHandler(result); server.register("/jobs/testing/execute", handler); HttpJobClient client = new HttpJobClient(baseUrl); client.submit(new JobId("testing")); assertThat(handler.requestElement, is(nullValue())); }
@Override public void submit(JobId id) throws IOException, InterruptedException { if (id == null) { throw new IllegalArgumentException("id must not be null"); } HttpPut request = new HttpPut(); URI uri = createUri(String.format("jobs/%s/execute", id.getToken())); request.setURI(uri); if (LOG.isDebugEnabled()) { LOG.debug("Submitting job: method=put, uri={}", uri); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } else { throw toException(request, response, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } }
HttpJobClient implements JobClient { @Override public void submit(JobId id) throws IOException, InterruptedException { if (id == null) { throw new IllegalArgumentException("id must not be null"); } HttpPut request = new HttpPut(); URI uri = createUri(String.format("jobs/%s/execute", id.getToken())); request.setURI(uri); if (LOG.isDebugEnabled()) { LOG.debug("Submitting job: method=put, uri={}", uri); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } else { throw toException(request, response, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } }
HttpJobClient implements JobClient { @Override public void submit(JobId id) throws IOException, InterruptedException { if (id == null) { throw new IllegalArgumentException("id must not be null"); } HttpPut request = new HttpPut(); URI uri = createUri(String.format("jobs/%s/execute", id.getToken())); request.setURI(uri); if (LOG.isDebugEnabled()) { LOG.debug("Submitting job: method=put, uri={}", uri); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } else { throw toException(request, response, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } HttpJobClient(String baseUri);  HttpJobClient(String baseUri, String user, String password); }
HttpJobClient implements JobClient { @Override public void submit(JobId id) throws IOException, InterruptedException { if (id == null) { throw new IllegalArgumentException("id must not be null"); } HttpPut request = new HttpPut(); URI uri = createUri(String.format("jobs/%s/execute", id.getToken())); request.setURI(uri); if (LOG.isDebugEnabled()) { LOG.debug("Submitting job: method=put, uri={}", uri); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } else { throw toException(request, response, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } HttpJobClient(String baseUri);  HttpJobClient(String baseUri, String user, String password); String getBaseUri(); String getUser(); @Override JobId register(JobScript script); @Override JobStatus getStatus(JobId id); @Override void submit(JobId id); @Override String toString(); }
HttpJobClient implements JobClient { @Override public void submit(JobId id) throws IOException, InterruptedException { if (id == null) { throw new IllegalArgumentException("id must not be null"); } HttpPut request = new HttpPut(); URI uri = createUri(String.format("jobs/%s/execute", id.getToken())); request.setURI(uri); if (LOG.isDebugEnabled()) { LOG.debug("Submitting job: method=put, uri={}", uri); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } else { throw toException(request, response, MessageFormat.format( "Failed to submit job: {0} ({1})", id.getToken(), request.getURI())); } } HttpJobClient(String baseUri);  HttpJobClient(String baseUri, String user, String password); String getBaseUri(); String getUser(); @Override JobId register(JobScript script); @Override JobStatus getStatus(JobId id); @Override void submit(JobId id); @Override String toString();  }