List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestBody
public void setRequestBody(NameValuePair[] paramArrayOfNameValuePair) throws IllegalArgumentException
From source file:org.iavante.sling.gad.source.SourceServiceTestIT.java
public void test_create_source_in_sources() { try {/*from w ww . jav a 2 s.c o m*/ Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create source PostMethod post_create = new PostMethod( SLING_URL + COL_URL + col_title + "/" + SOURCES_FOLDER + "/" + source_title); post_create.setDoAuthentication(true); NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", source_title), new NameValuePair("file", ""), new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""), new NameValuePair("bitrate", ""), new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create.setRequestBody(data_create); // post.setDoAuthentication(true); try { client.executeMethod(post_create); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_create.getStatusCode()); // Edit source PostMethod post_edit = new PostMethod( SLING_URL + COL_URL + col_title + "/" + SOURCES_FOLDER + "/" + source_title); post_edit.setDoAuthentication(true); NameValuePair[] data_edit = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("file", file), new NameValuePair("mimetype", mimetype), new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", type), new NameValuePair("bitrate", ""), new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_edit.setRequestBody(data_edit); post_edit.setDoAuthentication(true); try { client.executeMethod(post_edit); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(200, post_edit.getStatusCode()); try { Thread.sleep(10000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Get the source mime type HttpMethod get_trans_preview = new GetMethod(SLING_URL + COL_URL + col_title + "/" + SOURCES_FOLDER + "/" + source_title + "/" + TRANSFORMATIONS_FOLDER + "/" + TRANSFORMATION_PREVIEW + "/" + "title"); try { client.executeMethod(get_trans_preview); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // handle response. String res_trans_title = ""; try { res_trans_title = get_trans_preview.getResponseBodyAsString(); } catch (IOException e) { e.printStackTrace(); } assertEquals(TRANSFORMATION_PREVIEW_TITLE, res_trans_title); get_trans_preview.releaseConnection(); }
From source file:org.iavante.sling.gad.source.SourceServiceTestIT.java
public void test_transformation_folder_created() { try {//from w w w . j ava2s .c o m Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create the source PostMethod post_create = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/" + source_title); post_create.setDoAuthentication(true); NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", source_title), new NameValuePair("file", ""), new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""), new NameValuePair("bitrate", ""), new NameValuePair("tags", TAGS_REQUEST), new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create.setRequestBody(data_create); // post.setDoAuthentication(true); try { client.executeMethod(post_create); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_create.getStatusCode()); post_create.releaseConnection(); try { Thread.sleep(10000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Get trans folder HttpMethod get_trans_folder = new GetMethod( SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER + "/" + source_title + "/" + TRANSFORMATIONS_FOLDER + ".html"); // get_trans_folder.setDoAuthentication(true); try { client.executeMethod(get_trans_folder); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(200, get_trans_folder.getStatusCode()); get_trans_folder.releaseConnection(); }
From source file:org.iavante.sling.gad.transcoder.impl.TranscoderServiceImpl.java
public int sendConversionTask3(String conversionType, String sourceLocation, String targetLocation, String notificationUrl, String externalStorageServer, String externalStorageUrl, String params, String ds_custom_props) { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); List authPrefs = new ArrayList(2); Credentials defaultcreds;//from w w w . ja v a2 s .co m authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials(transcodingServerUser, transcodingServerPassword); // Set client connection params MultiThreadedHttpConnectionManager connManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connParams = connManager.getParams(); connParams.setConnectionTimeout(800); HttpClient client = new HttpClient(connManager); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); if (log.isInfoEnabled()) log.info("Sending conversion task"); Node convTypeNode = null; try { convTypeNode = rootNode.getNode(baseRepoDir + "/" + COMPONENTS_FOLDER + "/" + TRANSCODER_FOLDER) .getNode(conversionType); } catch (PathNotFoundException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } String executable = null; try { executable = convTypeNode.getProperty("command").getValue().getString(); if (params == null) { params = convTypeNode.getProperty("params").getValue().getString(); } if (ds_custom_props == null) { ds_custom_props = ""; } } catch (ValueFormatException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (PathNotFoundException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } PostMethod post = new PostMethod(sendConversionUrl); //post.getParams().setParameter("http.socket.timeout", new Integer(50)); post.setDoAuthentication(true); NameValuePair[] data = { new NameValuePair("source_location", sourceLocation), new NameValuePair("target_location", targetLocation), new NameValuePair("executable", executable), new NameValuePair("params", params), new NameValuePair("ds_custom_props", ds_custom_props), new NameValuePair("notification_url", notificationUrl), new NameValuePair("extern_storage_server", externalStorageServer), new NameValuePair("sling:resourceType", "gad/job"), new NameValuePair("extern_storage_url", externalStorageUrl) }; post.setRequestBody(data); post.setDoAuthentication(true); int status = 0; int intentos = 0; while ((status != 201) && (intentos < 2)) { try { client.executeMethod(post); status = post.getStatusCode(); log.info("Conversion sent. Status code: " + status); } catch (HttpException e1) { log.error("Excepcion: HttpException"); e1.printStackTrace(); post.releaseConnection(); return status; } catch (IOException e1) { log.error("Excepcion: IOexception"); e1.printStackTrace(); post.releaseConnection(); return status; } finally { intentos++; } } post.releaseConnection(); return status; }
From source file:org.iavante.sling.initialconfig.services.impl.AbstractHttpOperation.java
/** Execute a POST request and check status */ protected void assertAuthenticatedPostStatus(Credentials creds, String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage) throws IOException { final PostMethod post = new PostMethod(url); post.setFollowRedirects(false);// w w w .ja va 2 s . co m URL baseUrl = new URL(HTTP_BASE_URL); AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM); post.setDoAuthentication(true); Credentials oldCredentials = httpClient.getState().getCredentials(authScope); try { httpClient.getState().setCredentials(authScope, creds); if (postParams != null) { final NameValuePair[] nvp = {}; post.setRequestBody(postParams.toArray(nvp)); } final int status = httpClient.executeMethod(post); if (assertMessage == null) { assertEquals(expectedStatusCode, status); } else { assertEquals(assertMessage, expectedStatusCode, status); } } finally { httpClient.getState().setCredentials(authScope, oldCredentials); } }
From source file:org.iavante.sling.permissions.ValidationFilterIT.java
@org.junit.Before public void setUp() { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); boolean hashost = false; while (it.hasNext()) { String key = (String) it.next(); if (key.compareTo(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true;/*from w w w. j a va2 s .c o m*/ } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); title = "Test case content"; schema = "default"; slug_content = "test_case_content"; slug_collection = "admin"; authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials("admin", "admin"); anonymouscreds = new UsernamePasswordCredentials("anonymous", "anonymous"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); PostMethod post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + slug_collection); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"), new NameValuePair("title", title), new NameValuePair("subtitle", ""), new NameValuePair("schema", schema), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_col.setRequestBody(data_create_col); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Collection created post_create_col.releaseConnection(); }
From source file:org.iavante.sling.permissions.ValidationFilterIT.java
@org.junit.After public void tearDown() { try {/*from www . j a va2s .c o m*/ Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Delete the collection PostMethod post_delete = new PostMethod(SLING_URL + COLLECTIONS_URL + slug_collection); NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), }; post_delete.setDoAuthentication(true); post_delete.setRequestBody(data_delete); try { client.executeMethod(post_delete); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_delete.releaseConnection(); }
From source file:org.iavante.sling.permissions.ValidationFilterIT.java
@org.junit.Test public void test_createContent_ok() { try {//from w ww .j a va 2 s .c o m Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } PostMethod post_create_ok = new PostMethod( SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content); post_create_ok.setDoAuthentication(true); NameValuePair[] data_create_ok = { new NameValuePair("sling:resourceType", "gad/content"), new NameValuePair("title", this.title), new NameValuePair("schema", this.schema), new NameValuePair("description", "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"), new NameValuePair("lang", "es"), new NameValuePair("tags", "test case"), new NameValuePair("tags@TypeHint", "String[]"), new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_ok.setRequestBody(data_create_ok); post_create_ok.setDoAuthentication(true); try { client.executeMethod(post_create_ok); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created assertEquals(201, post_create_ok.getStatusCode()); post_create_ok.releaseConnection(); }
From source file:org.iavante.sling.permissions.ValidationFilterIT.java
@org.junit.Test public void test_createContent_bad() { try {//from w w w. ja v a 2 s . com Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } PostMethod post_create_bad = new PostMethod( SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content); post_create_bad.setDoAuthentication(true); NameValuePair[] data_create_bad = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", this.title), new NameValuePair("schema", this.schema), new NameValuePair("description", "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"), new NameValuePair("lang", "es"), new NameValuePair("tags", "test, case"), new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_bad.setRequestBody(data_create_bad); post_create_bad.setDoAuthentication(true); try { client.getState().setCredentials(AuthScope.ANY, anonymouscreds); client.executeMethod(post_create_bad); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { client.getState().setCredentials(AuthScope.ANY, defaultcreds); } // Content created bad assertEquals(403, post_create_bad.getStatusCode()); post_create_bad.releaseConnection(); }
From source file:org.iavante.sling.s3backend.S3BackendTestIT.java
private void createContent() { PostMethod post_create_ok = new PostMethod(SLING_URL + CATALOG_URL + slug); post_create_ok.setDoAuthentication(true); NameValuePair[] data_create_ok = { new NameValuePair("sling:resourceType", "gad/test3"), new NameValuePair("title", this.title), new NameValuePair("schema", this.schema), new NameValuePair("description", "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_ok.setRequestBody(data_create_ok); post_create_ok.setDoAuthentication(true); try {/*w ww . j av a 2s. c o m*/ client.executeMethod(post_create_ok); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created log.info("Created ok: " + post_create_ok.getStatusCode()); assertEquals(201, post_create_ok.getStatusCode()); post_create_ok.releaseConnection(); }
From source file:org.iavante.sling.s3backend.S3BackendTestIT.java
private void createTest3() { PostMethod post_create_ok = new PostMethod(SLING_URL + "/apps/gad/*"); post_create_ok.setDoAuthentication(true); NameValuePair[] data_create_ok = { new NameValuePair("title", "test3"), }; post_create_ok.setRequestBody(data_create_ok); post_create_ok.setDoAuthentication(true); try {/* ww w .j a va 2s . com*/ client.executeMethod(post_create_ok); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created log.info("Created ok: " + post_create_ok.getStatusCode()); assertEquals(201, post_create_ok.getStatusCode()); post_create_ok.releaseConnection(); }