|
@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
|
import com.yihu.hos.core.http.HTTPResponse;
|
|
|
import com.yihu.hos.core.http.HttpClientKit;
|
|
|
import org.apache.camel.Body;
|
|
|
import org.apache.camel.Exchange;
|
|
|
import org.apache.camel.Message;
|
|
|
import org.apache.camel.Processor;
|
|
@ -26,22 +25,24 @@ public class GatewayProcessor implements Processor {
|
|
|
|
|
|
public void process(Exchange exchange) throws Exception {
|
|
|
Message inMessage = exchange.getIn();
|
|
|
String appKey = exchange.getIn().getHeaders().get("appKey").toString();
|
|
|
String secret = getSecret(appKey);
|
|
|
exchange.setOut(inMessage);
|
|
|
exchange.getOut().setHeader("secret", secret);
|
|
|
}
|
|
|
Map<String, Object> headers = exchange.getIn().getHeaders();
|
|
|
// exchange.setOut(inMessage);
|
|
|
exchange.getOut().setHeader("api", headers.get("api"));
|
|
|
exchange.getOut().setHeader("param", headers.get("param"));
|
|
|
exchange.getOut().setHeader("timestamp", headers.get("timestamp"));
|
|
|
exchange.getOut().setHeader("v", headers.get("v"));
|
|
|
exchange.getOut().setHeader("appKey", headers.get("appKey"));
|
|
|
exchange.getOut().setHeader("sign", headers.get("sign"));
|
|
|
|
|
|
public String secret(@Body String body, Exchange exchange) throws IOException, ParseException {
|
|
|
System.out.println(body);
|
|
|
String appKey = exchange.getIn().getHeaders().get("appKey").toString();
|
|
|
return "restlet:"+ agUrl + "/api/v1.0/admin/apps/" + appKey;
|
|
|
}
|
|
|
|
|
|
|
|
|
public String route(Exchange exchange) throws IOException, ParseException {
|
|
|
// body = URLDecoder.decode(body, "UTF-8");
|
|
|
Map<String, Object> params = exchange.getIn().getHeaders();
|
|
|
String secret = params.get("secret").toString();
|
|
|
String appKey = params.get("appKey").toString();
|
|
|
String secret = getSecret(appKey);
|
|
|
|
|
|
if (secret.equals("")) {
|
|
|
return "jetty:http://0.0.0.0:9999/error/paramError"; //TODO:
|
|
|
}
|
|
@ -96,8 +97,8 @@ public class GatewayProcessor implements Processor {
|
|
|
|
|
|
Calendar date = Calendar.getInstance();
|
|
|
long timeInMillis = date.getTimeInMillis();
|
|
|
java.util.Date min = new java.util.Date(timeInMillis - 5 * ONE_MIN);
|
|
|
java.util.Date max = new java.util.Date(timeInMillis + 5 * ONE_MIN);
|
|
|
java.util.Date min = new java.util.Date(timeInMillis - 30 * ONE_MIN);
|
|
|
java.util.Date max = new java.util.Date(timeInMillis + 30 * ONE_MIN);
|
|
|
|
|
|
return ts.after(min) && ts.before(max);
|
|
|
|
|
@ -194,6 +195,7 @@ public class GatewayProcessor implements Processor {
|
|
|
if (body[0].length() != 0) {
|
|
|
exchange.getOut().setHeader(Exchange.REST_HTTP_QUERY, body[0].substring(1));
|
|
|
}
|
|
|
// exchange.getOut().setBody(null);
|
|
|
return endPoint[0];
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|