use of org.apache.struts2.rest.DefaultHttpHeaders in project onebusaway-application-modules by camsys.
the class CurrentTimeActionTest method test.
@Test
public void test() throws ParseException {
CurrentTimeAction action = new CurrentTimeAction();
long t = System.currentTimeMillis();
DefaultHttpHeaders headers = action.index();
assertEquals(200, headers.getStatus());
ResponseBean response = action.getModel();
assertEquals(200, response.getCode());
assertEquals(2, response.getVersion());
@SuppressWarnings("unchecked") EntryWithReferencesBean<TimeBean> entry = (EntryWithReferencesBean<TimeBean>) response.getData();
TimeBean time = entry.getEntry();
assertNotNull(time);
long delta = Math.abs(time.getTime() - t);
assertTrue("check that time delta is within limits: delta=" + delta, delta < 100);
String readableTime = DateLibrary.getTimeAsIso8601String(new Date(time.getTime()));
assertEquals(readableTime, time.getReadableTime());
}
use of org.apache.struts2.rest.DefaultHttpHeaders in project onebusaway-application-modules by camsys.
the class ApiActionSupport method setValidationErrorsResponse.
protected DefaultHttpHeaders setValidationErrorsResponse() {
ValidationErrorBean bean = new ValidationErrorBean(new ArrayList<String>(getActionErrors()), getFieldErrors());
_response = new ResponseBean(getReturnVersion(), ResponseCodes.RESPONSE_INVALID_ARGUMENT, "validation error", bean);
return new DefaultHttpHeaders().withStatus(_response.getCode());
}
use of org.apache.struts2.rest.DefaultHttpHeaders 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);
}
Aggregations