use of org.restlet.data.Parameter in project OpenAM by OpenRock.
the class OAuth2Representation method toRepresentation.
/**
* Converts the authorization token into a representation to send back to the user agent.
*
* @param context The Restlet context.
* @param request The Restlet request.
* @param response The Restlet response.
* @param authorizationToken The authorization token.
* @param redirectUri The redirect uri.
* @return The representation to send to the user agent.
*/
Representation toRepresentation(Context context, Request request, Response response, AuthorizationToken authorizationToken, String redirectUri) {
final Form tokenForm = toForm(authorizationToken);
final Reference redirectReference = new Reference(redirectUri);
if (authorizationToken.isFragment()) {
redirectReference.setFragment(tokenForm.getQueryString());
} else {
final Iterator<Parameter> iter = tokenForm.iterator();
while (iter.hasNext()) {
redirectReference.addQueryParameter(iter.next());
}
}
if (isFormPostRequest(requestFactory.create(request))) {
return getFormPostRepresentation(context, authorizationToken, redirectReference.toString());
}
final Redirector dispatcher = new Redirector(context, redirectReference.toString(), Redirector.MODE_CLIENT_FOUND);
dispatcher.handle(request, response);
return response == null ? null : response.getEntity();
}
use of org.restlet.data.Parameter in project OpenAM by OpenRock.
the class OpenAMResourceOwnerSessionValidator method removeLoginPrompt.
/**
* Removes "login" from prompt query parameter.
*
* This needs to be done before redirecting the user to login so that an infinite redirect loop is avoided.
*/
private void removeLoginPrompt(Request req) {
Form query = req.getResourceRef().getQueryAsForm();
Parameter param = query.getFirst(PROMPT);
if (param != null && param.getValue() != null) {
String newValue = param.getValue().toLowerCase().replace(OpenIdPrompt.PROMPT_LOGIN, "").trim();
param.setValue(newValue);
}
req.getResourceRef().setQuery(query.getQueryString());
}
use of org.restlet.data.Parameter in project camel by apache.
the class RestletComponent method addServerIfNecessary.
protected void addServerIfNecessary(RestletEndpoint endpoint) throws Exception {
String key = buildKey(endpoint);
Server server;
synchronized (servers) {
server = servers.get(key);
if (server == null) {
server = createServer(endpoint);
component.getServers().add(server);
// Add any Restlet server parameters that were included
Series<Parameter> params = server.getContext().getParameters();
if ("https".equals(endpoint.getProtocol())) {
SSLContextParameters scp = endpoint.getSslContextParameters();
if (endpoint.getSslContextParameters() == null) {
throw new InvalidParameterException("Need to specify the SSLContextParameters option here!");
}
setupServerWithSSLContext(params, scp);
}
if (getControllerDaemon() != null) {
params.add("controllerDaemon", getControllerDaemon().toString());
}
if (getControllerSleepTimeMs() != null) {
params.add("controllerSleepTimeMs", getControllerSleepTimeMs().toString());
}
if (getInboundBufferSize() != null) {
params.add("inboundBufferSize", getInboundBufferSize().toString());
}
if (getMinThreads() != null) {
params.add("minThreads", getMinThreads().toString());
}
if (getMaxThreads() != null) {
params.add("maxThreads", getMaxThreads().toString());
}
if (getLowThreads() != null) {
params.add("lowThreads", getLowThreads().toString());
}
if (getMaxQueued() != null) {
params.add("maxQueued", getMaxQueued().toString());
}
if (getMaxConnectionsPerHost() != null) {
params.add("maxConnectionsPerHost", getMaxConnectionsPerHost().toString());
}
if (getMaxTotalConnections() != null) {
params.add("maxTotalConnections", getMaxTotalConnections().toString());
}
if (getOutboundBufferSize() != null) {
params.add("outboundBufferSize", getOutboundBufferSize().toString());
}
if (getPersistingConnections() != null) {
params.add("persistingConnections", getPersistingConnections().toString());
}
if (getPipeliningConnections() != null) {
params.add("pipeliningConnections", getPipeliningConnections().toString());
}
if (getThreadMaxIdleTimeMs() != null) {
params.add("threadMaxIdleTimeMs", getThreadMaxIdleTimeMs().toString());
}
if (getUseForwardedForHeader() != null) {
params.add("useForwardedForHeader", getUseForwardedForHeader().toString());
}
if (getReuseAddress() != null) {
params.add("reuseAddress", getReuseAddress().toString());
}
LOG.debug("Setting parameters: {} to server: {}", params, server);
server.getContext().setParameters(params);
servers.put(key, server);
LOG.debug("Added server: {}", key);
server.start();
}
}
}
use of org.restlet.data.Parameter in project qi4j-sdk by Qi4j.
the class FormResponseWriter method writeResponse.
@Override
public boolean writeResponse(final Object result, final Response response) throws ResourceException {
if (result instanceof Form) {
MediaType type = getVariant(response.getRequest(), ENGLISH, supportedMediaTypes).getMediaType();
if (MediaType.APPLICATION_JSON.equals(type)) {
JSONObject json = new JSONObject();
Form form = (Form) result;
try {
for (Parameter parameter : form) {
String value = parameter.getValue();
if (value == null) {
json.put(parameter.getName(), JSONObject.NULL);
} else {
json.put(parameter.getName(), value);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
StringRepresentation representation = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON);
response.setEntity(representation);
return true;
} else if (MediaType.TEXT_HTML.equals(type)) {
Representation rep = new WriterRepresentation(MediaType.TEXT_HTML) {
@Override
public void write(Writer writer) throws IOException {
Map<String, Object> root = new HashMap<String, Object>();
root.put("request", response.getRequest());
root.put("response", response);
root.put("result", result);
try {
Template formHtmlTemplate = cfg.getTemplate("form.htm");
formHtmlTemplate.process(root, writer);
} catch (TemplateException e) {
throw new IOException(e);
}
}
};
response.setEntity(rep);
return true;
}
}
return false;
}
use of org.restlet.data.Parameter in project OpenAM by OpenRock.
the class OpenAMResourceOwnerSessionValidator method alterMaxAge.
/**
* After we are sent to authN we will come back to authZ, next time make sure
* we don't fail to max_age again (in case it's only a few seconds),
* otherwise we'll loop forever and ever...
*/
private void alterMaxAge(OAuth2Request req) {
final Request request = req.getRequest();
Form query = request.getResourceRef().getQueryAsForm();
Parameter param = query.getFirst(MAX_AGE);
if (param == null) {
param = new Parameter(MAX_AGE, CONFIRMED_MAX_AGE);
query.add(param);
} else {
param.setValue(CONFIRMED_MAX_AGE);
}
request.getResourceRef().setQuery(query.getQueryString());
}
Aggregations