commit 8a590c06b991c57125c25cc72bdbc106da7f122b Author: tilman Date: Sun May 14 13:00:34 2017 +0200 initial commit diff --git a/AH-TreeReader/.classpath b/AH-TreeReader/.classpath new file mode 100644 index 0000000..149cb3c --- /dev/null +++ b/AH-TreeReader/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/AH-TreeReader/.gitignore b/AH-TreeReader/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/AH-TreeReader/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/AH-TreeReader/.project b/AH-TreeReader/.project new file mode 100644 index 0000000..b3fbbf5 --- /dev/null +++ b/AH-TreeReader/.project @@ -0,0 +1,23 @@ + + + AH-TreeReader + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/AH-TreeReader/.settings/org.eclipse.jdt.core.prefs b/AH-TreeReader/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..672496e --- /dev/null +++ b/AH-TreeReader/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/AH-TreeReader/.settings/org.eclipse.m2e.core.prefs b/AH-TreeReader/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/AH-TreeReader/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/AH-TreeReader/pom.xml b/AH-TreeReader/pom.xml new file mode 100644 index 0000000..c29fb20 --- /dev/null +++ b/AH-TreeReader/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + AH-TreeReader + AH-TreeReader + 0.0.1-SNAPSHOT + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.apache.httpcomponents + httpmime + 4.5.3 + + + + + src + + + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/AH-TreeReader/src/de/tilman/AHTreeReader/AHTreeReader.java b/AH-TreeReader/src/de/tilman/AHTreeReader/AHTreeReader.java new file mode 100644 index 0000000..f17cbad --- /dev/null +++ b/AH-TreeReader/src/de/tilman/AHTreeReader/AHTreeReader.java @@ -0,0 +1,10 @@ +package de.tilman.AHTreeReader; + +public class AHTreeReader { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/AH-TreeReader/src/de/tilman/AHTreeReader/PlainApp.java b/AH-TreeReader/src/de/tilman/AHTreeReader/PlainApp.java new file mode 100644 index 0000000..3cad4b5 --- /dev/null +++ b/AH-TreeReader/src/de/tilman/AHTreeReader/PlainApp.java @@ -0,0 +1,99 @@ +package de.tilman.AHTreeReader; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import de.tilman.AHTreeReader.Tree.Node; + +public class PlainApp { + + public static void main(String[] args) throws Exception { + System.out.println("Aloha, funky time"); + String cookie = "PHPSESSID=5nccupenl4b7tps9048bge76h3"; + + Tree tr = new Tree(); + + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost("https://media-assistant.animalhealth.bayer.com/assets/php/ajax_loadCategoryTree.php"); + + HttpHost target = new HttpHost("media-assistant.animalhealth.bayer.com", 443, "https"); + HttpHost proxy = new HttpHost("10.185.190.100", 8080, "http"); + +// RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); +// httpPost.setConfig(config); + httpPost.setHeader("Cookie", cookie); + + HttpEntity entity = MultipartEntityBuilder.create().addTextBody("parent", "14344").build(); + httpPost.setEntity(entity); + + CloseableHttpResponse response = httpClient.execute(target, httpPost); + + try { + System.out.println(response.getStatusLine()); + String str = EntityUtils.toString(response.getEntity()); + + int startIndex = str.indexOf(""); + + String mainCategories = str.substring(str.indexOf("
    ", startIndex)+5, str.indexOf("
", startIndex + 5)); + + while (mainCategories.length() > 6) { + mainCategories = mainCategories.substring(mainCategories.indexOf("catId=") + 7); + String key = mainCategories.substring(0, mainCategories.indexOf('"')); + mainCategories = mainCategories.substring(mainCategories.indexOf(":void(0)'>") + 10); + String value = mainCategories.substring(0, mainCategories.indexOf('<')); + mainCategories = mainCategories.substring(mainCategories.indexOf('\n') + 1); + mainCategories = mainCategories.substring(mainCategories.indexOf('\n') + 1); + + System.out.println(key + ", " + value); + tr.root.children.add(new Node(key, value)); + } + + for (Node n : tr.root.children) { + httpPost = new HttpPost("https://media-assistant.animalhealth.bayer.com/assets/php/ajax_getCategoryFolderSubnavi.php"); +// httpPost.setConfig(config); + httpPost.setHeader("Cookie", cookie); + + entity = MultipartEntityBuilder.create().addTextBody("parent", n.key).build(); + httpPost.setEntity(entity); + + response = httpClient.execute(target, httpPost); + + System.out.println("\n\n ~~~~~~~~~~~~~"); + System.out.println(response.getStatusLine()); + str = EntityUtils.toString(response.getEntity()); + + if (str.indexOf("
    ") >= 0) { + + } + } + + + + } finally { + response.close(); + } + + + + + + + // ArrayList postParameters; + // + // postParameters = new ArrayList(); + // postParameters.add(new BasicNameValuePair("param1", "param1_value")); + // postParameters.add(new BasicNameValuePair("param2", "param2_value")); + // + // httpPost.setEntity(new UrlEncodedFormEntity(postParameters)); + // + // HttpResponse response = httpclient.execute(httpPost); + } + +} \ No newline at end of file diff --git a/AH-TreeReader/src/de/tilman/AHTreeReader/Tree.java b/AH-TreeReader/src/de/tilman/AHTreeReader/Tree.java new file mode 100644 index 0000000..4325c00 --- /dev/null +++ b/AH-TreeReader/src/de/tilman/AHTreeReader/Tree.java @@ -0,0 +1,29 @@ +package de.tilman.AHTreeReader; + +import java.util.ArrayList; +import java.util.List; + +public class Tree { + public Node root; + + public Tree() { + root = new Node(); + root.children = new ArrayList>(); + } + + public static class Node { + + public Node() { } + + public Node(K key, V value) { + this.key = key; + this.value = value; + } + + public K key; + public V value; + public Node parent; + public List> children = new ArrayList>(); + + } +} \ No newline at end of file