private Response doSyncUpdate(final Request request) { loggerContext.init(getRequestId(request.getRemoteAddress())); try { if (!sourceMatchesContext(request.getSource())) { return Response.status(Response.Status.BAD_REQUEST) .entity("Invalid source specified: " + request.getSource()) .build(); } boolean notificationsEnabled = true; if (request.isParam(Command.REDIRECT)) { if (!ipRanges.isTrusted(IpInterval.parse(request.getRemoteAddress()))) { return Response.status(Response.Status.FORBIDDEN) .entity("Not allowed to disable notifications: " + request.getRemoteAddress()) .build(); } notificationsEnabled = false; } if (!request.hasParam(Command.DATA) && request.isParam(Command.NEW)) { return Response.status(Response.Status.BAD_REQUEST) .entity("DATA parameter is missing") .build(); } if (!request.hasParam(Command.DATA) && !request.isParam(Command.HELP)) { return Response.status(Response.Status.BAD_REQUEST).entity("Invalid request").build(); } loggerContext.log("msg-in.txt", new SyncUpdateLogCallback(request.toString())); final UpdateContext updateContext = new UpdateContext(loggerContext); final String content = request.hasParam("DATA") ? request.getParam("DATA") : ""; final UpdateRequest updateRequest = new UpdateRequest( new SyncUpdate(dateTimeProvider, request.getRemoteAddress()), getKeyword(request), content, updatesParser.parse( updateContext, Lists.newArrayList(new ContentWithCredentials(content))), notificationsEnabled); final UpdateResponse updateResponse = updateRequestHandler.handle(updateRequest, updateContext); loggerContext.log("msg-out.txt", new SyncUpdateLogCallback(updateResponse.getResponse())); return getResponse(updateResponse); } finally { loggerContext.remove(); } }
private Charset getCharset(final String contentType) { if (contentType != null && contentType.length() > 0) { final String charset = getHeaderParameter(contentType, "charset"); if (charset != null && charset.length() > 0) { try { return Charset.forName(charset.toUpperCase()); } catch (UnsupportedCharsetException e) { loggerContext.log( new Message(Messages.Type.INFO, "Unsupported charset: %s, using default.", charset)); } catch (IllegalCharsetNameException e) { loggerContext.log( new Message(Messages.Type.INFO, "Illegal charset name: %s, using default.", charset)); } } } return Charsets.ISO_8859_1; }
private void setSsoSessionToContext(final UpdateContext updateContext, final String ssoToken) { if (!StringUtils.isBlank(ssoToken)) { try { updateContext.setUserSession(ssoTokenTranslator.translateSsoToken(ssoToken)); } catch (CrowdClientException e) { loggerContext.log(new Message(Messages.Type.ERROR, e.getMessage())); updateContext.addGlobalMessage(RestMessages.ssoAuthIgnored()); } } }