diff --git a/impexeditor.core/src/main/java/org/eclipseplugins/impexeditor/core/utils/ImpexHttpClient.java b/impexeditor.core/src/main/java/org/eclipseplugins/impexeditor/core/utils/ImpexHttpClient.java index daf0b15..6856eb7 100755 --- a/impexeditor.core/src/main/java/org/eclipseplugins/impexeditor/core/utils/ImpexHttpClient.java +++ b/impexeditor.core/src/main/java/org/eclipseplugins/impexeditor/core/utils/ImpexHttpClient.java @@ -19,10 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -35,7 +32,6 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; -import org.apache.http.util.EntityUtils; import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.Status; import org.eclipseplugins.impexeditor.core.Activator; @@ -47,7 +43,6 @@ import com.eclipsesource.json.JsonArray; import com.eclipsesource.json.JsonObject; -import com.eclipsesource.json.JsonValue; public class ImpexHttpClient @@ -56,37 +51,15 @@ public class ImpexHttpClient private static final String USER_AGENT = "Mozilla/5.0"; private final static Pattern pattern = Pattern .compile("JSESSIONID=[a-zA-Z0-9_-]*"); - private String jsessionId; + private String JSESSIONID; private final String hostName; - private final ILog logger = Activator.getDefault().getLog(); + private static final ILog logger = Activator.getDefault().getLog(); public ImpexHttpClient(final String hostName) { this.hostName = hostName; } - public static void main(final String[] args) throws Exception - { - - final ImpexHttpClient impexHttpClient = new ImpexHttpClient("http://localhost:9001/hac"); - final long startTime = System.currentTimeMillis(); - final Map allatypes = new HashMap(); - for (final JsonValue type : impexHttpClient.getAllTypes()) - { - allatypes.put(type.asString(), impexHttpClient.getTypeandAttribute(type.asString()).get("attributes").asArray()); - } - for (final String type : allatypes.keySet()) - { - System.out.println("type :" + type); - for (final JsonValue string : allatypes.get(type)) - { - System.out.println("---- " + string.asString()); - } - } - final long stopTime = System.currentTimeMillis(); - final long elapsedTime = stopTime - startTime; - System.out.println("Success elapsed time in seconde " + TimeUnit.MILLISECONDS.toSeconds(elapsedTime)); - } public JsonObject getTypeandAttribute(final String type) throws Exception { @@ -123,7 +96,6 @@ public JsonArray getAllTypes() throws Exception private String sendLoginPost() { - final String jssessionId = null; final String validJSessionID = getValidJSessionID(); String csrfToken = null; try @@ -141,7 +113,6 @@ private String sendLoginPost() new BasicNameValuePair("j_username", "admin"), new BasicNameValuePair("j_password", "nimda"), new BasicNameValuePair("_csrf", csrfToken) }); - final String jsessionIdCookieToken = validJSessionID; HttpResponse response = null; String jsessionIDToken = null; try @@ -169,22 +140,21 @@ private String sendLoginPost() } catch (final IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.log(new Status(Status.ERROR, Activator.PLUGIN_ID, e!=null?e.getMessage():"IO Exception")); } return null; } public String getJsessionId() { - if (jsessionId != null) + if (JSESSIONID != null) { - return jsessionId; + return JSESSIONID; } else { - jsessionId = sendLoginPost(); - return jsessionId; + JSESSIONID = sendLoginPost(); + return JSESSIONID; } } @@ -231,19 +201,14 @@ public String validateImpex(final String content) new BasicNameValuePair("scriptContent", content), new BasicNameValuePair("validationEnum", "IMPORT_STRICT"), new BasicNameValuePair("encoding", "UTF-8"), new BasicNameValuePair("maxThreads", "4") }); - System.out.println("############################# "); - System.out.println(content); - System.out.println("############################# "); try { final HttpResponse response = makeHttpPostRequest(hostName + "/console/impex/import", getJsessionId(), params); - final String html = EntityUtils.toString(response.getEntity()); - System.out.println(html); + //TODO parse html ? or better idea execute a remote groovey script wich will restun a json reult easy to parse } catch (final IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.log(new Status(Status.ERROR, Activator.PLUGIN_ID, Status.ERROR, "Connection refused to " + hostName, e)); } return ""; @@ -272,7 +237,7 @@ private String getValidJSessionID() } catch (final IOException e) { - e.printStackTrace(); + logger.log(new Status(Status.ERROR, Activator.PLUGIN_ID, Status.ERROR, "Connection refused to " + hostName, e)); } if (res == null) {