Commit 7d846333 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Created example code for component

parent 712a0c14
......@@ -6,4 +6,5 @@
/drip-provisioner/target/
/target/
/drip-planner2provisioner/target/
/drip-component_example/target/
\ No newline at end of file
/drip-component_example/target/
/deleteme/target/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>deleteme</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package nl.uva.sne.drip.deleteme;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Base64;
/**
*
* @author alogo
*/
public class Main {
public static void main(String[] args) throws IOException {
byte[] bytes = Files.readAllBytes(Paths.get("/home/alogo/workspace/DRIP/docs/images/DRIP_arch.png"));
byte[] encoded = Base64.getEncoder().encode(bytes);
String cont = new String(encoded, "US-ASCII");
System.out.println(cont);
byte[] decoded = Base64.getDecoder().decode(cont);
OpenOption[] options = new OpenOption[1];
options[0] = StandardOpenOption.CREATE_NEW;
Files.write(Paths.get("/home/alogo/Downloads/DRIP_arch.png"), decoded, options);
}
}
This diff is collapsed.
......@@ -15,10 +15,30 @@
*/
package nl.uva.sne.drip.drip.component_example;
import java.io.File;
/**
* This is an example components. It is a dumy components to demonstrate a
* simple application logic
*
* @author S. Koulouzis
* @author S. Koulouziss
*/
public class Component {
private final int input;
private final File inputTextFile;
private final File inputBinFile;
private final ExamplePOJO book;
public Component(int input, File inputTextFile, File inputBinFile, ExamplePOJO book) {
this.input = input;
this.inputTextFile = inputTextFile;
this.inputBinFile = inputBinFile;
this.book = book;
}
String run() throws Exception {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.drip.component_example;
/**
*
* @author S. Koulouzis
*/
public class ExamplePOJO {
private final String author;
private final String content;
private final String translator;
private final String language;
public ExamplePOJO(String author, String content, String translator, String language) {
this.author = author;
this.content = content;
this.translator = translator;
this.language = language;
}
/**
* @return the author
*/
public String getAuthor() {
return author;
}
/**
* @return the content
*/
public String getContent() {
return content;
}
/**
* @return the translator
*/
public String getTranslator() {
return translator;
}
/**
* @return the language
*/
public String getLanguage() {
return language;
}
}
......@@ -29,6 +29,7 @@ import java.util.Properties;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
/**
* This class is responsible for receiving and sending message to the DRIP
......@@ -52,9 +53,9 @@ public class RPCServer {
try {
Consumer c = new Consumer();
byte[] encoded = Files.readAllBytes(Paths.get(args[1]));
String response = c.handleDelivery(new String(encoded, "UTF-8"));
String response = c.invokeComponent(new String(encoded, "UTF-8"));
Logger.getLogger(RPCServer.class.getName()).log(Level.INFO, MessageFormat.format("Response: {0}", response));
} catch (IOException ex) {
} catch (IOException | JSONException ex) {
Logger.getLogger(RPCServer.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
......
......@@ -12,5 +12,6 @@
<modules>
<module>drip-api</module>
<module>drip-planner2provisioner</module>
<module>deleteme</module>
</modules>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment