Refine search
/** * Create an HTTPS restlet Server instance matching the given parameters. * * @param port * @param address * @param keystorePath * @param keystorePassword * @param keyPassword */ protected void setupServer(int port, String address, String keystorePath, String keystorePassword, String keyPassword) { Server server = new Server(Protocol.HTTPS,address,port,null); component.getServers().add(server); server.getContext().getParameters().add("keystorePath", keystorePath); server.getContext().getParameters().add("keystorePassword", keystorePassword); server.getContext().getParameters().add("keyPassword", keyPassword); }
public AdminRestletResource() { _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); }
/** * Creates a protected child context. This is especially useful for new * application attached to their parent component, to ensure their isolation * from the other applications. By default it just creates a new context * instance. * * @return The child context. */ public Context createChildContext() { return new Context(); }
_component.getClients().add(Protocol.WAR); final Context applicationContext = _component.getContext().createChildContext(); applicationContext.getAttributes().put(ControllerConf.class.toString(), _config); applicationContext.getAttributes().put(HelixMirrorMakerManager.class.toString(), _helixMirrorMakerManager); applicationContext.getAttributes().put(ValidationManager.class.toString(), _validationManager); applicationContext.getAttributes().put(SourceKafkaClusterValidationManager.class.toString(), _srcKafkaValidationManager); applicationContext.getAttributes().put(KafkaBrokerTopicObserver.class.toString(), _kafkaBrokerTopicObserverMap.get(SRC_KAFKA_CLUSTER)); applicationContext.getAttributes().put(AutoTopicWhitelistingManager.class.toString(), _autoTopicWhitelistingManager);
public TopicManagementRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); _autoTopicWhitelistingManager = (AutoTopicWhitelistingManager) getApplication().getContext() .getAttributes().get(AutoTopicWhitelistingManager.class.toString()); if (getApplication().getContext().getAttributes() .containsKey(KafkaBrokerTopicObserver.class.toString())) { _srcKafkaBrokerTopicObserver = (KafkaBrokerTopicObserver) getApplication().getContext() .getAttributes().get(KafkaBrokerTopicObserver.class.toString()); } else { _srcKafkaBrokerTopicObserver = null; } }
public XWikiJaxRsApplication(Context context) { this.jaxRsClasses = new HashSet<Class< ? >>(); ComponentManager componentManager = (ComponentManager) context.getAttributes().get(Constants.XWIKI_COMPONENT_MANAGER); /* Look up all the component that are markes as XWikiRestComponent. */ List<ComponentDescriptor<XWikiRestComponent>> cds = componentManager.getComponentDescriptorList(XWikiRestComponent.class); for (ComponentDescriptor<XWikiRestComponent> cd : cds) { this.jaxRsClasses.add(cd.getImplementation()); context.getLogger().log(Level.FINE, String.format("%s registered.", cd.getImplementation().getName())); } context.getLogger().log(Level.INFO, "RESTful API subsystem initialized."); }
private void validateState(Request request, Form params) throws Exception { String sessionId = request.getCookies().getFirstValue("_state"); String state = (String) getContext().getAttributes().get(sessionId); if (state != null && state.equals(params.getFirstValue(STATE))) { return; } // CSRF detected throw new Exception("The state does not match."); }
/** * Constructor. * * @param context * The context. * @param protocols * The connector protocols. * @param helperClass * Optional helper class name. */ public Client(Context context, List<Protocol> protocols, String helperClass) { super(context, protocols); if ((protocols != null) && !protocols.isEmpty()) { if (Engine.getInstance() != null) { this.helper = Engine.getInstance().createHelper(this, helperClass); } else { this.helper = null; } } else { this.helper = null; } if (context != null && this.helper != null) { context.getAttributes().put("org.restlet.engine.helper", this.helper); } }
/** * Unget current authorization session. */ protected void ungetAuthSession() { String sessionId = getCookies().getFirstValue(ClientCookieID); // cleanup cookie. if (sessionId != null && sessionId.length() > 0) { ConcurrentMap<String, Object> attribs = getContext() .getAttributes(); attribs.remove(sessionId); } }
private String setupState(Response response) { String sessionId = UUID.randomUUID().toString(); byte[] secret = new byte[20]; random.nextBytes(secret); String state = Base64.encode(secret, false); CookieSetting cs = new CookieSetting("_state", sessionId); response.getCookieSettings().add(cs); getContext().getAttributes().put(sessionId, state); return state; }
public static void main( String[] args ) throws Exception { Energy4Java polygene = new Energy4Java( ); Server server = new Server( Protocol.HTTP, 8888 ); Application app = polygene.newApplication( new ForumAssembler(), new MetadataService() ); app.activate(); ContextRestlet restlet = app.findModule( "REST", "Restlet" ).newObject( ContextRestlet.class, new org.restlet.Context() ); ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm"); MapVerifier mapVerifier = new MapVerifier(); mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray()); guard.setVerifier(mapVerifier); guard.setNext(restlet); server.setNext( restlet ); server.start(); } }
/** * Constructor. * * @param context * The context from which the client dispatcher will be * retrieved. * @param serviceUri * The service URI. * @throws IOException */ public Service(Context context, String serviceUri) throws IOException { this(context.getClientDispatcher(), serviceUri, context .getClientDispatcher() .handle(new Request(Method.GET, serviceUri)).getEntity()); }
@Override protected int thresholdReached(Request request, Response response, CounterResult counterResult) { Context.getCurrentLogger().log( Level.FINE, "The current request has been blocked because \"" + counterResult.getCountedValue() + "\" issued too many requests."); response.setStatus(Status.CLIENT_ERROR_TOO_MANY_REQUESTS); return Filter.SKIP; }
private ClientResource createClientResource(String url, boolean buffering) { ClientResource clientResource = new ClientResource(new Context(), url); clientResource.getContext().getParameters().add("socketConnectTimeoutMs", String.valueOf(CONNECTION_TIMEOUT)); clientResource.getContext().getParameters().add("maxIoIdleTimeMs", String.valueOf(CONNECTION_TIMEOUT)); clientResource.setEntityBuffering(buffering); return clientResource; }
/** * Returns the value of the "loginPage" parameter. * * @param c * The context where to find the parameter. * @return The value of the "loginPage" parameter. */ public static String getLoginPage(Context c) { return c.getParameters().getFirstValue("login", "/login"); }
public static void main(String[] args) throws Exception { Engine.setLogLevel(Level.FINE); Server server = null; server = new Server(new Context(), Protocol.SIP, Integer.parseInt(args[0]), UacServerResource.class); } else { server = new Server(new Context(), Protocol.SIP, UacServerResource.class); .getParameters() .add((String) entry.getKey(), (String) entry.getValue());
/** * Returns the logger to use. * * @return The logger to use. */ public Logger getLogger() { return (getContext() != null) ? getContext().getLogger() : Context .getCurrentLogger(); }
/** * Returns the value of the "authSkipApproved" parameter. * * @param c * The context where to find the parameter. * @return The value of the "authSkipApproved" parameter. */ public static boolean getAuthSkipApproved(Context c) { c.getLogger().fine("Trying to get auth page template"); String skip = c.getParameters().getFirstValue("authSkipApproved"); if (skip == null) return false; return Boolean.parseBoolean(skip); }
/** * Sets the value of the "authPage" parameter. * * @param authPage * The value of the "authPage" parameter. * @param c * The context to update. */ public static void setAuthPage(String authPage, Context c) { c.getParameters().set("authPage", authPage); }
/** * Checks the context and sets it if necessary. * * @param target * The target Restlet. */ protected void checkContext(Restlet target) { if ((target.getContext() == null) && (this.parentContext != null)) { target.setContext(this.parentContext.createChildContext()); } }