git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/SeaDataNetConnector@119871 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
bac462c935
commit
a617392fcb
|
@ -0,0 +1,70 @@
|
||||||
|
package org.gcube.dataanalysis.seadatanet;
|
||||||
|
|
||||||
|
public class DivaAnalysisGetResponse {
|
||||||
|
|
||||||
|
public DivaAnalysisGetResponse(String id,double len,double stn,
|
||||||
|
double x0,double x1, double dx,double y0,double y1,double dy,int level) {
|
||||||
|
super();
|
||||||
|
this.x0 = x0;
|
||||||
|
this.x1 = x1;
|
||||||
|
this.dx = dx;
|
||||||
|
this.y0 = y0;
|
||||||
|
this.y1 = y1;
|
||||||
|
this.dy = dy;
|
||||||
|
this.len = len;
|
||||||
|
this.stn = stn;
|
||||||
|
this.sessionid = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DivaFilePostResponse [obs_x0=" + obs_x0 + ", obs_x1="
|
||||||
|
+ obs_x1 + ", obs_y0=" + obs_y0 + ", obs_y1=" + obs_y1
|
||||||
|
+ ", obs_v0=" + obs_v0 + ", obs_v1=" + obs_v1
|
||||||
|
+ ", obs_count=" + obs_count + ", sessionid=" + sessionid
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Double getVmax() {
|
||||||
|
return vmax;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVmax(Double vmax) {
|
||||||
|
this.vmax = vmax;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getStat_obs_count_used() {
|
||||||
|
return stat_obs_count_used;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStat_obs_count_used(Double stat_obs_count_used) {
|
||||||
|
this.stat_obs_count_used = stat_obs_count_used;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getStat_posteriori_stn() {
|
||||||
|
return stat_posteriori_stn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStat_posteriori_stn(Double stat_posteriori_stn) {
|
||||||
|
this.stat_posteriori_stn = stat_posteriori_stn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSessionid() {
|
||||||
|
return sessionid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionid(String sessionid) {
|
||||||
|
this.sessionid = sessionid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Double vmax;
|
||||||
|
Double stat_obs_count_used;
|
||||||
|
Double stat_posteriori_stn;
|
||||||
|
String sessionid;
|
||||||
|
}
|
|
@ -17,77 +17,79 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||||||
|
import org.jfree.util.Log;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
public class DivaHTTPClient {
|
public class DivaHTTPClient {
|
||||||
|
|
||||||
public static String WEB_HTTP="http://gher-diva.phys.ulg.ac.be/web-vis/Python/web";
|
public static String WEB_HTTP="http://gher-diva.phys.ulg.ac.be/web-vis/Python/web";
|
||||||
|
|
||||||
public static String postFile(File file) throws Exception {
|
public static String postFile(File file) throws Exception {
|
||||||
String crlf = "\r\n";
|
String crlf = "\r\n";
|
||||||
String twoHyphens = "--";
|
String twoHyphens = "--";
|
||||||
String boundary = "*****";
|
String boundary = "*****";
|
||||||
|
|
||||||
HttpURLConnection httpUrlConnection = null;
|
HttpURLConnection httpUrlConnection = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
URL url = new URL(WEB_HTTP+"/upload");
|
|
||||||
httpUrlConnection = (HttpURLConnection) url.openConnection();
|
|
||||||
httpUrlConnection.setUseCaches(false);
|
|
||||||
httpUrlConnection.setDoOutput(true);
|
|
||||||
|
|
||||||
httpUrlConnection.setRequestMethod("POST");
|
URL url = new URL(WEB_HTTP+"/upload");
|
||||||
httpUrlConnection.setRequestProperty("Connection", "Keep-Alive");
|
httpUrlConnection = (HttpURLConnection) url.openConnection();
|
||||||
httpUrlConnection.setRequestProperty("Cache-Control", "no-cache");
|
httpUrlConnection.setUseCaches(false);
|
||||||
|
httpUrlConnection.setDoOutput(true);
|
||||||
httpUrlConnection.setRequestProperty(
|
|
||||||
"Content-Type", "multipart/form-data;boundary=" + boundary);
|
httpUrlConnection.setRequestMethod("POST");
|
||||||
|
httpUrlConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||||
DataOutputStream request = new DataOutputStream(
|
httpUrlConnection.setRequestProperty("Cache-Control", "no-cache");
|
||||||
httpUrlConnection.getOutputStream());
|
|
||||||
|
httpUrlConnection.setRequestProperty(
|
||||||
|
"Content-Type", "multipart/form-data;boundary=" + boundary);
|
||||||
|
|
||||||
|
DataOutputStream request = new DataOutputStream(
|
||||||
|
httpUrlConnection.getOutputStream());
|
||||||
|
|
||||||
request.writeBytes("--" + boundary + crlf);
|
request.writeBytes("--" + boundary + crlf);
|
||||||
request.writeBytes("Content-Disposition: form-data; name=\"data" + "\";filename=\"" +
|
request.writeBytes("Content-Disposition: form-data; name=\"data" + "\";filename=\"" +
|
||||||
file.getName() + "\"" + crlf);
|
file.getName() + "\"" + crlf);
|
||||||
request.writeBytes(crlf);
|
request.writeBytes(crlf);
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
String lineString = reader.readLine();
|
String lineString = reader.readLine();
|
||||||
while (lineString!=null) {
|
while (lineString!=null) {
|
||||||
request.writeBytes(lineString);
|
request.writeBytes(lineString);
|
||||||
lineString = reader.readLine();
|
lineString = reader.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
reader.close();
|
reader.close();
|
||||||
request.writeBytes(crlf);
|
request.writeBytes(crlf);
|
||||||
request.writeBytes(twoHyphens + boundary +
|
request.writeBytes(twoHyphens + boundary +
|
||||||
twoHyphens + crlf);
|
twoHyphens + crlf);
|
||||||
request.flush();
|
request.flush();
|
||||||
request.close();
|
request.close();
|
||||||
InputStream responseStream = new
|
InputStream responseStream = new
|
||||||
BufferedInputStream(httpUrlConnection.getInputStream());
|
BufferedInputStream(httpUrlConnection.getInputStream());
|
||||||
|
|
||||||
BufferedReader responseStreamReader =
|
BufferedReader responseStreamReader =
|
||||||
new BufferedReader(new InputStreamReader(responseStream));
|
new BufferedReader(new InputStreamReader(responseStream));
|
||||||
|
|
||||||
String line = "";
|
String line = "";
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
while ((line = responseStreamReader.readLine()) != null) {
|
while ((line = responseStreamReader.readLine()) != null) {
|
||||||
stringBuilder.append(line).append("\n");
|
stringBuilder.append(line).append("\n");
|
||||||
}
|
}
|
||||||
responseStreamReader.close();
|
responseStreamReader.close();
|
||||||
|
|
||||||
|
String response = stringBuilder.toString();
|
||||||
|
|
||||||
|
responseStream.close();
|
||||||
|
httpUrlConnection.disconnect();
|
||||||
|
AnalysisLogger.getLogger().debug("Response "+response);
|
||||||
|
return response;
|
||||||
|
|
||||||
String response = stringBuilder.toString();
|
|
||||||
responseStream.close();
|
|
||||||
httpUrlConnection.disconnect();
|
|
||||||
AnalysisLogger.getLogger().debug("Response "+response);
|
|
||||||
return response;
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Exception(e);
|
throw new Exception(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -95,8 +97,81 @@ public class DivaHTTPClient {
|
||||||
httpUrlConnection.disconnect();
|
httpUrlConnection.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* sessionid
|
||||||
|
id from previous upload
|
||||||
|
len
|
||||||
|
correlation length (arc degrees)
|
||||||
|
stn
|
||||||
|
signal to noise ratio (non-dimensional)
|
||||||
|
x0,x1,dx
|
||||||
|
first and last longitude values and resolution of the grid
|
||||||
|
y0,y1,dy
|
||||||
|
idem for latitude
|
||||||
|
level
|
||||||
|
depth level
|
||||||
|
*/
|
||||||
|
public static String getAnalysis (String id,double len,double stn,double x0,double x1, double dx,double y0,double y1,double dy,double level) throws Exception {
|
||||||
|
HttpURLConnection httpUrlConnection = null;
|
||||||
|
try {
|
||||||
|
String get_url=WEB_HTTP+"/make_analysis?";
|
||||||
|
get_url+="sessionid="+id+"&";
|
||||||
|
get_url+="len="+len+"&";
|
||||||
|
get_url+="stn="+stn+"&";
|
||||||
|
get_url+="x0="+x0+"&";
|
||||||
|
get_url+="x1="+x1+"&";
|
||||||
|
get_url+="dx="+dx+"&";
|
||||||
|
get_url+="y0="+y0+"&";
|
||||||
|
get_url+="y1="+y1+"&";
|
||||||
|
get_url+="dy="+dy+"&";
|
||||||
|
get_url+="level="+level+"";
|
||||||
|
System.out.println("GET URL="+get_url);
|
||||||
|
URL url = new URL(get_url);
|
||||||
|
|
||||||
|
httpUrlConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
httpUrlConnection.setUseCaches(false);
|
||||||
|
httpUrlConnection.setDoOutput(true);
|
||||||
|
|
||||||
|
httpUrlConnection.setRequestMethod("GET");
|
||||||
|
httpUrlConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||||
|
httpUrlConnection.setRequestProperty("Cache-Control", "no-cache");
|
||||||
|
InputStream responseStream = new
|
||||||
|
BufferedInputStream(httpUrlConnection.getInputStream());
|
||||||
|
|
||||||
|
BufferedReader responseStreamReader =
|
||||||
|
new BufferedReader(new InputStreamReader(responseStream));
|
||||||
|
|
||||||
|
String line = "";
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
while ((line = responseStreamReader.readLine()) != null) {
|
||||||
|
stringBuilder.append(line).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
responseStreamReader.close();
|
||||||
|
|
||||||
|
|
||||||
|
String response = stringBuilder.toString();
|
||||||
|
|
||||||
|
Document doc = loadXMLFromString(response);
|
||||||
|
System.out.println("DENTRO: "+ doc.getFirstChild());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
responseStream.close();
|
||||||
|
httpUrlConnection.disconnect();
|
||||||
|
AnalysisLogger.getLogger().debug("Response "+response);
|
||||||
|
return response;
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Exception(e);
|
||||||
|
} finally {
|
||||||
|
if (httpUrlConnection != null)
|
||||||
|
httpUrlConnection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static DivaFilePostResponse uploadFile(File file) throws Exception, IOException, ParserConfigurationException, SAXException
|
public static DivaFilePostResponse uploadFile(File file) throws Exception, IOException, ParserConfigurationException, SAXException
|
||||||
{
|
{
|
||||||
String result_xml = null;
|
String result_xml = null;
|
||||||
|
@ -105,12 +180,12 @@ public class DivaHTTPClient {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result_xml == null) {
|
if (result_xml == null) {
|
||||||
throw new SAXException("Error in HTTP response no response element found!");
|
throw new SAXException("Error in HTTP response no response element found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Create Document object by XMLResponse
|
//Create Document object by XMLResponse
|
||||||
Document doc = loadXMLFromString(result_xml);
|
Document doc = loadXMLFromString(result_xml);
|
||||||
//Print XML Response
|
//Print XML Response
|
||||||
|
@ -133,17 +208,18 @@ public class DivaHTTPClient {
|
||||||
return new DivaFilePostResponse(obs_x0, obs_x1, obs_y0, obs_y1, obs_v0, obs_v1, obs_count, sessionid);
|
return new DivaFilePostResponse(obs_x0, obs_x1, obs_y0, obs_y1, obs_v0, obs_v1, obs_count, sessionid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
DivaFilePostResponse response=uploadFile(new File("temperature_argo10.txt"));
|
DivaFilePostResponse response=uploadFile(new File("C:"+File.separator+"Users"+File.separator+"marbas"+File.separator+"Desktop"+File.separator+"temperature_argo.txt"));
|
||||||
|
|
||||||
|
System.out.println(getAnalysis(response.getSessionid(),5,4,76,78,1,35,78,1,2));
|
||||||
System.out.println(response);
|
System.out.println(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//PARSER XML
|
//PARSER XML
|
||||||
private static Document loadXMLFromString(String xml) throws ParserConfigurationException, SAXException, IOException
|
private static Document loadXMLFromString(String xml) throws ParserConfigurationException, SAXException, IOException
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue