package kr.ac.kaist.resl.lilliput.rest; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import kr.ac.kaist.resl.lilliput.core.DeviceInformationAdapter; import kr.ac.kaist.resl.lilliput.core.SNSPusher; import kr.ac.kaist.resl.lilliput.util.EPCISHelper; import net.sf.json.xml.XMLSerializer; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Hex; import org.fosstrak.epcis.model.Poll; import org.fosstrak.epcis.model.QueryResults; import org.fosstrak.epcis.queryclient.QueryControlClient; import org.fosstrak.epcis.soap.ImplementationExceptionResponse; import org.fosstrak.epcis.soap.NoSuchNameExceptionResponse; import org.fosstrak.epcis.soap.QueryParameterExceptionResponse; import org.fosstrak.epcis.soap.QueryTooComplexExceptionResponse; import org.fosstrak.epcis.soap.QueryTooLargeExceptionResponse; import org.fosstrak.epcis.soap.SecurityExceptionResponse; import org.fosstrak.epcis.soap.ValidationExceptionResponse; import org.fosstrak.epcis.utils.QueryResultsParser; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.restlet.ext.json.JsonRepresentation; import org.restlet.resource.Get; import org.restlet.resource.ServerResource; import edu.stanford.smi.protegex.owl.model.RDFIndividual; public class LatencyTest extends ServerResource { @Get("json") public JsonRepresentation toJson() throws JSONException, DecoderException { try { String value = getQuery().getValues("value"); String numberS = getQuery().getValues("number"); int number = Integer.parseInt(numberS); XMLSerializer serializer = new XMLSerializer(); net.sf.json.JSONObject resultJSON = (net.sf.json.JSONObject)serializer.read(value); JSONObject returnObject = new JSONObject(resultJSON.toString()); //Reflecting it to the IoT-Social Graph DeviceInformationAdapter da = new DeviceInformationAdapter(); FileOutputStream stream = new FileOutputStream("Before.txt",true); long pretime1 = System.nanoTime(); String message = number + "\t" + (double)pretime1/1000000000+"\n"; System.out.println("Before : " + message ); stream.write(message.getBytes()); stream.close(); da.latencyTest(returnObject, number); return null; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject err = new JSONObject(); err.put("message", "error occured"); JsonRepresentation representation = new JsonRepresentation(err); return representation; } }