org.restlet.util.Series Java Examples
The following examples show how to use
org.restlet.util.Series.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoteCarService.java From microservices-comparison with Apache License 2.0 | 6 votes |
@Override public List<Car> list() { Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("truststorePath", System.getProperty("javax.net.ssl.trustStore")); ClientResource clientResource = new ClientResource("https://localhost:8043/api/cars/cars"); clientResource.setNext(client); ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER); challenge.setRawValue(Request.getCurrent().getAttributes().getOrDefault("token", "").toString()); clientResource.setChallengeResponse(challenge); CarServiceInterface carServiceInterface = clientResource.wrap(CarServiceInterface.class); Car[] allCars = carServiceInterface.getAllCars(); try { client.stop(); } catch (Exception e) { throw new RuntimeException(e); } return asList(allCars); }
Example #2
Source File: Preference.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Returns the modifiable list of parameters. Creates a new instance if no * one has been set. * * @return The modifiable list of parameters. */ public Series<Parameter> getParameters() { // Lazy initialization with double-check. Series<Parameter> p = this.parameters; if (p == null) { synchronized (this) { p = this.parameters; if (p == null) { this.parameters = p = new Series<Parameter>(Parameter.class); } } } return p; }
Example #3
Source File: PolygeneRestApplication.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public synchronized void start() throws Exception { setName( polygeneApplication.name() ); Series<Parameter> parameters = getContext().getParameters(); String mode = parameters.getFirstValue( "org.apache.polygene.runtime.mode" ); super.start(); getLogger().info( "RestApplication successfully started." ); }
Example #4
Source File: RestComponent.java From microservices-comparison with Apache License 2.0 | 5 votes |
@Inject public RestComponent(@Hello Application helloApp, @Car Application carApp, Verifier authTokenVerifier) { getClients().add(Protocol.HTTPS); Server secureServer = getServers().add(Protocol.HTTPS, 8043); Series<Parameter> parameters = secureServer.getContext().getParameters(); parameters.add("sslContextFactory", "org.restlet.engine.ssl.DefaultSslContextFactory"); parameters.add("keyStorePath", System.getProperty("javax.net.ssl.keyStorePath")); getDefaultHost().attach("/api/hello", secure(helloApp, authTokenVerifier, "ame")); getDefaultHost().attach("/api/cars", secure(carApp, authTokenVerifier, "ame")); replaceConverter(JacksonConverter.class, new JacksonCustomConverter()); }
Example #5
Source File: Request.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Sets the modifiable series of cookies provided by the client. Note that * when used with HTTP connectors, this property maps to the "Cookie" * header. This method clears the current series and adds all entries in the * parameter series. * * @param cookies * A series of cookies provided by the client. */ public void setCookies(Series<Cookie> cookies) { synchronized (getCookies()) { if (cookies != getCookies()) { if (getCookies() != null) { getCookies().clear(); } if (cookies != null) { getCookies().addAll(cookies); } } } }
Example #6
Source File: Request.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Returns the modifiable series of cookies provided by the client. Creates * a new instance if no one has been set.<br> * <br> * Note that when used with HTTP connectors, this property maps to the * "Cookie" header. * * @return The cookies provided by the client. */ public Series<Cookie> getCookies() { // Lazy initialization with double-check. Series<Cookie> c = this.cookies; if (c == null) { synchronized (this) { c = this.cookies; if (c == null) { this.cookies = c = new Series<Cookie>(Cookie.class); } } } return c; }
Example #7
Source File: Response.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Returns the modifiable series of cookie settings provided by the server. * Creates a new instance if no one has been set.<br> * <br> * Note that when used with HTTP connectors, this property maps to the * "Set-Cookie" and "Set-Cookie2" headers. * * @return The cookie settings provided by the server. */ public Series<CookieSetting> getCookieSettings() { // Lazy initialization with double-check. Series<CookieSetting> c = this.cookieSettings; if (c == null) { synchronized (this) { c = this.cookieSettings; if (c == null) { this.cookieSettings = c = new Series<CookieSetting>( CookieSetting.class); } } } return c; }
Example #8
Source File: Context.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Sets the modifiable series of parameters. This method clears the current * series and adds all entries in the parameter series. * * @param parameters * A series of parameters. */ public void setParameters(Series<Parameter> parameters) { synchronized (getParameters()) { if (parameters != getParameters()) { getParameters().clear(); if (parameters != null) { getParameters().addAll(parameters); } } } }
Example #9
Source File: Context.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Constructor. * * @param logger * The logger instance of use. */ public Context(Logger logger) { this.attributes = new ConcurrentHashMap<String, Object>(); this.logger = logger; this.parameters = new Series<Parameter>(Parameter.class, new CopyOnWriteArrayList<Parameter>()); this.defaultVerifier = null; }
Example #10
Source File: ContextUtils.java From ontopia with Apache License 2.0 | 5 votes |
public static Parameter getParameter(Context context, String name) { Series<Parameter> parameters = getParameters(context); if (parameters == null) { return null; } return parameters.getFirst(name); }
Example #11
Source File: HeaderTest.java From ontopia with Apache License 2.0 | 5 votes |
@Test public void testHeaders() { OntopiaTestResource request = new OntopiaTestResource(Method.GET, getUrl(null), defaultMediatype); request.request(); Series<Header> headers = request.getResponse().getHeaders(); Assert.assertNotNull(headers); Assert.assertEquals("v1", headers.getFirstValue("X-Ontopia-API-Version")); Assert.assertEquals("n.o.t.r.OntopiaRestApplication", headers.getFirstValue("X-Ontopia-Application")); Assert.assertEquals("n.o.t.r.v1.topic.TopicsResource", headers.getFirstValue("X-Ontopia-Resource")); Assert.assertEquals("topics.ltm", headers.getFirstValue("X-Ontopia-Topicmap")); }
Example #12
Source File: ServerResource.java From open-rmbt with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected void addAllowOrigin() { Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers"); if (responseHeaders == null) { responseHeaders = new Series<>(Header.class); getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders); } responseHeaders.add("Access-Control-Allow-Origin", "*"); responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS"); responseHeaders.add("Access-Control-Allow-Headers", "Content-Type"); responseHeaders.add("Access-Control-Allow-Credentials", "false"); responseHeaders.add("Access-Control-Max-Age", "60"); }
Example #13
Source File: ServerResource.java From open-rmbt with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public String getIP() { final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers"); final String realIp = headers.getFirstValue("X-Real-IP", true); if (realIp != null) return realIp; else return getRequest().getClientInfo().getAddress(); }
Example #14
Source File: ServerResource.java From open-rmbt with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public Reference getURL() { final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers"); final String realURL = headers.getFirstValue("X-Real-URL", true); if (realURL != null) return new Reference(realURL); else return getRequest().getOriginalRef(); }
Example #15
Source File: Disposition.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Returns the list of disposition parameters. * * @return The list of disposition parameters. */ public Series<Parameter> getParameters() { if (this.parameters == null) { this.parameters = new Series<Parameter>(Parameter.class); } return this.parameters; }
Example #16
Source File: ServerResource.java From open-rmbt with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected void addAllowOrigin() { Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers"); if (responseHeaders == null) { responseHeaders = new Series<>(Header.class); getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders); } responseHeaders.add("Access-Control-Allow-Origin", "*"); responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS"); responseHeaders.add("Access-Control-Allow-Headers", "Content-Type"); responseHeaders.add("Access-Control-Allow-Credentials", "false"); responseHeaders.add("Access-Control-Max-Age", "60"); }
Example #17
Source File: MediaType.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Returns the unmodifiable list of parameters corresponding to subtype * modifiers. Creates a new instance if no one has been set. * * @return The list of parameters. */ @SuppressWarnings("unchecked") public Series<Parameter> getParameters() { // Lazy initialization with double-check. Series<Parameter> p = this.parameters; if (p == null) { synchronized (this) { p = this.parameters; if (p == null) { Series<Parameter> params = null; if (getName() != null) { int index = getName().indexOf(';'); if (index != -1) { params = new Form(getName().substring(index + 1) .trim(), ';'); } } if (params == null) { params = new Series<Parameter>(Parameter.class); } this.parameters = p = (Series<Parameter>) Series .unmodifiableSeries(params); } } } return p; }
Example #18
Source File: MediaType.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Constructor. * * @param name * The name. * @param parameters * The list of parameters. * @param description * The description. */ @SuppressWarnings("unchecked") public MediaType(String name, Series<Parameter> parameters, String description) { super(normalizeType(name, parameters), description); if (parameters != null) { this.parameters = (Series<Parameter>) Series .unmodifiableSeries(parameters); } }
Example #19
Source File: ServerResource.java From open-rmbt with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public String getIP() { final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers"); final String realIp = headers.getFirstValue("X-Real-IP", true); if (realIp != null) return realIp; else return getRequest().getClientInfo().getAddress(); }
Example #20
Source File: MediaType.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Normalizes the specified media type. * * @param name * The name of the type to normalize. * @param parameters * The parameters of the type to normalize. * @return The normalized type. */ private static String normalizeType(String name, Series<Parameter> parameters) { int slashIndex; int colonIndex; String mainType; String subType; StringBuilder params = null; // Ignore null names (backward compatibility). if (name == null) return null; // Check presence of parameters if ((colonIndex = name.indexOf(';')) != -1) { params = new StringBuilder(name.substring(colonIndex)); name = name.substring(0, colonIndex); } // No main / sub separator, assumes name/*. if ((slashIndex = name.indexOf('/')) == -1) { mainType = normalizeToken(name); subType = "*"; } else { // Normalizes the main and sub types. mainType = normalizeToken(name.substring(0, slashIndex)); subType = normalizeToken(name.substring(slashIndex + 1)); } // Merge parameters taken from the name and the method argument. if (parameters != null && !parameters.isEmpty()) { throw new RuntimeException("parameters != null."); } return (params == null) ? mainType + '/' + subType : mainType + '/' + subType + params.toString(); }
Example #21
Source File: ServerResource.java From open-rmbt with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public Reference getURL() { final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers"); final String realURL = headers.getFirstValue("X-Real-URL", true); if (realURL != null) return new Reference(realURL); else return getRequest().getOriginalRef(); }
Example #22
Source File: RestService.java From open-rmbt with Apache License 2.0 | 5 votes |
@Override public void start() throws UnknownHostException { if (isEnabled) { final boolean isRunning = this.isRunning.getAndSet(true); if (!isRunning) { if (isEnabled && port <= 0) { this.isEnabled = false; TestServerConsole.log("Could not start RestService. Parameter missing: 'server.service.rest.port'", 1, TestServerServiceEnum.TEST_SERVER); } Component component = new Component(); Server s = component.getServers().add(isSsl ? Protocol.HTTPS : Protocol.HTTP, InetAddress.getLocalHost().getHostAddress(), port); if (isSsl) { Series<Parameter> parameters = s.getContext().getParameters(); parameters.add("keystorePath", QOS_KEY_FILE_ABSOLUTE); parameters.add("keystorePassword", TestServer.QOS_KEY_PASSWORD); parameters.add("keyPassword", TestServer.QOS_KEY_PASSWORD); parameters.add("keystoreType", TestServer.QOS_KEY_TYPE); } component.getDefaultHost().attach("", new RestletApplication()); try { component.start(); TestServerConsole.log("[" + getName() + "] started: " + toString(), 1, TestServerServiceEnum.TEST_SERVER); } catch (Exception e) { TestServerConsole.error(getName(), e, 0, TestServerServiceEnum.TEST_SERVER); } } } }
Example #23
Source File: LocalOAuth2Main.java From DeviceConnect-Android with MIT License | 5 votes |
/** * AuthPageServerResourceを実行する. * * @param sessionId セッションID * @param scopes スコープ * @param applicationName アプリケーション名 * @return 戻り値(RedirectRepresentation) */ private RedirectRepresentation callAuthPageServerResource(final String sessionId, final ArrayList<Scope> scopes, final String applicationName) { Series<Cookie> cookies = new Series<>(Cookie.class); cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId); // scopesを文字列配列に変換する ArrayList<String> strScopes = ScopeUtil.scopesToStrings(scopes); ArrayList<String> actions = new ArrayList<>(); actions.add(AuthPageServerResource.ACTION_ACCEPT); ArrayList<String> applicationNames = new ArrayList<>(); applicationNames.add(applicationName); AuthPageServerResource.getQuery().put(AuthPageServerResource.SCOPE, strScopes); AuthPageServerResource.getQuery().put(AuthPageServerResource.GRANTED_SCOPE, new ArrayList<String>()); AuthPageServerResource.getQuery().put(AuthPageServerResource.ACTION, actions); AuthPageServerResource.getQuery().put(AuthPageServerResource.APPLICATION_NAME, applicationNames); Request request = new Request(); request.setCookies(cookies); Response response = new Response(request); AuthPageServerResource.init(request, response); RedirectRepresentation redirectRepresentation = null; try { Representation representation = AuthPageServerResource.showPage(); if (representation != null) { if (representation instanceof RedirectRepresentation) { redirectRepresentation = (RedirectRepresentation) representation; } } } catch (OAuthException e) { e.printStackTrace(); } return redirectRepresentation; }
Example #24
Source File: ServerResource.java From open-rmbt with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected void addAllowOrigin() { Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers"); if (responseHeaders == null) { responseHeaders = new Series<Header>(Header.class); getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders); } responseHeaders.add("Access-Control-Allow-Origin", "*"); responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS"); responseHeaders.add("Access-Control-Allow-Headers", "Content-Type"); responseHeaders.add("Access-Control-Allow-Credentials", "false"); responseHeaders.add("Access-Control-Max-Age", "60"); }
Example #25
Source File: LocalOAuth2Main.java From DeviceConnect-Android with MIT License | 4 votes |
/** * LoginPageServerResourceを実行する. * * @param userId ユーザーID * @param password パスワード * @return 戻り値(ResultRepresentation) */ private ResultRepresentation callLoginPageServerResource(final String userId, final String password) { // 前の処理からセッションIDを引き継ぐ String sessionId = AuthorizationServerResource.getSessionId(); Series<Cookie> cookies = new Series<>(Cookie.class); cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId); // (B)の処理 LoginPageServerResource.initResult(); Request request = new Request(); Reference requestReference = new Reference(DUMMY_ORIGINAL_REF); requestReference.addQueryParameter(LoginPageServerResource.USER_ID, userId); requestReference.addQueryParameter(LoginPageServerResource.PASSWORD, password); requestReference.addQueryParameter(LoginPageServerResource.CONTINUE, RedirectRepresentation.RedirectProc.requestAuthorization.toString()); // QueryParameterとは別の変数に値を入れているので、直接値を設定する ArrayList<String> userIds = new ArrayList<>(); userIds.add(userId); ArrayList<String> passwords = new ArrayList<>(); passwords.add(password); ArrayList<String> continues = new ArrayList<>(); continues.add(RedirectRepresentation.RedirectProc.requestAuthorization.toString()); LoginPageServerResource.getQuery().put(LoginPageServerResource.USER_ID, userIds); LoginPageServerResource.getQuery().put(LoginPageServerResource.PASSWORD, passwords); LoginPageServerResource.getQuery().put(LoginPageServerResource.CONTINUE, continues); request.setCookies(cookies); request.setOriginalRef(requestReference); request.setResourceRef(requestReference); Response response = new Response(request); LoginPageServerResource.init(request, response); ResultRepresentation resultRepresentation; try { resultRepresentation = (ResultRepresentation) LoginPageServerResource.getPage(this); } catch (OAuthException e) { resultRepresentation = new ResultRepresentation(); resultRepresentation.setResult(false); resultRepresentation.setError(e.getMessage(), e.getErrorDescription()); } return resultRepresentation; }
Example #26
Source File: ContextUtils.java From ontopia with Apache License 2.0 | 4 votes |
public static Series<Parameter> getParameters(Context context) { if (context == null) { return null; } return context.getParameters(); }
Example #27
Source File: FormReader.java From DeviceConnect-Android with MIT License | 4 votes |
/** * Reads the parameters whose name is a key in the given map. If a matching * parameter is found, its value is put in the map. If multiple values are * found, a list is created and set in the map. * * @param parameters * The parameters map controlling the reading. * @throws IOException * If the parameters could not be read. */ @SuppressWarnings("unchecked") public void readParameters(Map<String, Object> parameters) throws IOException { if (this.stream != null) { Parameter param = readNextParameter(); Object currentValue = null; while (param != null) { if (parameters.containsKey(param.getName())) { currentValue = parameters.get(param.getName()); if (currentValue != null) { List<Object> values = null; if (currentValue instanceof List) { // Multiple values already found for this parameter values = (List<Object>) currentValue; } else { // Second value found for this parameter // Create a list of values values = new ArrayList<Object>(); values.add(currentValue); parameters.put(param.getName(), values); } if (param.getValue() == null) { values.add(Series.EMPTY_VALUE); } else { values.add(param.getValue()); } } else { if (param.getValue() == null) { parameters.put(param.getName(), Series.EMPTY_VALUE); } else { parameters.put(param.getName(), param.getValue()); } } } param = readNextParameter(); } this.stream.close(); } }
Example #28
Source File: FormReader.java From DeviceConnect-Android with MIT License | 4 votes |
/** * Reads the parameters with the given name. If multiple values are found, a * list is returned created. * * @param name * The parameter name to match. * @return The parameter value or list of values. * @throws IOException * If the parameters could not be read. */ @SuppressWarnings("unchecked") public Object readParameter(String name) throws IOException { Object result = null; if (this.stream != null) { Parameter param = readNextParameter(); while (param != null) { if (param.getName().equals(name)) { if (result != null) { List<Object> values = null; if (result instanceof List) { // Multiple values already found for this parameter values = (List<Object>) result; } else { // Second value found for this parameter // Create a list of values values = new ArrayList<Object>(); values.add(result); result = values; } if (param.getValue() == null) { values.add(Series.EMPTY_VALUE); } else { values.add(param.getValue()); } } else { if (param.getValue() == null) { result = Series.EMPTY_VALUE; } else { result = param.getValue(); } } } param = readNextParameter(); } this.stream.close(); } return result; }
Example #29
Source File: LocalOAuth2Main.java From DeviceConnect-Android with MIT License | 4 votes |
/** * AuthorizationServerResourceを実行. * * @param client クライアント情報 * @param initialize 初期化フラグ(trueにするとContextを初期化する) * @param sessionId セッションID(引き継ぐセッションIDが存在すれば指定する、無ければnullを設定する) * @return not null: RedirectRepresentation型の戻り値を返す / null: エラー * @throws AuthorizationException Authorization例外. */ private RedirectRepresentation callAuthorizationServerResource(final Client client, final boolean initialize, final String sessionId) throws AuthorizationException { // AuthorizationServerResourceを初期化する if (initialize) { Context context = new Context(sLogger); AuthorizationServerResource.init(context); } // request, responseを初期化 * Request request = new Request(); request.setOriginalRef(new Reference(DUMMY_ORIGINAL_REF)); Response response = new Response(request); request.setResourceRef(new Reference(DUMMY_REFERENCE)); // セッションIDが指定されていたらRequestに設定する if (sessionId != null) { Series<Cookie> cookies = new Series<>(Cookie.class); cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId); request.setCookies(cookies); } AuthorizationServerResource.init(request, response, mClientManager, mTokenManager); // Formに設定する Form paramsA = new Form(); paramsA.add(AuthorizationServerResource.CLIENT_ID, client.getClientId()); paramsA.add(AuthorizationServerResource.REDIR_URI, DUMMY_REDIRECT_URI); paramsA.add(AuthorizationServerResource.RESPONSE_TYPE, "code"); paramsA.add(AuthorizationServerResource.SCOPE, DUMMY_SCOPE1); // requestAuthorizationを実行する Representation representationA; try { representationA = AuthorizationServerResource.requestAuthorization(paramsA); } catch (OAuthException e) { throw new AuthorizationException(e); } // 正常終了(ログイン画面リダイレクト) if (representationA instanceof RedirectRepresentation) { return (RedirectRepresentation) representationA; } return null; }
Example #30
Source File: Context.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Returns the modifiable series of parameters. A parameter is a pair * composed of a name and a value and is typically used for configuration * purpose, like Java properties. Note that multiple parameters with the * same name can be declared and accessed. * * @return The modifiable series of parameters. */ public Series<Parameter> getParameters() { return this.parameters; }