Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.

Assignment 6 (up)

 
Write for a correlator for a predefined process. Hints: 
 

Assignment 6a - Preparation (2 points) (up)

You manage an inventory (for your topic). Answer the following questions: 
 
Additionally: write three REST services, das describe above. 

Submission (up)

MANDATORY AND VERY IMPORTANT: Register the rest services via «http://donatello.cs.univie.ac.at/tools_lehre/interop/2021/correlation_phase1/index.php». 

Hints (up)

Assignment 6b - Correlation (10 points) (up)

Write and register a correlation service via «http://donatello.cs.univie.ac.at/tools_lehre/interop/2021/correlation_phase2/index.php». 
 
Implement the correlator logic: To create a process instance, change the process template, and instantiate (from file) it through «https://cpee.org/flow/». 
How to change the process template: 
When the correlator is called from the engine it should answer, that it wants to call back later. 
<call id="a4" endpoint="correlation">
  <parameters>
    <label>"Warten auf Fortschritt"</label>
    <method>:post</method>
    <parameters>
      <pid>data.pid</pid>
    </parameters>
  </parameters>
  <finalize>data.progress = result["progress"]</finalize>
</call>
 
<finalize>data.progress = result["progress"]</finalize>
 
Example for GET requests using «Slim»: 
<?php
  $app = AppFactory::create();
  $app->setBasePath("[your_url]");
  $app->addBodyParsingMiddleware();
  $app->get('', function (Request $request, Response $response, array $args) {
    $response = $response-> withStatus(200);
    $response = $response->withHeader('Content-Type','application/json');
    $response = $response->withAddedHeader('CPEE_CALLBACK','true');
    $rueckgabe = new stdClass();
    $rueckgabe->method = $request->getMethod();
    $rueckgabe->headers= $request->getHeaders();
    $rueckgabe->bodyParams= $request->getParsedBody();
    $rueckgabe->queryParams= $request->getQueryParams();
    //TODO: log to file, database, ...
    $response->getBody()->write(json_encode($rueckgabe));
    return $response;
  });
  $app->run();
?>
 
Example using raw php (can also be found via «http://wwwlab.cs.univie.ac.at/~stertzf9/callback/server.phps»): 
<?php
  include('rest_handle.php');
  $rest = handleREST($_SERVER,$_GET);
  //******* Receiving CPEE POST . CPEE can issue also GET PUT und DELETE requests.
  if ($rest->method=="POST"){
    //******* The correlator can log requests via
    $fh = fopen("log.log","a");
    //******* Write ALL headers in a file.
    fwrite($fh,print_r(getallheaders(),true));
    //******* Set following header to inform CPEE that we will reply later.
    header('CPEE_CALLBACK: true');
  }
/*
  The headers may look like bellow. You will require [Cpee_callback].
  A PUT request to this address progresses the state of the process instance.
  (
    [Cpee_base] => http://cpee.org
    [Cpee_instance] => http://cpee.org/194
    [Cpee_callback] => http://cpee.org/194/callbacks/22b728c475d6f70ec970ce0a130a22fa
    [Cpee_activity] => a1
    [Cpee_label] => Wir werden warten
    [Cpee_attr_info] => ss
    [Cpee_attr_modeltype] => CPEE
    [Accept-Encoding] => gzip;q=1.0,deflate;q=0.6,identity;q=0.3
    [Accept] => *//*
    [User-Agent] => Ruby
    [Content-Type] => text/plain
    [Content-Length] => 0
    [Host] => wwwlab.cs.univie.ac.at
  )
*/
?>
 
Example using php curl («documentation»): 
<?php
  $curl_handle = curl_init();
  curl_setopt($curl_handle, CURLOPT_URL, "[url]");
  curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl_handle, CURLOPT_PUT, true);
  curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
  $body = json_encode(array('key'=>'value','key1'=>'value1'));
  $file = fopen('php://temp', 'w');
  fwrite($file, $body);
  fseek($file, 0);
  curl_setopt($curl_handle, CURLOPT_INFILE, $file);
  curl_setopt($curl_handle, CURLOPT_INFILESIZE, strlen($body));
  $result = curl_exec($curl_handle);
  if(curl_error($curl_handle)) {
    print(curl_error($curl_handle));
  }
  else {
    var_dump($result);
  }
  fclose($file);
  curl_close($curl_handle);
?>
 
 
Example using raw php: 
<?
  $opts = array('http' =>
    array(
      'method'  => 'PUT',
      'header'  => 'Content-type: application/json',
      'content' => JSON_DATA
    )
  );
  $context = stream_context_create($opts);
  $result = file_get_contents('http://...', false, $context);
  exit;
?>

Submission (up)

DONT FORGET: change /testset/attributes/info. 
 
MANDATORY AND VERY IMPORTANT: Register the rest services via «http://donatello.cs.univie.ac.at/tools_lehre/interop/2021/correlation_phase2/».  

Hints (up)

Letzte Änderung: 11.06.2021, 11:26 | 862 Worte