Minor Update
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@91545 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5f0c12e49e
commit
ffe640fd49
|
@ -3,11 +3,9 @@
|
|||
*/
|
||||
package org.gcube.portlets.user.td.expressionwidget.server;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -18,81 +16,89 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.data.analysis.tabulardata.expression.Expression;
|
||||
import org.gcube.data.analysis.tabulardata.expression.MalformedExpressionException;
|
||||
import org.gcube.data.analysis.tabulardata.expression.composite.comparable.GreaterThan;
|
||||
import org.gcube.data.analysis.tabulardata.expression.leaf.ColumnReferencePlaceholder;
|
||||
import org.gcube.data.analysis.tabulardata.expression.leaf.ConstantList;
|
||||
import org.gcube.data.analysis.tabulardata.model.datatype.DataType;
|
||||
import org.gcube.data.analysis.tabulardata.model.datatype.IntegerType;
|
||||
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDInteger;
|
||||
import org.gcube.data.analysis.tabulardata.model.datatype.value.TDTypeValue;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.C_Expression;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value;
|
||||
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVFileUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class CExpressionMapServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1352918477757397708L;
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(CExpressionMapServlet.class);
|
||||
|
||||
protected static Logger logger = LoggerFactory
|
||||
.getLogger(CExpressionMapServlet.class);
|
||||
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
handleRequest(req, resp);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
handleRequest(req, resp);
|
||||
}
|
||||
|
||||
protected void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
protected void handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
logger.info("CExpressionMapServlet");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
if(session==null){
|
||||
logger.error("Error getting the upload session, no session valid found: "+session);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error getting the user session, no session found"+session);
|
||||
return ;
|
||||
}
|
||||
logger.info("CExpressionMapServlet import session id: "+session.getId());
|
||||
|
||||
|
||||
//response.setContentType("application/json; charset=utf-8");
|
||||
if (session == null) {
|
||||
logger.error("Error getting the upload session, no session valid found: "
|
||||
+ session);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"ERROR-Error getting the user session, no session found"
|
||||
+ session);
|
||||
return;
|
||||
}
|
||||
logger.info("CExpressionMapServlet import session id: "
|
||||
+ session.getId());
|
||||
|
||||
ObjectInputStream in = new ObjectInputStream(request.getInputStream());
|
||||
C_Expression exp=null;
|
||||
try {
|
||||
exp = (C_Expression) in.readObject();
|
||||
logger.debug("CExpressionMapServlet Exp: "+exp);
|
||||
} catch (ClassNotFoundException e) {
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
|
||||
"ERROR-Error retreiving expression in request: "+e.getLocalizedMessage());
|
||||
|
||||
}
|
||||
|
||||
Expression expression = parse(exp);
|
||||
logger.trace("Expression: " + expression.toString());
|
||||
|
||||
response.setContentType("Content-Type: application/java-object");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
|
||||
C_Expression exp=(C_Expression)request.getAttribute("C_Expression");
|
||||
Expression expression=parse(exp);
|
||||
logger.trace("Expression: "+expression.toString());
|
||||
|
||||
ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
|
||||
oos.writeObject(expression);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
logger.trace("Response in "+(System.currentTimeMillis()-startTime));
|
||||
|
||||
ObjectOutputStream oos = new ObjectOutputStream(
|
||||
response.getOutputStream());
|
||||
oos.writeObject(expression);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
logger.trace("Response in " + (System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
|
||||
protected Expression parse(C_Expression exp){
|
||||
List<TDTypeValue> args=new ArrayList<TDTypeValue>();
|
||||
TDInteger value=new TDInteger(1);
|
||||
|
||||
protected Expression parse(C_Expression exp) {
|
||||
List<TDTypeValue> args = new ArrayList<TDTypeValue>();
|
||||
TDInteger value = new TDInteger(1);
|
||||
args.add(value);
|
||||
Expression e=new GreaterThan(new ColumnReferencePlaceholder(new IntegerType(), "1"),
|
||||
new ConstantList(args));
|
||||
Expression e = new GreaterThan(new ColumnReferencePlaceholder(
|
||||
new IntegerType(), "1"), new ConstantList(args));
|
||||
return e;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
<web-app>
|
||||
|
||||
<!-- Servlets -->
|
||||
<servlet>
|
||||
<servlet-name>CExpressionMapServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.user.td.expressionwidget.server.CExpressionMapServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>TDGWTService</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl</servlet-class>
|
||||
|
@ -17,6 +22,10 @@
|
|||
</servlet>
|
||||
|
||||
<!-- Servlets Mapping -->
|
||||
<servlet-mapping>
|
||||
<servlet-name>CExpressionMapServlet</servlet-name>
|
||||
<url-pattern>ExpressionWidget/CExpressionMap</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>TDGWTService</servlet-name>
|
||||
<url-pattern>ExpressionWidget/TDGWTService</url-pattern>
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.client;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.data.analysis.tabulardata.expression.Expression;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.C_Expression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestCExpressionServlet {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
HttpURLConnection cs = null;
|
||||
|
||||
String path = "ExpressionWidget/CExpressionMap";
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL("http://127.0.0.1:8888/" + path);
|
||||
} catch (MalformedURLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
C_Expression exp = new C_Expression();
|
||||
// Save the object's instance
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out;
|
||||
try {
|
||||
out = new ObjectOutputStream(buffer);
|
||||
out.writeObject(exp);
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOException :" + e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare the header
|
||||
byte[] serobj = buffer.toByteArray();
|
||||
|
||||
try {
|
||||
cs = (HttpURLConnection) url.openConnection();
|
||||
|
||||
cs.setConnectTimeout(0);
|
||||
cs.setReadTimeout(0);
|
||||
cs.setRequestMethod("POST");
|
||||
cs.setRequestProperty("User-Agent",
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
|
||||
cs.setDoOutput(true);
|
||||
cs.setDoInput(true);
|
||||
cs.setUseCaches(false);
|
||||
cs.setAllowUserInteraction(false);
|
||||
cs.setRequestProperty("Content-Type", "application/java-object");
|
||||
cs.setRequestProperty("Content-Language", "en-US");
|
||||
cs.setRequestProperty("Content-Length",
|
||||
String.valueOf(serobj.length));
|
||||
OutputStream sout = cs.getOutputStream();
|
||||
sout.write(serobj);
|
||||
|
||||
int HTTPcodicerisposta = cs.getResponseCode();
|
||||
System.out.println("Codice Risposta: " + HTTPcodicerisposta);
|
||||
if (HTTPcodicerisposta == 200) {
|
||||
ObjectInputStream oin = new ObjectInputStream(
|
||||
cs.getInputStream());
|
||||
Expression serverExpression = null;
|
||||
|
||||
try {
|
||||
serverExpression = (Expression) oin.readObject();
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println("Read Object error :"
|
||||
+ e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(serverExpression);
|
||||
|
||||
} else {
|
||||
System.out.println("Codice Risposta: " + HTTPcodicerisposta);
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error: "+e1.getLocalizedMessage());
|
||||
e1.printStackTrace();
|
||||
} finally {
|
||||
cs.disconnect();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue