protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
OAuthMessage message = new HttpRequestMessage(req, req.getRequestURL().toString());
// OAuth %-escapes the @ in the username so we need to decode it.
String username = OAuth.decodePercent(message.getConsumerKey());
ParticipantId participant;
try {
participant = ParticipantId.of(username);
} catch (InvalidParticipantAddress e) {
LOG.info("Participant id invalid", e);
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
AccountData account;
try {
account = accountStore.getAccount(participant);
} catch (PersistenceException e) {
LOG.severe("Failed to retrieve account data for " + participant, e);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"An unexpected error occured while trying to retrieve account data for "
+ participant.getAddress());
return;
}
if (account == null || !account.isRobot()) {
LOG.info("The account for robot named " + participant + " does not exist");
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
OAuthConsumer consumer =
new OAuthConsumer(null, participant.getAddress(), account.asRobot().getConsumerSecret(),
oauthServiceProvider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
processOpsRequest(req, resp, message, accessor, participant);
}