Commit 384a7c87 by Adi Amir

Add skeleton for HttpAdapter

parent f2efc933
{
"serviceId": "transportation",
"BaseURL": "http://www.ctabustracker.com/bustime/api/v1",
"apiList": [{
"id": "getroutes",
"method": "GET",
"uri": "getroutes",
"QueryParams": [{
"key": "$config$chicago.transportation.key"
}]
}]
}
\ No newline at end of file
{
"adapters": [{
"id": "chicago.transportationn",
"instance": "CHttpAdapter:jarName",
"configFile": "chicago.transportation.json"
}]
}
\ No newline at end of file
{
"services": [{
"apiId": "getroutes",
"actions": [{
"id": "forwardRequest",
"adapterId": "chicago.transportation",
"apiId": "getroutes",
"Responses": [{
"code": "*",
"actionId": "sendResponseToOriginator"
}]
}]
}, {
"apiId": "getNearestBus",
"actions": [{
"id": "forwardRequest",
"adapterId": "Chicago.transportation",
"apiId": "getNearestBus",
"Responses": [{
"code": "*",
"actionId": "sendResponseToOriginator"
}]
}]
}]
}
\ No newline at end of file
{
"services": [ { "id": "chicago.transportation" } ]
}
\ No newline at end of file
MDE Configuration files
=======================
file(service list): services.json
{
"services": [ { "id": "services.chicago.transportation" } ]
}
file(services): services.chicago.transportation.json.
{
"services": [{
"apiId": "getroutes",
"actions": [{
"id": "forwardRequest",
"adapterId": "chicago.transportation",
"apiId": "getroutes",
"Responses": [{
"code": "*",
"actionId": "sendResponseToOriginator"
}]
}]
}, {
"apiId": "getNearestBus",
"actions": [{
"id": "forwardRequest",
"adapterId": "Chicago.transportation",
"apiId": "getroutes",
"Responses": [{
"code": "*",
"actionId": "sendResponseToOriginator"
}]
}]
}]
}
file(adapter list): adapters.json
{
"adapters": [{
"id": "chicago.transportationn",
"instance": "CHttpAdapter:jarName",
"configFile": "chicago.transportation.json"
}]
}
file(adapter api(s)): chicago.transportation.json
{
"serviceId": "transportation",
"BaseURL": "http://www.ctabustracker.com/bustime/api/v1",
"apiList": [{
"id": "getRoutes",
"method": "GET",
"uri": "getroutes",
"QueryParams": [{
"key": "$config.key"
}]
}]
}
Flow
====
http://www.ctabustracker.com/bustime/api/v1/getroutes?key=gT2nciTKwRv6Jy5njqm8fe7LW
GET ../mde/{tenantId}/{serviceId}/{apiId}
mde.HandleRequest(reqCtx)
{
service = getService(chicago.transportation/*serviceId*/)
api = service.getApi({apiId})
action = api.getFirstAction(api)
while (action)
{
adapter = action.getAdapter()
action.handleRquest(reqCtx)
action = getNextAction()
}
api.handleRequest(reqCtx);
}
...@@ -2,10 +2,10 @@ package handlers; ...@@ -2,10 +2,10 @@ package handlers;
import logic.MdeManager; import logic.MdeManager;
import logic.adapter.HttpAdapter.HttpAdapter;
import microservice.RequestContext; import microservice.RequestContext;
import microservice.handlers.BaseHandler; import microservice.handlers.BaseHandler;
import microservice.io.iface.ILogger; import microservice.io.iface.ILogger;
import util.Enums;
import utils.common.CacheClient; import utils.common.CacheClient;
import utils.common.RedisCacheClient; import utils.common.RedisCacheClient;
import utils.http.simpleRestClient.SimpleRestResponse; import utils.http.simpleRestClient.SimpleRestResponse;
...@@ -41,8 +41,14 @@ public class MdeHandler extends BaseHandler { ...@@ -41,8 +41,14 @@ public class MdeHandler extends BaseHandler {
@Override @Override
public void doRead(RequestContext requestContext) { public void doRead(RequestContext requestContext) {
int i =0;
i++; // GET ../mde/{tenantId}/{serviceId}/{apiId}
String tenantId = requestContext.params[0];
String serviceId = requestContext.params[1];
String apiId = requestContext.params[2];
HttpAdapter httpAdapter = new HttpAdapter();
httpAdapter.handleRequest(requestContext);
} }
@Override @Override
......
package logic.adapter;
import microservice.RequestContext;
/**
* Created by adi on 13/06/16.
*/
public abstract class BaseAdapter {
public void handleRequest(RequestContext requestContext) {
}
}
package logic.adapter.HttpAdapter;
import java.util.ArrayList;
import java.util.List;
/**
* Created by adi on 13/06/16.
*/
public class DataHttpAdapter {
public static enum eParamSource {
EPath,
EContent,
EQueryParams
};
public String serviceId = null;
public String baseUrl = null;
public List<DataHttpAdapterApi> apiList= null;
public DataHttpAdapter() {
apiList = new ArrayList<DataHttpAdapterApi>();
}
}
package logic.adapter.HttpAdapter;
import java.util.List;
/**
* Created by adi on 13/06/16.
*/
public class DataHttpAdapterApi {
public String id = null;
public String method = null;
public String uri = null;
public String content = null;
public List<String> pathList = null;
public List<String> queryParamsList = null;
}
package logic.adapter.HttpAdapter;
import logic.adapter.BaseAdapter;
import microservice.RequestContext;
/**
* Created by adi on 13/06/16.
*/
public class HttpAdapter extends BaseAdapter {
protected String id = null;
public HttpAdapter() {
}
public Boolean Init(String id) {
this.id = id;
return LoadFromFile(id);
}
public void handleRequest(RequestContext requestContext) {
String tenantId = requestContext.params[0];
String serviceId = requestContext.params[1];
String apiId = requestContext.params[2];
// todo: build the url & send to site
}
protected Boolean LoadFromFile(String id) {
return false;
}
}
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