List of usage examples for org.apache.http.client.fluent Request Put
public static Request Put(final String uri)
From source file:com.helger.peppol.bdxrclient.BDXRClient.java
/** * Saves a service meta data object. The ServiceGroupReference value is * ignored./* w ww .ja v a 2 s . c o m*/ * * @param aServiceMetadata * The service meta data object to save. * @param aCredentials * The user name and password to use as aCredentials. * @throws SMPClientException * in case something goes wrong * @throws SMPClientUnauthorizedException * The user name or password was not correct. * @throws SMPClientNotFoundException * A HTTP Not Found was received. This can happen if the service was * not found. * @throws SMPClientBadRequestException * The request was not well formed. */ public void saveServiceRegistration(@Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException { ValueEnforcer.notNull(aServiceMetadata, "ServiceMetadata"); ValueEnforcer.notNull(aServiceMetadata.getServiceInformation(), "ServiceMetadata.ServiceInformation"); ValueEnforcer.notNull(aServiceMetadata.getServiceInformation().getParticipantIdentifier(), "ServiceMetadata.ServiceInformation.ParticipantIdentifier"); ValueEnforcer.notNull(aServiceMetadata.getServiceInformation().getDocumentIdentifier(), "ServiceMetadata.ServiceInformation.DocumentIdentifier"); ValueEnforcer.notNull(aCredentials, "Credentials"); final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation(); final IParticipantIdentifier aServiceGroupID = aServiceInformation.getParticipantIdentifier(); final IDocumentTypeIdentifier aDocumentTypeID = aServiceInformation.getDocumentIdentifier(); try { final String sBody = new BDXRMarshallerServiceMetadataType().getAsXMLString(aServiceMetadata); final Request aRequest = Request .Put(getSMPHostURI() + IdentifierHelper.getIdentifierURIPercentEncoded(aServiceGroupID) + "/services/" + IdentifierHelper.getIdentifierURIPercentEncoded(aDocumentTypeID)) .addHeader(CHTTPHeader.AUTHORIZATION, aCredentials.getRequestValue()) .bodyString(sBody, CONTENT_TYPE_TEXT_XML); executeRequest(aRequest).handleResponse(new SMPHttpResponseHandlerWriteOperations()); } catch (final Exception ex) { throw getConvertedException(ex); } }
From source file:com.softinstigate.restheart.integrationtest.SecurityIT.java
@Test public void testPutAsPowerUser() throws Exception { try {/* w w w .j av a 2 s . c o m*/ // *** PUT root Response resp = user1Executor.execute(Request.Put(rootUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put root as user1", resp, HttpStatus.SC_UNAUTHORIZED); // *** PUT db resp = user1Executor.execute(Request.Put(dbUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db as user1", resp, HttpStatus.SC_UNAUTHORIZED); // *** PUT tmpdb resp = user1Executor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db as user1", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = user1Executor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1 as user1", resp, HttpStatus.SC_CREATED); // *** PUT doc1 resp = user1Executor.execute(Request.Put(documentTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put doc1 as user1", resp, HttpStatus.SC_CREATED); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.restheart.test.integration.SecurityIT.java
@Test public void testPutAsPowerUser() throws Exception { try {//from www .j a v a 2 s .c o m // *** PUT root Response resp = user1Executor.execute(Request.Put(rootUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put root as user1", resp, HttpStatus.SC_FORBIDDEN); // *** PUT db resp = user1Executor.execute(Request.Put(dbUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db as user1", resp, HttpStatus.SC_FORBIDDEN); // *** PUT tmpdb resp = user1Executor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db as user1", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = user1Executor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1 as user1", resp, HttpStatus.SC_CREATED); // *** PUT doc1 resp = user1Executor.execute(Request.Put(documentTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put doc1 as user1", resp, HttpStatus.SC_CREATED); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.restheart.test.integration.SecurityIT.java
@Test public void testPathPefixAndRegexPredicates() throws Exception { // *** create dbs Response resp = user2Executor.execute(Request.Put(dbTmpUri2).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check create " + dbTmpName2 + " as user2", resp, HttpStatus.SC_CREATED); resp = user2Executor.execute(Request.Put(dbTmpUri3).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check create " + dbTmpName3 + " as user2", resp, HttpStatus.SC_CREATED); // *** create user collection resp = user2Executor.execute(Request.Put(collectionTmpUserUri2).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check path predicate creating user collection " + collectionTmpUserUri2 + " as user2", resp, HttpStatus.SC_CREATED);//from ww w .j a v a 2s.c om // *** create user collection resp = user2Executor.execute(Request.Put(collectionTmpUserUri3).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check regex predicate creating user collection " + collectionTmpUserUri3 + " as user2", resp, HttpStatus.SC_CREATED); }
From source file:org.talend.components.datastewardship.connection.TdsConnection.java
/** * Executes Http Put request/*from w w w. j a va 2 s .c o m*/ * * @param resource REST API resource. E. g. issue/{issueId} * @param body message body * @return http status code * @throws ClientProtocolException * @throws IOException */ public int put(String resource, String body) throws IOException { Request put = Request.Put(hostPort + resource).addHeader(authorization).bodyString(body, contentType); return executor.execute(put).returnResponse().getStatusLine().getStatusCode(); }
From source file:org.talend.components.jira.connection.Rest.java
/** * Executes Http Put request// w ww .j av a 2s.co m * * @param resource REST API resource. E. g. issue/{issueId} * @param body message body * @return http status code * @throws ClientProtocolException * @throws IOException */ public int put(String resource, String body) throws IOException { Request put = Request.Put(hostPort + resource).bodyString(body, contentType); for (Header header : headers) { put.addHeader(header); } executor.clearCookies(); return executor.execute(put).returnResponse().getStatusLine().getStatusCode(); }