use of com.opensymphony.xwork2.ActionProxy in project onebusaway-application-modules by camsys.
the class ApiKeyInterceptor method unauthorized.
// package private for unit tests
String unauthorized(ActionInvocation invocation, ApiKeyPermissionService.Status reason) throws IOException {
ActionProxy proxy = invocation.getProxy();
int httpCode = ResponseCodes.RESPONSE_UNAUTHORIZED;
String message = "permission denied";
switch(reason) {
case UNAUTHORIZED:
httpCode = ResponseCodes.RESPONSE_UNAUTHORIZED;
break;
case RATE_EXCEEDED:
httpCode = ResponseCodes.RESPONSE_TOO_MANY_REQUESTS;
message = "rate limit exceeded";
break;
case AUTHORIZED:
// this should never happen!
throw new IllegalStateException("Valid status code " + reason + " in unauthorized response");
default:
httpCode = ResponseCodes.RESPONSE_UNAUTHORIZED;
}
ResponseBean response = new ResponseBean(1, httpCode, message, null);
DefaultHttpHeaders methodResult = new DefaultHttpHeaders().withStatus(response.getCode());
return _handlerSelector.handleResult(proxy.getConfig(), methodResult, response);
}
use of com.opensymphony.xwork2.ActionProxy in project onebusaway-application-modules by camsys.
the class ExceptionInterceptor method getActionAsUrl.
private String getActionAsUrl(ActionInvocation invocation) {
ActionProxy proxy = invocation.getProxy();
ActionContext context = invocation.getInvocationContext();
StringBuilder b = new StringBuilder();
b.append(proxy.getNamespace());
b.append("/");
b.append(proxy.getActionName());
b.append("!");
b.append(proxy.getMethod());
Map<String, Object> params = context.getParameters();
if (!params.isEmpty()) {
b.append("?");
boolean seenFirst = false;
for (Map.Entry<String, Object> entry : params.entrySet()) {
// Prune out any identifying information
if ("app_uid".equals(entry.getKey()))
continue;
Object value = entry.getValue();
String[] values = (value instanceof String[]) ? (String[]) value : new String[] { value.toString() };
for (String v : values) {
if (seenFirst)
b.append("&");
else
seenFirst = true;
b.append(entry.getKey());
b.append("=");
b.append(v);
}
}
}
return b.toString();
}
use of com.opensymphony.xwork2.ActionProxy in project onebusaway-application-modules by camsys.
the class IndexActionTest method testExecute.
@Test
public void testExecute() throws Exception {
ActionProxy proxy = Mockito.mock(ActionProxy.class);
Mockito.when(proxy.getActionName()).thenReturn("index");
Mockito.when(proxy.getNamespace()).thenReturn("/");
ActionInvocation invocation = Mockito.mock(ActionInvocation.class);
Mockito.when(invocation.getProxy()).thenReturn(proxy);
Map<String, Object> c = new HashMap<String, Object>();
ActionContext ac = new ActionContext(c);
ac.setActionInvocation(invocation);
ActionContext.setContext(ac);
IndexAction action = new IndexAction();
String response = action.execute();
assertEquals("successful response", "success", response);
}
Aggregations