List of usage examples for org.apache.commons.httpclient.auth AuthPolicy AUTH_SCHEME_PRIORITY
String AUTH_SCHEME_PRIORITY
To view the source code for org.apache.commons.httpclient.auth AuthPolicy AUTH_SCHEME_PRIORITY.
Click Source Link
From source file:org.iavante.sling.searcher.SearcherServiceTestIT.java
@org.junit.Test public void test_fullinfo_channels_xml() { // Empty search String param = "?key=" + TITLE_CONTENT + "&format=xml&fullinfo=true&path=/content/catalogo/&type=gad/revision"; String body = null;/*from ww w . j av a2 s.c o m*/ GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param); searchmethod.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(searchmethod); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(200, searchmethod.getStatusCode()); try { body = searchmethod.getResponseBodyAsString(); assertTrue("fullinfo channels xml 1", body.contains("<counter>1</counter>")); assertTrue("fullinfo channels xml 2", body.contains("<channels>\n </channels>")); assertTrue("fullinfo channels xml 3", body.contains("<?xml version=\"1.0\"?>")); } catch (IOException e) { assertFalse(true); } searchmethod.releaseConnection(); }
From source file:org.iavante.sling.searcher.SearcherServiceTestIT.java
@org.junit.Test public void test_fullinfo_channels_json() { // Empty search String param = "?key=" + TITLE_CONTENT + "&format=json&fullinfo=true&path=/content/catalogo/&type=gad/revision"; String body = null;/*w w w .ja v a 2 s. c om*/ GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param); searchmethod.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(searchmethod); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(200, searchmethod.getStatusCode()); try { body = searchmethod.getResponseBodyAsString(); assertTrue("fullinfo channels json 1", body.contains("\"counter\":\"1\"")); assertTrue("fullinfo channels json 2", body.contains("\"channels\":[]")); } catch (IOException e) { assertFalse(true); } searchmethod.releaseConnection(); }
From source file:org.iavante.sling.searcher.SearcherServiceTestIT.java
@org.junit.Test public void test_related_search() { // Empty search String param = "?key=" + TITLE_CONTENT + "&path=/content/colecciones&related=0.2&format=xml"; String body = null;//from w w w .j av a2 s. c o m GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param); searchmethod.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(searchmethod); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(200, searchmethod.getStatusCode()); try { body = searchmethod.getResponseBodyAsString(); System.out.println(body); assertTrue("fullinfo related 1", body.contains("<counter>6</counter>")); } catch (IOException e) { assertFalse(true); } searchmethod.releaseConnection(); }
From source file:org.iavante.sling.transcodingServer.impl.TranscodingManagerImpl.java
@SuppressWarnings("unchecked") private String notificateTransformation(Node jobNode) { log.info("notificateTransformation: reading properties"); String response = ""; String source_location = ""; String target_location = ""; String notification_url = null; String gadUser = null;/*from ww w . j a va2 s.com*/ String gadPassword = null; String source_file = null; String target_file = null; HttpClient client = null; List authPrefs = new ArrayList(2); client = new HttpClient(); Credentials defaultcreds; // first of all. We have to take the useful data try { // source_location-->sourcefile // target_location-->targetfile // ds_custom_props-->ds_custom_props source_location = jobNode.getProperty("source_location").getValue().getString(); String[] splitedSourceLocation = source_location.split("/"); source_file = splitedSourceLocation[splitedSourceLocation.length - 1]; target_location = jobNode.getProperty("target_location").getValue().getString(); String[] splitedTargetLocation = target_location.split("/"); target_file = splitedTargetLocation[splitedTargetLocation.length - 1]; notification_url = jobNode.getProperty("notification_url").getValue().getString(); gadUser = Constantes.getGADuser(); gadPassword = Constantes.getGADpassword(); log.info("notificateTransformation: notification_url:" + notification_url); log.info("notificateTransformation: target_file:" + target_file); log.info("notificateTransformation: source_file:" + source_file); } catch (ValueFormatException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (PathNotFoundException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } // Using the hhtp client. This has to be authenticated authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials(gadUser, gadPassword); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // Using the POST Method PostMethod post_notification = new PostMethod(notification_url); post_notification.setDoAuthentication(true); NameValuePair[] data_notification = { new NameValuePair("sling:resourceType", "gad/transformation"), new NameValuePair("title", source_file), // new NameValuePair("file", target_file), new NameValuePair("jcr:lastModified", "") }; post_notification.setRequestBody(data_notification); post_notification.setDoAuthentication(true); try { log.info("notificateTransformation: Notificating..."); client.executeMethod(post_notification); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Response in Status int status = post_notification.getStatusCode(); post_notification.releaseConnection(); if (status == 200) { response = "OK. Notificated. Status =" + status; log.info(response); } else { response = "Error notificating. Status =" + status; log.error(response); } return response; }
From source file:org.iavante.sling.transcodingServer.impl.TranscodingManagerImpl.java
@SuppressWarnings("unchecked") private String notificateStatus(String mystatus, Node jobNode) { log.info("notificatingStatus: reading properties"); String response = ""; String notification_url = null; String gadUser = null;//from w w w .j av a 2 s .c o m String gadPassword = null; HttpClient client = null; List authPrefs = new ArrayList(2); client = new HttpClient(); Credentials defaultcreds; // first of all. We have to take the useful data try { notification_url = jobNode.getProperty("notification_url").getValue().getString(); gadUser = Constantes.getGADuser(); gadPassword = Constantes.getGADpassword(); } catch (ValueFormatException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (PathNotFoundException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } // Using the hhtp client. This has to be authenticated authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials(gadUser, gadPassword); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // Using the POST Method PostMethod post_notification = new PostMethod(notification_url); post_notification.setDoAuthentication(true); NameValuePair[] data_notification = { new NameValuePair("sling:resourceType", "gad/transformation"), new NameValuePair("state", mystatus) }; post_notification.setRequestBody(data_notification); post_notification.setDoAuthentication(true); try { log.info("notificatingStatus..."); client.executeMethod(post_notification); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Response in Status int status = post_notification.getStatusCode(); post_notification.releaseConnection(); if (status == 200) { response = "OK. Notificated. Status =" + status; log.info(response); } else { response = "Error notificating. Status =" + status; log.error(response); } return response; }
From source file:org.iavante.sling.transcodingServer.TranscodingServerTestIT.java
protected 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 ava 2s. com } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials("admin", "admin"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // Create a wrong job PostMethod post_create_job = new PostMethod(SLING_URL + JOBS_PENDING_URL); post_create_job.setDoAuthentication(true); NameValuePair[] data_create_job = { new NameValuePair("sling:resourceType", resourceType), new NameValuePair("source_location", wrong_source_location), new NameValuePair("target_location", wrong_target_location), new NameValuePair("executable", executable), new NameValuePair("title", title), new NameValuePair("notification_url", notification_url), new NameValuePair("extern_storage_server", extern_storage_server), new NameValuePair("extern_storage_url", extern_storage_url), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_job.setRequestBody(data_create_job); try { client.executeMethod(post_create_job); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_create_job.releaseConnection(); }
From source file:org.iavante.uploader.ifaces.impl.UploadServiceImpl.java
/** * POST to a specified url./* ww w.j a v a 2s. co m*/ * * @param request * @param urlNotification * @param params * @return * @throws Exception */ private String restConnection2(HttpServletRequest request, String urlNotification, Map params) throws Exception { if (out.isInfoEnabled()) out.info("restConnection, ini"); String rt = request.getParameter("rt"); if (rt == null) { rt = "gad/source"; } if (out.isInfoEnabled()) out.info("restConnection, rt -> " + rt); PostMethod post = new PostMethod(urlNotification); List<Part> listPart = new ArrayList<Part>(); listPart.add(new StringPart("sling:resourceType", rt)); listPart.add(new StringPart("jcr:lastModified", "")); listPart.add(new StringPart("jcr:lastModifiedBy", "")); listPart.add(new FilePart("body.txt", new File(bodyFilename))); // parts[3] = new StringPart("filename", f.getName()), new FilePart("data", // f); Set set = params.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); if ("".compareTo((String) entry.getValue()) != 0) { String campo = (String) relation.get("" + entry.getKey()); listPart.add(new StringPart(campo, "" + entry.getValue())); } } int cont = 0; if ("".compareTo((String) params.get("video")) != 0) { listPart.add(new StringPart("track_1_type", "video")); cont++; } if ("".compareTo((String) params.get("audio")) != 0) { listPart.add(new StringPart("track_2_type", "audio")); cont++; } if (cont > 0) { listPart.add(new StringPart("tracks_number", "" + cont)); } Part[] parts = new Part[listPart.size()]; for (int i = 0; i < listPart.size(); i++) { parts[i] = listPart.get(i); } post.setRequestEntity((RequestEntity) new MultipartRequestEntity(parts, post.getParams())); post.setDoAuthentication(true); SlingHttpServletRequest req = (SlingHttpServletRequest) request; String credentials = authTools.extractUserPass(req); int colIdx = credentials.indexOf(':'); if (colIdx < 0) { userCreds = new UsernamePasswordCredentials(credentials); } else { userCreds = new UsernamePasswordCredentials(credentials.substring(0, colIdx), credentials.substring(colIdx + 1)); } client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, userCreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); int responseCode = -1; String responseMessage = ""; try { client.executeMethod(post); responseCode = post.getStatusCode(); responseMessage = post.getResponseBodyAsString(); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { post.releaseConnection(); } if (responseCode != 201 && responseCode != 200) { throw new IOException("sendContentToRevision, code=" + responseCode); } if (out.isInfoEnabled()) out.info("restConnection, end"); return responseMessage + " (" + responseCode + ")"; }
From source file:org.iavante.uploader.ifaces.impl.UploadServiceImpl.java
/** * Initial http client configuration.// w w w. j a v a 2 s .c om */ private void setup() { client = new HttpClient(); defaultCreds = new UsernamePasswordCredentials("admin", "admin"); authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultCreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); }
From source file:org.iavante.uploader.ifaces.UploadServiceIT.java
/** * Tests a valid upload action.//from w w w. j a v a 2 s .co m * * @exception Exception * Invalid httpRequest Exception */ public void test_ValidUpload() throws Exception { PostMethod post0 = new PostMethod(SLING_URL + CONTENT); Part[] parts0 = { new StringPart("title", "Prueba") }; post0.setRequestEntity((RequestEntity) new MultipartRequestEntity(parts0, post0.getParams())); post0.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post0); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post0.getStatusCode()); File f = new File(VIDEODIR + VIDEONAME); PostMethod post = new PostMethod(SLING_URL + UPLOADER_URL); Part[] parts = { new StringPart("coreurl", CORE_URL), new StringPart("content", CONTENT), new StringPart("filename", f.getName()), new FilePart("data", f) }; post.setRequestEntity((RequestEntity) new MultipartRequestEntity(parts, post.getParams())); post.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(200, post.getStatusCode()); if (post.getStatusCode() == 200) { // --------------------------------------------------- // --------------------------------------------------- uploadService.removeFile("/mnt/gad/input_repository/" + VIDEONAME); PostMethod post2 = new PostMethod(SLING_URL + CONTENT); Part[] parts2 = { new StringPart(":operation", "delete") }; post2.setRequestEntity((RequestEntity) new MultipartRequestEntity(parts2, post2.getParams())); post2.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post2); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(post2.getStatusCode(), 200); } post.releaseConnection(); }
From source file:org.infoglue.igide.helper.HTTPClientHelper.java
public HTTPClientHelper(URL baseurl, String username, String password) { HttpClientParams params = new HttpClientParams(HttpClientParams.getDefaultParams()); client = new HttpClient(params); Credentials defaultcreds = new UsernamePasswordCredentials(username, password); client.getState().setCredentials(new AuthScope(baseurl.getHost(), baseurl.getPort(), AuthScope.ANY_REALM), defaultcreds);//from w ww . j a v a 2s . com List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.BASIC); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.NTLM); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); }