Commit 7c497249 by amir

- add getMD5Hash, catch unhandled exceptions, add command-params builder

parent e2e6fdd9
### Microservice Framework in JAVA ### Microservice Framework in JAVA
## 1.3.2:
- add getMD5Hash, catch unhandled exceptions, add command-params builder
## 1.3.1: ## 1.3.1:
- add rabbotmq command client + change version to 1.3.1 - add rabbotmq command client + change version to 1.3.1
## 1.3.0: ## 1.3.0:
......
group 'com.ipgallery.common' group 'com.ipgallery.common'
version '1.3.1' version '1.3.2'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
...@@ -28,8 +28,6 @@ dependencies { ...@@ -28,8 +28,6 @@ dependencies {
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2' compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
compile 'com.ipgallery.common:utils:1.1.4' compile 'com.ipgallery.common:utils:1.1.4'
compile ('com.ipgallery.common:rabbitmq:1.0.3') compile ('com.ipgallery.common:rabbitmq:1.0.3')
//compile 'com.rabbitmq:amqp-client:3.6.3'
//compile files ('resources/rabbitmq-1.0.x.jar')
compile 'com.ecwid.consul:consul-api:1.1.9' compile 'com.ecwid.consul:consul-api:1.1.9'
compile 'com.github.davidb:metrics-influxdb:0.8.2' compile 'com.github.davidb:metrics-influxdb:0.8.2'
compile 'io.dropwizard.metrics:metrics-graphite:3.1.2' compile 'io.dropwizard.metrics:metrics-graphite:3.1.2'
......
...@@ -17,11 +17,21 @@ public class EncryptionUtils { ...@@ -17,11 +17,21 @@ public class EncryptionUtils {
public final static String JWT_SALT = System.getProperty("jwt.salt","12345678901234567890123456789012"); public final static String JWT_SALT = System.getProperty("jwt.salt","12345678901234567890123456789012");
private static int workload = 5; private static int workload = 5;
public static String getMD5Hash(String data){
String encrypted = getDigestedString(data,"MD5");
return encrypted;
}
public static String getSHA256Hash(String data){ public static String getSHA256Hash(String data){
String encrypted = getDigestedString(data,"SHA-256");
return encrypted;
}
private static String getDigestedString(String data,String algoritm) {
String encrypted = null; String encrypted = null;
MessageDigest md = null; MessageDigest md = null;
try { try {
md = MessageDigest.getInstance("SHA-256"); md = MessageDigest.getInstance(algoritm);
md.update(data.getBytes()); md.update(data.getBytes());
byte byteData[] = md.digest(); byte byteData[] = md.digest();
......
...@@ -81,21 +81,20 @@ public class RestHandler implements HttpHandler , IContainer ...@@ -81,21 +81,20 @@ public class RestHandler implements HttpHandler , IContainer
return; return;
} }
try {
/* /*
* async part * async part
*/ */
RequestContext reqContext = getRequestContext(exchange); RequestContext reqContext = getRequestContext(exchange);
if (reqContext != null) if (reqContext != null) {
{
HttpString requestMethod = exchange.getRequestMethod(); HttpString requestMethod = exchange.getRequestMethod();
EnumHttpMethod eMethod = EnumHttpMethod.resolveMethod(requestMethod.toString()); EnumHttpMethod eMethod = EnumHttpMethod.resolveMethod(requestMethod.toString());
reqContext.enumCrudMethod = Enums.EnumCrudMethod.resolveMethodFromHttp(eMethod); reqContext.enumCrudMethod = Enums.EnumCrudMethod.resolveMethodFromHttp(eMethod);
//exchange. request.setCharacterEncoding(Constants.C_ENCODING_UTF8); //exchange. request.setCharacterEncoding(Constants.C_ENCODING_UTF8);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, Constants.CONTENT_TYPE_JSON); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, Constants.CONTENT_TYPE_JSON);
if (eMethod != null && reqContext != null) if (eMethod != null && reqContext != null) {
{
if (validateRequest(reqContext)) { if (validateRequest(reqContext)) {
// pre // pre
if (enableMetrics) if (enableMetrics)
...@@ -122,16 +121,18 @@ public class RestHandler implements HttpHandler , IContainer ...@@ -122,16 +121,18 @@ public class RestHandler implements HttpHandler , IContainer
if (enableMetrics) if (enableMetrics)
postHandleMetrics(eMethod); postHandleMetrics(eMethod);
} }
} else {
sendErrorResp(reqContext.response, Constants.METHOD_NOT_IMPLEMENTED);
} }
else } else {
{ IResponse iResp = new IResponseRestImpl(exchange);
sendErrorResp(reqContext.response,Constants.METHOD_NOT_IMPLEMENTED); sendErrorResp(iResp, Constants.FAILED_TO_GET_PARAMS);
} }
} }
else catch (Exception exp)
{ {
IResponse iResp = new IResponseRestImpl(exchange); IResponse iResp = new IResponseRestImpl(exchange);
sendErrorResp(iResp,Constants.FAILED_TO_GET_PARAMS); sendErrorResp(iResp, exp.toString());
} }
/* /*
......
...@@ -11,9 +11,11 @@ public class CommandParams ...@@ -11,9 +11,11 @@ public class CommandParams
String content; String content;
Map<String,String> headersMap = null; Map<String,String> headersMap = null;
public CommandParams() {
}
public CommandParams(String entity, String paramsString, public CommandParams(String entity, String paramsString,
String requestParams, String content,Map<String,String> headersMap) String requestParams, String content, Map<String,String> headersMap)
{ {
super(); super();
this.entity = entity; this.entity = entity;
...@@ -61,6 +63,31 @@ public class CommandParams ...@@ -61,6 +63,31 @@ public class CommandParams
return content; return content;
} }
public Map<String, String> getHeadersMap() {
return headersMap;
}
public void setEntity(String entity) {
this.entity = entity;
}
public void setParams(String[] params) {
this.params = params;
}
public void setParamsString(String paramsString) {
this.paramsString = paramsString;
}
public void setRequestParams(String requestParams) {
this.requestParams = requestParams;
}
public void setContent(String content) {
this.content = content;
}
public void setHeadersMap(Map<String, String> headersMap) {
this.headersMap = headersMap;
}
} }
package microservice.params;
import java.util.Map;
/**
* Created by amir on 15/08/16.
*/
public class CommandParamsBuilder {
CommandParams commandParams = new CommandParams();
public CommandParamsBuilder setEntity(String entity) {
commandParams.setEntity(entity);
return this;
}
public CommandParamsBuilder setParams(String[] params) {
if (commandParams.getParamsString() == null)
commandParams.setParams(params);
return this;
}
public CommandParamsBuilder setParamsString(String paramsString) {
if (commandParams.getParams() == null)
commandParams.setParamsString(paramsString);
return this;
}
public CommandParamsBuilder setRequestParams(String requestParams) {
commandParams.setRequestParams(requestParams);
return this;
}
public CommandParamsBuilder setContent(String content) {
commandParams.setContent(content);
return this;
}
public CommandParamsBuilder setHeadersMap(Map<String, String> headersMap) {
commandParams.setHeadersMap(headersMap);
return this;
}
public CommandParams build(){
return commandParams;
}
}
...@@ -4,7 +4,9 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -4,7 +4,9 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import microservice.io.iface.ICommandClient; import microservice.io.iface.ICommandClient;
import microservice.io.impl.IRMQClientRestImpl; import microservice.io.impl.IRMQClientRestImpl;
import microservice.params.BaseClientParams;
import microservice.params.CommandParams; import microservice.params.CommandParams;
import microservice.params.CommandParamsBuilder;
import microservice.params.RMQClientParams; import microservice.params.RMQClientParams;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
import org.junit.Test; import org.junit.Test;
...@@ -129,10 +131,25 @@ public class TestCommandClient { ...@@ -129,10 +131,25 @@ public class TestCommandClient {
} }
@Test @Test
public void testCommand() throws InterruptedException public void testCommand() throws InterruptedException
{ {
ASM asm = new ASM();
ASMClient asmClient = new ASMClient(asm);
MicroserviceClient msClient = new MicroserviceClient(asmClient, new BaseClientParams("", false, 0));
CommandParams reqCtx = new CommandParams("AE", "ae1", null, null, null);
msClient.create(reqCtx);
System.out.println("sleeping");
//Thread.sleep(5000);
reqCtx = new CommandParams("AE", "ae1", null, null, null);
BaseRestResponse readBrr = msClient.read(reqCtx);
System.out.println(readBrr.objectNode.toString());
System.out.println("end test");
}
@Test
public void testRabbitCommand() throws InterruptedException
{
try { try {
RMQClientParams clientParams = new RMQClientParams("test", "respQ@localhost", "myFirstQ@localhost", 1, 100, "/logs"); RMQClientParams clientParams = new RMQClientParams("test", "respQ@localhost", "myFirstQ@localhost", 1, 100, "/logs");
...@@ -148,4 +165,13 @@ public class TestCommandClient { ...@@ -148,4 +165,13 @@ public class TestCommandClient {
} }
System.out.println("end test"); System.out.println("end test");
} }
@Test
public void testCommandParams()
{
CommandParams commandParams = new CommandParamsBuilder()
.setEntity("test")
.setParamsString("stam")
.build();
}
} }
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 sign in to comment