Advertisement
jbjares

serviceCall

May 18th, 2015
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1.     private PAKCRestServiceWrapperTO callService(
  2.             SimulationInstanceTO simulationInstanceTO,
  3.             SessionIndexTO sessionIndexTO, InputStream is) throws Exception {
  4.  
  5.         String session = null;
  6.         PAKCRestServiceWrapperTO result = new PAKCRestServiceWrapperTO();
  7.         PAKCRestServiceTO simulationInstance = new PAKCRestServiceTO();
  8.         byte[] cfgFileByteArr = IOUtils.toByteArray(is);
  9.         simulationInstance.setCfgFile(cfgFileByteArr);
  10.         String parameter = Util.getJsonStrFromObject(simulationInstance);
  11.  
  12.         System.out
  13.                 .println("http://213.249.38.66:7072/SolverInterface/webresources/solver/authenticate"
  14.                         + "/testusername/password");
  15.         session = Request
  16.                 .Get("http://213.249.38.66:7072/SolverInterface/webresources/solver/authenticate"
  17.                         + "/testusername/password").execute().returnContent()
  18.                 .asString();
  19.         System.out.println(session);
  20.  
  21.         Request.Post(
  22.                 "http://213.249.38.66:7072/SolverInterface/webresources/ConfigurationFile/upload/"
  23.                         + session)
  24.                 .bodyForm(
  25.                         Form.form().add("simulationInstance", parameter)
  26.                                 .build()).execute();
  27.  
  28.         Request.Get(
  29.                 "http://213.249.38.66:7072/SolverInterface/webresources/solver/cad/init"
  30.                         + "/" + session).execute();
  31.  
  32.         Integer status = HttpStatus.SC_NOT_FOUND;
  33.         while(status!=HttpStatus.SC_OK){
  34.             status = getStatus(session);
  35.             Thread.sleep(15000);
  36.         }
  37.         System.out.println();
  38.         System.out.println("OK");
  39.         /*
  40.          * Thread.sleep(240000);
  41.          */
  42.  
  43.         //subscribeWithTopicLookup(session);
  44.         System.out.println(" -------------- Done");
  45.         String responseContentStr = Request
  46.                 .Get("http://213.249.38.66:7072/SolverInterface/webresources/accessResults/simulation/"
  47.                         + session).execute().returnContent().asString();
  48.         System.out.println(" -------------- Done");
  49.         Gson gson = new GsonBuilder().create();
  50.         simulationInstance = gson.fromJson(responseContentStr,PAKCRestServiceTO.class);
  51.        
  52.         InputStream datIS = new ByteArrayInputStream(simulationInstance.getDatFile());
  53.         InputStream unvIS = new ByteArrayInputStream(simulationInstance.getUnvFile());
  54.  
  55.         System.out.println(" -------------- Done");
  56.         result.setSessionID(session);
  57.         result.setDatFile(datIS);
  58.         result.setUnvFile(unvIS);
  59.  
  60.         System.out.println(" -------------- Done Result");
  61.         return result;
  62.  
  63.     }
  64.  
  65.     private int getStatus(String session) throws ClientProtocolException, IOException {
  66.         CloseableHttpClient httpclient = HttpClients.createDefault();
  67.         int result = 0;
  68.         try{
  69.             HttpGet getRequest = new HttpGet(
  70.                     "http://213.249.38.66:7072/SolverInterface/webresources/accessResults/simulation"+ "/" + session);
  71.             getRequest.addHeader("accept", "application/json");
  72.            
  73.             HttpResponse response = httpclient.execute(getRequest);
  74.             result = response.getStatusLine().getStatusCode();
  75.         }finally{
  76.             httpclient.close();
  77.             httpclient.getConnectionManager().shutdown();
  78.         }
  79.         return result;
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement