git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine@150996 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7108959c4b
commit
6930074afc
|
@ -7,28 +7,12 @@ import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class DateGuesser {
|
public class DateGuesser {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
private static Logger LOGGER = LoggerFactory.getLogger(DateGuesser.class);
|
||||||
Calendar c = convertDate("20/2/2010 0:49:00");
|
|
||||||
System.out.println("giorno " + c.get(Calendar.DAY_OF_MONTH) + " mese " + (c.get(Calendar.MONTH) + 1) + " anno " + c.get(Calendar.YEAR));
|
|
||||||
System.out.println("pattern " + getPattern("20/2/2010 0:49:00"));
|
|
||||||
System.out.println("pattern " + getPattern("2009-05-12 15:42:10"));
|
|
||||||
System.out.println("pattern " + getPattern("1970"));
|
|
||||||
System.out.println("pattern " + getPattern("2009-05-12"));
|
|
||||||
System.out.println("pattern " + getPattern("prova"));
|
|
||||||
System.out.println("pattern " + getPattern("9/26/2010 1:49:00"));
|
|
||||||
System.out.println("pattern " + getPattern("0.99"));
|
|
||||||
System.out.println("pattern " + getPattern("01/25/2013 14:48"));
|
|
||||||
c = convertDate("2009-05-12");
|
|
||||||
System.out.println("giorno " + c.get(Calendar.DAY_OF_MONTH) + " mese " + (c.get(Calendar.MONTH) + 1) + " anno " + c.get(Calendar.YEAR));
|
|
||||||
// Properties prop = new Properties(System.getProperties());
|
|
||||||
|
|
||||||
// prop.list(System.out);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Calendar convertDate(String data) {
|
public static Calendar convertDate(String data) {
|
||||||
return convertDate(data, null);
|
return convertDate(data, null);
|
||||||
|
@ -46,6 +30,7 @@ public class DateGuesser {
|
||||||
if (isSeconds(data))
|
if (isSeconds(data))
|
||||||
return "s";
|
return "s";
|
||||||
|
|
||||||
|
|
||||||
// String language = System.getProperty("user.language");
|
// String language = System.getProperty("user.language");
|
||||||
Locale l = Locale.UK;
|
Locale l = Locale.UK;
|
||||||
if (language != null && language.equalsIgnoreCase("it"))
|
if (language != null && language.equalsIgnoreCase("it"))
|
||||||
|
@ -90,7 +75,7 @@ public class DateGuesser {
|
||||||
if ((("" + secondsint).length() == 4) && (secondsint == seconds))
|
if ((("" + secondsint).length() == 4) && (secondsint == seconds))
|
||||||
isSeconds = false;
|
isSeconds = false;
|
||||||
else {
|
else {
|
||||||
AnalysisLogger.getLogger().debug("This entry contains seconds indication");
|
LOGGER.debug("This entry contains seconds indication");
|
||||||
isSeconds = true;
|
isSeconds = true;
|
||||||
}
|
}
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
|
|
|
@ -30,16 +30,15 @@ import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
||||||
import org.apache.commons.httpclient.auth.AuthScope;
|
import org.apache.commons.httpclient.auth.AuthScope;
|
||||||
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
|
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
|
||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
|
import org.slf4j.Logger;
|
||||||
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
|
||||||
import org.apache.commons.httpclient.methods.multipart.Part;
|
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.FileTools;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class HttpRequest {
|
public class HttpRequest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HttpRequest.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an HTTP GET request to a url
|
* Sends an HTTP GET request to a url
|
||||||
*
|
*
|
||||||
|
@ -74,7 +73,7 @@ public class HttpRequest {
|
||||||
rd.close();
|
rd.close();
|
||||||
result = sb.toString();
|
result = sb.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LOGGER.error("error sending get request",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -137,7 +136,7 @@ public class HttpRequest {
|
||||||
public static Object getJSonData(String endpoint, String requestParameters, Type outputClass) throws Exception {
|
public static Object getJSonData(String endpoint, String requestParameters, Type outputClass) throws Exception {
|
||||||
String output = sendGetRequest(endpoint, requestParameters);
|
String output = sendGetRequest(endpoint, requestParameters);
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
// AnalysisLogger.getLogger().debug("HttpRequest-> OUTPUT JSON:\n"+output.toString());
|
// LOGGER.debug("HttpRequest-> OUTPUT JSON:\n"+output.toString());
|
||||||
// Output the response
|
// Output the response
|
||||||
Object rebuiltJson = gson.fromJson(output.toString(), outputClass);
|
Object rebuiltJson = gson.fromJson(output.toString(), outputClass);
|
||||||
return rebuiltJson;
|
return rebuiltJson;
|
||||||
|
@ -176,7 +175,7 @@ public class HttpRequest {
|
||||||
writer = new OutputStreamWriter(out);
|
writer = new OutputStreamWriter(out);
|
||||||
// write parameters
|
// write parameters
|
||||||
String jsonString = gson.toJson(obj);
|
String jsonString = gson.toJson(obj);
|
||||||
AnalysisLogger.getLogger().trace("INPUT JSON:\n" + jsonString);
|
LOGGER.trace("INPUT JSON:\n" + jsonString);
|
||||||
writer.write(jsonString);
|
writer.write(jsonString);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
@ -193,13 +192,13 @@ public class HttpRequest {
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
reader.close();
|
reader.close();
|
||||||
// AnalysisLogger.getLogger().debug("OUTPUT JSON:\n"+answer.toString());
|
// LOGGER.debug("OUTPUT JSON:\n"+answer.toString());
|
||||||
// Output the response
|
// Output the response
|
||||||
Object rebuiltJson = gson.fromJson(answer.toString(), outputClass);
|
Object rebuiltJson = gson.fromJson(answer.toString(), outputClass);
|
||||||
return rebuiltJson;
|
return rebuiltJson;
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
LOGGER.error("error executing http call",ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -247,9 +246,9 @@ public class HttpRequest {
|
||||||
return answer.toString();
|
return answer.toString();
|
||||||
|
|
||||||
} catch (MalformedURLException ex) {
|
} catch (MalformedURLException ex) {
|
||||||
ex.printStackTrace();
|
LOGGER.error("error sending post request",ex);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
LOGGER.error("error sending post request",ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -284,7 +283,7 @@ public class HttpRequest {
|
||||||
checkConn = conn.getResponseCode();
|
checkConn = conn.getResponseCode();
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("ERROR in URL " + e.getMessage());
|
LOGGER.error("error in url",e);
|
||||||
}
|
}
|
||||||
return checkConn;
|
return checkConn;
|
||||||
}
|
}
|
||||||
|
@ -293,7 +292,7 @@ public class HttpRequest {
|
||||||
URL smpFile = new URL(fileurl);
|
URL smpFile = new URL(fileurl);
|
||||||
URLConnection uc = (URLConnection) smpFile.openConnection();
|
URLConnection uc = (URLConnection) smpFile.openConnection();
|
||||||
InputStream is = uc.getInputStream();
|
InputStream is = uc.getInputStream();
|
||||||
AnalysisLogger.getLogger().debug("GenericWorker-> Retrieving from " + fileurl + " to :" + localFile);
|
LOGGER.debug("GenericWorker-> Retrieving from " + fileurl + " to :" + localFile);
|
||||||
inputStreamToFile(is, localFile);
|
inputStreamToFile(is, localFile);
|
||||||
is.close();
|
is.close();
|
||||||
is = null;
|
is = null;
|
||||||
|
@ -328,10 +327,15 @@ public class HttpRequest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = client.executeMethod(postMethod);
|
client.executeMethod(postMethod);
|
||||||
|
|
||||||
byte[] responseBody = postMethod.getResponseBody();
|
String response = "";
|
||||||
String response = new String(responseBody);
|
try(BufferedReader bis = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream()))){
|
||||||
|
String line = null;
|
||||||
|
while ((line = bis.readLine())!=null)
|
||||||
|
response += line ;
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +356,7 @@ public class HttpRequest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = client.executeMethod(postMethod);
|
client.executeMethod(postMethod);
|
||||||
|
|
||||||
byte[] responseBody = postMethod.getResponseBody();
|
byte[] responseBody = postMethod.getResponseBody();
|
||||||
String response = new String(responseBody);
|
String response = new String(responseBody);
|
||||||
|
@ -360,25 +364,4 @@ public class HttpRequest {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
/*
|
|
||||||
* String url = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/rest/layergroups/group4402c0cff-27e3-4606-a2f1-993ad37c3dfb.json"; int d = checkUrl(url, "admin", "gcube@geo2010"); System.out.println(d);
|
|
||||||
*/
|
|
||||||
String host = "dataminer1-devnext.d4science.org";
|
|
||||||
int port = 80;
|
|
||||||
String url = "http://" + host + ":" + port + "/wps/WebProcessingService";
|
|
||||||
|
|
||||||
String username = "gianpaolo.coro";
|
|
||||||
String password = "cb289202-e7d6-45ee-8076-a80bc4d4be51|98187548";
|
|
||||||
String parameters = "";
|
|
||||||
File filetosend = new File("dbscan_req_2016-07-05_01_49_01.507.xml");
|
|
||||||
/*
|
|
||||||
String fileloaded = FileTools.loadString(filetosend.getAbsolutePath(), "UTF-8");
|
|
||||||
fileloaded = fileloaded.trim().replaceFirst("^([\\W]+)<","<");
|
|
||||||
File testfile = new File("test.xml");
|
|
||||||
FileTools.saveString(testfile.getAbsolutePath(), fileloaded, true, "UTF-8");
|
|
||||||
*/
|
|
||||||
// PostData(url, parameters, username, password, filetosend);
|
|
||||||
PostFileData(url, host, port, new LinkedHashMap<String, String>(), username, password, filetosend);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue