private void put(final HttpPut put) throws IOException { logger.info(String.format("Writing to \"%s\".", put.getURI())); try (final CloseableHttpResponse response = client.execute(put)) { final int code = response.getStatusLine().getStatusCode(); if (code < 200 || code >= 300) { throw new TaggedIOException(new IOException(String.format("Unexpected response code: %d", code)), this); } } } }
public CouchPutRequest(HttpPut request) { this.request = request; uri = new CouchURI(request.getURI()); }
@Override public void submit(JobId id) throws IOException, InterruptedException { if (id == null) { throw new IllegalArgumentException("id must not be null"); //$NON-NLS-1$ } 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())); } }
LOGGER.info(String.format(" HTTP POST URI: %s", httpPut.getURI().toString())); LOGGER.info(String.format(" HTTP POST Headers: %s", Arrays.toString(httpPut.getAllHeaders()))); LOGGER.info(String.format(" HTTP POST Entity Content:%n%s", sw.toString()));
LOGGER.info(String.format(" HTTP POST URI: %s", httpPut.getURI().toString())); LOGGER.info(String.format(" HTTP POST Headers: %s", Arrays.toString(httpPut.getAllHeaders()))); LOGGER.info(String.format(" HTTP POST Entity Content:%n%s", sw.toString()));
Credentials c = new UsernamePasswordCredentials(userInfo); clientContext.getCredentialsProvider().setCredentials( new AuthScope(putRequest.getURI().getHost(), putRequest .getURI().getPort()), c); lastResponseEncoding = "plaintext"; final String responseBody = requestValidator.decodeMessage(putRequest.getURI().getPath(), response); // limiting to 16MB, should be way enough if (logger.isDebugEnabled()) { logger.debug("ping: response body=" + responseBody);
@Override protected void implPut( PutTask task ) throws Exception { PutTaskEntity entity = new PutTaskEntity( task ); HttpPut request = commonHeaders( entity( new HttpPut( resolve( task ) ), entity ) ); try { execute( request, null ); } catch ( HttpResponseException e ) { if ( e.getStatusCode() == HttpStatus.SC_EXPECTATION_FAILED && request.containsHeader( HttpHeaders.EXPECT ) ) { state.setExpectContinue( false ); request = commonHeaders( entity( new HttpPut( request.getURI() ), entity ) ); execute( request, null ); return; } throw e; } }