Skip to content

Commit

Permalink
further minor update for both #71 and #77
Browse files Browse the repository at this point in the history
- fix problem in previous commit, @ service calls
- implement clean up command @ short circuit example
  • Loading branch information
tkohegyi committed Mar 13, 2016
1 parent 5ebf680 commit 742cfeb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,19 @@ protected void doGet(final HttpServletRequest req, final HttpServletResponse res
}

//call further registered services
if (response != null) {
if (response == null) {
response = serviceMap.callExternalService(req, requestedService, resp);
}

//if we still don't have the response, then either provide the service map, or send back that it is unknown request
if (response == null && requestedService.length() > 0) {
response = "{ \"unknownServiceCall\": \"" + req.getMethod() + ":" + requestedService + "\" }";
} else {
//call the built-in listing service (service-map)
response = serviceMap.getMapAsResponse();
resp.setStatus(HttpServletResponse.SC_OK);
if (response == null) {
if (requestedService.length() > 0) {
response = "{ \"unknownServiceCall\": \"" + req.getMethod() + ":" + requestedService + "\" }";
} else {
//call the built-in listing service (service-map)
response = serviceMap.getMapAsResponse();
resp.setStatus(HttpServletResponse.SC_OK);
}
}

//write the answer back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ShortCircuitInterceptor implements ResponseInterceptor, RequestInte
* that means the response should be preserved.
*
* @param wilmaHttpResponse is the response
* @param parameterList may contain the response validity timeout - if not response will be valid forever
* @param parameterList may contain the response validity timeout - if not response will be valid forever
*/
@Override
public void onResponseReceive(WilmaHttpResponse wilmaHttpResponse, ParameterList parameterList) {
Expand Down Expand Up @@ -94,40 +94,56 @@ public void onRequestReceive(WilmaHttpRequest wilmaHttpRequest, ParameterList pa

@Override
public String handleRequest(HttpServletRequest httpServletRequest, String request, HttpServletResponse httpServletResponse) {
String response = null;
boolean myCall = request.equalsIgnoreCase(this.getClass().getSimpleName() + "/circuits");
String myMethod = httpServletRequest.getMethod();
String myQueryString = httpServletRequest.getQueryString();
boolean myCall = request.equalsIgnoreCase(this.getClass().getSimpleName() + "/circuits");

//set default response
response = "{ \"unknownServiceCall\": \"" + myMethod + ":" + request + "\" }";
String response = "{ \"unknownServiceCall\": \"" + myMethod + ":" + request + "\" }";
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
if (myCall) {
if ("get".equalsIgnoreCase(myMethod) && httpServletRequest.getQueryString() == null) {
//list the map (circuits + get)
response = handleCircuitRequest(httpServletResponse);
}
String myQueryString = httpServletRequest.getQueryString();
if (myQueryString != null && myQueryString.length() > 0) {
if ("post".equalsIgnoreCase(myMethod)) {
//save map (to files) (circuits?folder + post)
//TODO
response = handleCircuitRequest(httpServletResponse);
}
if ("get".equalsIgnoreCase(myMethod)) {
//load map (from files) (circuits?folder + get)
//TODO
response = handleCircuitRequest(httpServletResponse);
}
if ("delete".equalsIgnoreCase(myMethod)) {
//invalidate map (remove all from map) (circuits + delete)
//TODO
response = handleCircuitRequest(httpServletResponse);
}
if ("delete".equalsIgnoreCase(myMethod)) {
//invalidate a single entry (remove a specific entry) (circuits/n)
//TODO
response = handleCircuitRequest(httpServletResponse);
}
}

//handle basic call
if (myCall && httpServletRequest.getQueryString() == null) {
response = handleBasicCall(myMethod, httpServletResponse);
}

//handle complex calls
if (myCall && httpServletRequest.getQueryString() != null) {
response = handleComplexCall(myMethod, myQueryString, httpServletResponse);
}
return response;
}

private String handleBasicCall(String myMethod, HttpServletResponse httpServletResponse) {
String response = null;
if ("get".equalsIgnoreCase(myMethod)) {
//list the map (circuits + get)
response = handleCircuitRequest(httpServletResponse);
}
if ("delete".equalsIgnoreCase(myMethod)) {
//invalidate map (remove all from map) (circuits + delete)
shortCircuitMap.clear();
response = handleCircuitRequest(httpServletResponse);
}
return response;
}

private String handleComplexCall(String myMethod, String myQueryString, HttpServletResponse httpServletResponse) {
String response = null;
if ("post".equalsIgnoreCase(myMethod)) {
//save map (to files) (circuits?folder + post)
//TODO
response = handleCircuitRequest(httpServletResponse);
}
if ("get".equalsIgnoreCase(myMethod)) {
//load map (from files) (circuits?folder + get)
//TODO
response = handleCircuitRequest(httpServletResponse);
}
if ("delete".equalsIgnoreCase(myMethod)) {
//invalidate a single entry (remove a specific entry) (circuits/n)
//TODO
response = handleCircuitRequest(httpServletResponse);
}
return response;
}
Expand All @@ -153,8 +169,7 @@ private String handleCircuitRequest(HttpServletResponse httpServletResponse) {
@Override
public Set<String> getHandlers() {
return Sets.newHashSet(
this.getClass().getSimpleName() + "/circuits",
this.getClass().getSimpleName() + "/circuits/"
this.getClass().getSimpleName() + "/circuits"
);
}
}

0 comments on commit 742cfeb

Please sign in to comment.