Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
591b93c7
Commit
591b93c7
authored
Mar 11, 2017
by
skoulouzis
Committed by
GitHub
Mar 11, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #32 from skoulouzis/package
Package
parents
50b04be1
b68c5ae0
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
116 additions
and
107 deletions
+116
-107
vcs.xml
.idea/vcs.xml
+0
-6
NOTES
doc/NOTES
+5
-1
SecurityConfig.java
...rc/main/java/nl/uva/sne/drip/api/conf/SecurityConfig.java
+2
-3
UserService.java
...rc/main/java/nl/uva/sne/drip/api/service/UserService.java
+19
-2
UserController0.java
...ain/java/nl/uva/sne/drip/api/v0/rest/UserController0.java
+10
-1
UserController.java
...main/java/nl/uva/sne/drip/api/v1/rest/UserController.java
+7
-6
drip.properties
drip-api/src/main/resources/drip.properties
+1
-1
rpc_server.py
drip-deployer/rpc_server.py
+2
-2
rpc_server.py
drip-planner/rpc_server.py
+1
-1
pom.xml
drip-provisioner/pom.xml
+0
-5
Consumer.java
.../main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
+12
-13
RPCServer.java
...main/java/nl/uva/sne/drip/drip/provisioner/RPCServer.java
+1
-1
pom.xml
drip-simple_planner/pom.xml
+1
-7
Consumer.java
.../src/main/java/nl/uva/sne/drip/drip/planner/Consumer.java
+55
-57
Planner.java
...r/src/main/java/nl/uva/sne/drip/drip/planner/Planner.java
+0
-1
No files found.
.idea/vcs.xml
deleted
100644 → 0
View file @
50b04be1
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
doc/NOTES
View file @
591b93c7
#-------------------------Dockers--------------------------------------------
docker run -
d --hostname my-rabbit --name some-rabbit
rabbitmq:3-management
docker run -
-hostname my-rabbit --name some-rabbit -p 127.0.0.1:15672:15672 -d
rabbitmq:3-management
docker run --name mongo-inst -p 127.0.0.1:27017:27017 -d mongo:3
#--------Add admin-----------------
docker exec -t mongo-inst mongo -eval 'db.user.insert({"password":"$2a$10$QdysFgsH0sl6Y4BD84UhGO7yyNfoDPXjjEHkDJ3pX6cRfHDj2Q0BO","roles":["ADMIN"],"username":"admin","accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"enabled":true})' localhost/drip
drip-api/src/main/java/nl/uva/sne/drip/api/conf/SecurityConfig.java
View file @
591b93c7
...
...
@@ -21,7 +21,6 @@ import nl.uva.sne.drip.api.service.UserService;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.access.expression.method.MethodSecurityExpressionHandler
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
...
...
@@ -37,8 +36,8 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
*/
@Configuration
@EnableWebSecurity
//
@EnableGlobalMethodSecurity(jsr250Enabled = true, prePostEnabled = true)
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
@EnableGlobalMethodSecurity
(
jsr250Enabled
=
true
,
prePostEnabled
=
true
)
//
@EnableGlobalMethodSecurity(prePostEnabled = true)
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Autowired
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/UserService.java
View file @
591b93c7
...
...
@@ -15,6 +15,7 @@
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.api.dao.UserDao
;
...
...
@@ -49,7 +50,23 @@ public class UserService implements UserDetailsService {
return
null
;
}
public
UserDao
getDao
()
{
return
dao
;
public
User
save
(
User
user
)
{
return
dao
.
save
(
user
);
}
public
User
findOne
(
String
id
)
{
return
dao
.
findOne
(
id
);
}
public
void
delete
(
User
user
)
{
dao
.
delete
(
user
);
}
public
List
<
User
>
findAll
()
{
return
dao
.
findAll
();
}
public
void
deleteAll
()
{
dao
.
deleteAll
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/UserController0.java
View file @
591b93c7
...
...
@@ -15,6 +15,8 @@
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
v0
.
rest
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.exception.PasswordNullException
;
import
nl.uva.sne.drip.api.exception.UserExistsException
;
...
...
@@ -62,8 +64,15 @@ public class UserController0 {
}
User
user
=
new
User
();
user
.
setUsername
(
register
.
user
);
user
.
setAccountNonExpired
(
true
);
user
.
setAccountNonLocked
(
true
);
user
.
setEnabled
(
true
);
user
.
setCredentialsNonExpired
(
true
);
Collection
<
String
>
roles
=
new
ArrayList
<>();
roles
.
add
(
"USER"
);
user
.
setRoles
(
roles
);
user
.
setPassword
(
new
BCryptPasswordEncoder
().
encode
(
register
.
pwd
));
service
.
getDao
()
.
save
(
user
);
user
=
service
.
save
(
user
);
return
"Success: "
+
user
.
getId
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/UserController.java
View file @
591b93c7
...
...
@@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.service.UserService
;
import
org.springframework.security.access.prepost.PostAuthorize
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -75,7 +76,7 @@ public class UserController {
throw
new
UserExistsException
(
"Username "
+
user
.
getUsername
()
+
" is used"
);
}
user
.
setPassword
(
new
BCryptPasswordEncoder
().
encode
(
user
.
getPassword
()));
service
.
getDao
()
.
save
(
user
);
user
=
service
.
save
(
user
);
return
user
.
getId
();
}
...
...
@@ -101,7 +102,7 @@ public class UserController {
public
@ResponseBody
User
get
(
@PathVariable
(
"id"
)
String
id
)
{
try
{
User
user
=
service
.
getDao
().
findOne
(
id
);
User
user
=
service
.
findOne
(
id
);
if
(
user
==
null
)
{
throw
new
UserNotFoundException
(
"User "
+
id
+
" not found"
);
}
...
...
@@ -123,11 +124,11 @@ public class UserController {
public
@ResponseBody
String
remove
(
@PathVariable
(
"id"
)
String
id
)
{
try
{
User
user
=
service
.
getDao
().
findOne
(
id
);
User
user
=
service
.
findOne
(
id
);
if
(
user
==
null
)
{
throw
new
UserNotFoundException
(
"User "
+
id
+
" not found"
);
}
service
.
getDao
().
delete
(
user
);
service
.
delete
(
user
);
return
"Deleted : "
+
id
;
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
UserController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
...
...
@@ -145,7 +146,7 @@ public class UserController {
public
@ResponseBody
List
<
String
>
getIds
()
{
try
{
List
<
User
>
all
=
service
.
getDao
().
findAll
();
List
<
User
>
all
=
service
.
findAll
();
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
User
tr
:
all
)
{
ids
.
add
(
tr
.
getId
());
...
...
@@ -162,7 +163,7 @@ public class UserController {
public
@ResponseBody
List
<
User
>
getAll
()
{
try
{
return
service
.
getDao
().
findAll
();
return
service
.
findAll
();
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
UserController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
...
...
drip-api/src/main/resources/drip.properties
View file @
591b93c7
message.broker.host
=
1
72.17.0.3
message.broker.host
=
1
27.0.0.1
db.name
=
drip
db.username
=
drip-user
db.password
=
drip-pass
drip-deployer/rpc_server.py
View file @
591b93c7
...
...
@@ -11,7 +11,7 @@ import docker_swarm
import
control_agent
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
'1
72.17.0.3
'
))
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
'1
27.0.0.1
'
))
channel
=
connection
.
channel
()
channel
.
queue_declare
(
queue
=
'deployer_queue'
)
...
...
@@ -87,4 +87,4 @@ channel.basic_qos(prefetch_count=1)
channel
.
basic_consume
(
on_request
,
queue
=
'deployer_queue'
)
print
(
" [x] Awaiting RPC requests"
)
channel
.
start_consuming
()
\ No newline at end of file
channel
.
start_consuming
()
drip-planner/rpc_server.py
View file @
591b93c7
...
...
@@ -17,7 +17,7 @@ import json
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
'1
72.17.0.3
'
))
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
'1
27.0.0.1
'
))
channel
=
connection
.
channel
()
channel
.
queue_declare
(
queue
=
'planner_queue'
)
...
...
drip-provisioner/pom.xml
View file @
591b93c7
...
...
@@ -15,11 +15,6 @@
</properties>
<dependencies>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-commons
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
View file @
591b93c7
...
...
@@ -38,7 +38,6 @@ import java.util.Map;
import
java.util.Properties
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.commons.types.MessageParameter
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONArray
;
...
...
@@ -376,12 +375,12 @@ public class Consumer extends DefaultConsumer {
private
File
getCloudConfigurationFile
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
MessageParameter
.
NAME
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"ec2.conf"
)
||
name
.
equals
(
"geni.conf"
))
{
try
{
File
confFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
name
);
if
(
confFile
.
createNewFile
())
{
writeValueToFile
((
String
)
param
.
get
(
MessageParameter
.
VALUE
),
confFile
);
writeValueToFile
((
String
)
param
.
get
(
"value"
),
confFile
);
return
confFile
;
}
else
{
return
null
;
...
...
@@ -398,7 +397,7 @@ public class Consumer extends DefaultConsumer {
private
File
getTopology
(
JSONArray
parameters
,
String
tempInputDirPath
,
int
level
)
throws
JSONException
,
IOException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
MessageParameter
.
NAME
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"topology"
))
{
JSONObject
attributes
=
param
.
getJSONObject
(
"attributes"
);
int
fileLevel
=
Integer
.
valueOf
((
String
)
attributes
.
get
(
"level"
));
...
...
@@ -419,7 +418,7 @@ public class Consumer extends DefaultConsumer {
File
topologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
);
topologyFile
.
createNewFile
();
String
val
=
(
String
)
param
.
get
(
MessageParameter
.
VALUE
);
String
val
=
(
String
)
param
.
get
(
"value"
);
writeValueToFile
(
val
,
topologyFile
);
return
topologyFile
;
}
...
...
@@ -432,13 +431,13 @@ public class Consumer extends DefaultConsumer {
Map
<
String
,
File
>
files
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
MessageParameter
.
NAME
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"certificate"
))
{
JSONObject
attribute
=
param
.
getJSONObject
(
"attributes"
);
String
fileName
=
(
String
)
attribute
.
get
(
"filename"
);
File
certificate
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
+
".pem"
);
if
(
certificate
.
createNewFile
())
{
writeValueToFile
((
String
)
param
.
get
(
MessageParameter
.
VALUE
),
certificate
);
writeValueToFile
((
String
)
param
.
get
(
"value"
),
certificate
);
files
.
put
(
fileName
,
certificate
);
}
}
...
...
@@ -449,9 +448,9 @@ public class Consumer extends DefaultConsumer {
private
String
getLogDirPath
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
MessageParameter
.
NAME
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"logdir"
))
{
return
(
String
)
param
.
get
(
MessageParameter
.
VALUE
);
return
(
String
)
param
.
get
(
"value"
);
}
}
return
System
.
getProperty
(
"java.io.tmpdir"
);
...
...
@@ -460,9 +459,9 @@ public class Consumer extends DefaultConsumer {
private
File
getSSHKey
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
,
IOException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
MessageParameter
.
NAME
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"sshkey"
))
{
String
sshKeyContent
=
(
String
)
param
.
get
(
MessageParameter
.
VALUE
);
String
sshKeyContent
=
(
String
)
param
.
get
(
"value"
);
File
sshKeyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
"user.pem"
);
if
(
sshKeyFile
.
createNewFile
())
{
writeValueToFile
(
sshKeyContent
,
sshKeyFile
);
...
...
@@ -476,9 +475,9 @@ public class Consumer extends DefaultConsumer {
private
File
getSciptFile
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
,
IOException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
MessageParameter
.
NAME
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"guiscript"
))
{
String
scriptContent
=
(
String
)
param
.
get
(
MessageParameter
.
VALUE
);
String
scriptContent
=
(
String
)
param
.
get
(
"value"
);
File
scriptFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
"guiscipt.sh"
);
if
(
scriptFile
.
createNewFile
())
{
writeValueToFile
(
scriptContent
,
scriptFile
);
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/RPCServer.java
View file @
591b93c7
...
...
@@ -31,7 +31,7 @@ import java.util.logging.Logger;
public
class
RPCServer
{
private
static
final
String
RPC_QUEUE_NAME
=
"provisioner_queue"
;
private
static
final
String
HOST
=
"1
72.17.0.3
"
;
private
static
final
String
HOST
=
"1
27.0.0.1
"
;
public
static
void
main
(
String
[]
argv
)
{
start
();
...
...
drip-simple_planner/pom.xml
View file @
591b93c7
...
...
@@ -13,13 +13,7 @@
<maven.compiler.target>
1.8
</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-commons
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependencies>
<dependency>
<groupId>
com.rabbitmq
</groupId>
<artifactId>
amqp-client
</artifactId>
...
...
drip-simple_planner/src/main/java/nl/uva/sne/drip/drip/planner/Consumer.java
View file @
591b93c7
...
...
@@ -33,8 +33,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.commons.types.MessageParameter
;
import
nl.uva.sne.drip.commons.types.Message
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -77,9 +75,9 @@ public class Consumer extends DefaultConsumer {
throw
new
FileNotFoundException
(
"Could not create output directory: "
+
tempDir
.
getAbsolutePath
());
}
//We need to extact the call parameters form the json message.
inputFiles
=
jacksonUnmarshalExample
(
message
);
//
inputFiles = jacksonUnmarshalExample(message);
//Call the method with the extracted parameters
List
<
File
>
files
=
panner
.
plan
(
inputFiles
[
0
].
getAbsolutePath
(),
inputFiles
[
1
].
getAbsolutePath
(),
tempDir
.
getAbsolutePath
());
//
List<File> files = panner.plan(inputFiles[0].getAbsolutePath(), inputFiles[1].getAbsolutePath(), tempDir.getAbsolutePath());
//Here we do the same as above with a different API
// inputFiles = simpleJsonUnmarshalExample(message);
...
...
@@ -87,7 +85,7 @@ public class Consumer extends DefaultConsumer {
// files = panner.plan(inputFiles[0].getAbsolutePath(), inputFiles[1].getAbsolutePath(), tempDir.getAbsolutePath());
//Now we need to put the result of the call to a message and respond
//Example 1
response
=
jacksonMarshalExample
(
files
);
//
response = jacksonMarshalExample(files);
//Example 2
// response = simpleJsonMarshalExample(files);
...
...
@@ -102,35 +100,35 @@ public class Consumer extends DefaultConsumer {
}
private
File
[]
jacksonUnmarshalExample
(
String
message
)
throws
IOException
{
//Use the Jackson API to convert json to Object
File
[]
files
=
new
File
[
2
];
ObjectMapper
mapper
=
new
ObjectMapper
();
Message
request
=
mapper
.
readValue
(
message
,
Message
.
class
);
List
<
MessageParameter
>
params
=
request
.
getParameters
();
//Create tmp input files
File
inputFile
=
File
.
createTempFile
(
"input-"
,
Long
.
toString
(
System
.
nanoTime
()));
File
exampleFile
=
File
.
createTempFile
(
"example-"
,
Long
.
toString
(
System
.
nanoTime
()));
//loop through the parameters in a message to find the input files
for
(
MessageParameter
param
:
params
)
{
if
(
param
.
getName
().
equals
(
"input"
))
{
try
(
PrintWriter
out
=
new
PrintWriter
(
inputFile
))
{
out
.
print
(
param
.
getValue
());
}
files
[
0
]
=
inputFile
;
}
if
(
param
.
getName
().
equals
(
"example"
))
{
try
(
PrintWriter
out
=
new
PrintWriter
(
exampleFile
))
{
out
.
print
(
param
.
getValue
());
}
files
[
1
]
=
exampleFile
;
}
}
//Return the array with input files
return
files
;
}
//
private File[] jacksonUnmarshalExample(String message) throws IOException {
//
//Use the Jackson API to convert json to Object
//
File[] files = new File[2];
//
ObjectMapper mapper = new ObjectMapper();
//
Message request = mapper.readValue(message, Message.class);
//
//
List<MessageParameter> params = request.getParameters();
//
//
//Create tmp input files
//
File inputFile = File.createTempFile("input-", Long.toString(System.nanoTime()));
//
File exampleFile = File.createTempFile("example-", Long.toString(System.nanoTime()));
//
//loop through the parameters in a message to find the input files
//
for (MessageParameter param : params) {
//
if (param.getName().equals("input")) {
//
try (PrintWriter out = new PrintWriter(inputFile)) {
//
out.print(param.getValue());
//
}
//
files[0] = inputFile;
//
}
//
if (param.getName().equals("example")) {
//
try (PrintWriter out = new PrintWriter(exampleFile)) {
//
out.print(param.getValue());
//
}
//
files[1] = exampleFile;
//
}
//
}
//
//Return the array with input files
//
return files;
//
}
private
File
[]
simpleJsonUnmarshalExample
(
String
message
)
throws
JSONException
,
FileNotFoundException
,
IOException
{
//Use the JSONObject API to convert json to Object (Message)
...
...
@@ -141,16 +139,16 @@ public class Consumer extends DefaultConsumer {
File
exampleFile
=
File
.
createTempFile
(
"example-"
,
Long
.
toString
(
System
.
nanoTime
()));
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
MessageParameter
.
NAME
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"input"
))
{
try
(
PrintWriter
out
=
new
PrintWriter
(
inputFile
))
{
out
.
print
(
param
.
get
(
MessageParameter
.
VALUE
));
out
.
print
(
param
.
get
(
"value"
));
}
files
[
0
]
=
inputFile
;
}
if
(
name
.
equals
(
"example"
))
{
try
(
PrintWriter
out
=
new
PrintWriter
(
exampleFile
))
{
out
.
print
(
param
.
get
(
MessageParameter
.
VALUE
));
out
.
print
(
param
.
get
(
"value"
));
}
files
[
1
]
=
exampleFile
;
}
...
...
@@ -158,26 +156,26 @@ public class Consumer extends DefaultConsumer {
return
files
;
}
private
String
jacksonMarshalExample
(
List
<
File
>
files
)
throws
UnsupportedEncodingException
,
IOException
{
//Use the jackson API to convert Object (Message) to json
Message
responseMessage
=
new
Message
();
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
for
(
File
f
:
files
)
{
MessageParameter
fileParam
=
new
MessageParameter
();
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
f
.
getAbsolutePath
()));
fileParam
.
setValue
(
new
String
(
bytes
,
charset
));
fileParam
.
setEncoding
(
charset
);
fileParam
.
setName
(
f
.
getName
());
parameters
.
add
(
fileParam
);
}
responseMessage
.
setParameters
(
parameters
);
//The creationDate is the only filed that has to be there
responseMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
ObjectMapper
mapper
=
new
ObjectMapper
();
return
mapper
.
writeValueAsString
(
responseMessage
);
}
//
private String jacksonMarshalExample(List<File> files) throws UnsupportedEncodingException, IOException {
//
//Use the jackson API to convert Object (Message) to json
//
Message responseMessage = new Message();
//
List parameters = new ArrayList();
//
String charset = "UTF-8";
//
for (File f : files) {
//
MessageParameter fileParam = new MessageParameter();
//
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
//
fileParam.setValue(new String(bytes, charset));
//
fileParam.setEncoding(charset);
//
fileParam.setName(f.getName());
//
parameters.add(fileParam);
//
}
//
responseMessage.setParameters(parameters);
//
//The creationDate is the only filed that has to be there
//
responseMessage.setCreationDate((System.currentTimeMillis()));
//
//
ObjectMapper mapper = new ObjectMapper();
//
return mapper.writeValueAsString(responseMessage);
//
}
private
String
simpleJsonMarshalExample
(
List
<
File
>
files
)
throws
JSONException
,
IOException
{
//Use the JSONObject API to convert Object (Message) to json
...
...
drip-simple_planner/src/main/java/nl/uva/sne/drip/drip/planner/Planner.java
View file @
591b93c7
...
...
@@ -24,7 +24,6 @@ import java.io.IOException;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
nl.uva.sne.drip.commons.utils.Converter
;
/**
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment