initial commit

This commit is contained in:
tilman
2017-05-14 13:00:34 +02:00
commit 8a590c06b9
9 changed files with 233 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
+2
View File
@@ -0,0 +1,2 @@
/bin/
/target/
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AH-TreeReader</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -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
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
+34
View File
@@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>AH-TreeReader</groupId>
<artifactId>AH-TreeReader</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,10 @@
package de.tilman.AHTreeReader;
public class AHTreeReader {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
@@ -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<String, String> tr = new Tree<String, String>();
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("</ul>");
String mainCategories = str.substring(str.indexOf("<ul>", startIndex)+5, str.indexOf("</ul>", 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<String, String>(key, value));
}
for (Node<String, String> 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("<ul>") >= 0) {
}
}
} finally {
response.close();
}
// ArrayList<NameValuePair> postParameters;
//
// postParameters = new ArrayList<NameValuePair>();
// postParameters.add(new BasicNameValuePair("param1", "param1_value"));
// postParameters.add(new BasicNameValuePair("param2", "param2_value"));
//
// httpPost.setEntity(new UrlEncodedFormEntity(postParameters));
//
// HttpResponse response = httpclient.execute(httpPost);
}
}
@@ -0,0 +1,29 @@
package de.tilman.AHTreeReader;
import java.util.ArrayList;
import java.util.List;
public class Tree<K,V> {
public Node<K,V> root;
public Tree() {
root = new Node<K,V>();
root.children = new ArrayList<Node<K,V>>();
}
public static class Node<K,V> {
public Node() { }
public Node(K key, V value) {
this.key = key;
this.value = value;
}
public K key;
public V value;
public Node<K,V> parent;
public List<Node<K,V>> children = new ArrayList<Node<K,V>>();
}
}