This commit is contained in:
Gianpaolo Coro 2015-10-19 16:15:47 +00:00
parent bac462c935
commit a617392fcb
2 changed files with 192 additions and 46 deletions

View File

@ -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;
}

View File

@ -17,6 +17,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.jfree.util.Log;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
@ -83,6 +84,80 @@ public class DivaHTTPClient {
responseStreamReader.close();
String response = stringBuilder.toString();
responseStream.close();
httpUrlConnection.disconnect();
AnalysisLogger.getLogger().debug("Response "+response);
return response;
} catch (IOException e) {
throw new Exception(e);
} finally {
if (httpUrlConnection != null)
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);
@ -138,8 +213,9 @@ public class DivaHTTPClient {
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);
}