org.restlet.data.Parameter Java Examples
The following examples show how to use
org.restlet.data.Parameter.
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: FormReader.java From DeviceConnect-Android with MIT License | 6 votes |
/** * Reads all the parameters. * * @return The form read. * @throws IOException * If the parameters could not be read. */ public Form read() throws IOException { Form result = new Form(); if (this.stream != null) { Parameter param = readNextParameter(); while (param != null) { result.add(param); param = readNextParameter(); } this.stream.close(); } return result; }
Example #2
Source File: FormReader.java From DeviceConnect-Android with MIT License | 6 votes |
/** * Reads the first parameter with the given name. * * @param name * The parameter name to match. * @return The parameter value. * @throws IOException */ public Parameter readFirstParameter(String name) throws IOException { Parameter result = null; if (this.stream != null) { Parameter param = readNextParameter(); while ((param != null) && (result == null)) { if (param.getName().equals(name)) { result = param; } param = readNextParameter(); } this.stream.close(); } return result; }
Example #3
Source File: JacksonRepresentationImpl.java From ontopia with Apache License 2.0 | 6 votes |
@Override protected ObjectWriter createObjectWriter() { ObjectWriter writer = super.createObjectWriter(); for (SerializationFeature feature : SerializationFeature.values()) { boolean hasDefault = DEFAULT_SERIALIZATION_FEATURES.contains(feature); Parameter parameter = ContextUtils.getParameter(ContextUtils.getCurrentApplicationContext(), SERIALIZATION_FEATURE + feature.name()); if ((parameter != null) || hasDefault) { if (ContextUtils.getParameterAsBoolean(parameter, feature.enabledByDefault() || hasDefault)) { writer = writer.with(feature); } else { writer = writer.without(feature); } } } return writer; }
Example #4
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 #5
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 #6
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 #7
Source File: JobQueuesResource.java From helix with Apache License 2.0 | 5 votes |
/** * Add a new job queue * <p> * Usage: * <code>curl -d @'{jobQueueConfig.yaml}' * -H 'Content-Type: application/json' http://{host:port}/clusters/{clusterName}/jobQueues * <p> * For jobQueueConfig.yaml, see {@link Workflow#parse(String)} */ @Override public Representation post(Representation entity) { try { String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME); ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT); Form form = new Form(entity); // Get the job queue and submit it if (form.size() < 1) { throw new HelixException("Yaml job queue config is required!"); } Parameter payload = form.get(0); String yamlPayload = payload.getName(); if (yamlPayload == null) { throw new HelixException("Yaml job queue config is required!"); } Workflow workflow = Workflow.parse(yamlPayload); JobQueue.Builder jobQueueCfgBuilder = new JobQueue.Builder(workflow.getName()); jobQueueCfgBuilder.fromMap(workflow.getWorkflowConfig().getResourceConfigMap()); TaskDriver driver = new TaskDriver(zkClient, clusterName); driver.createQueue(jobQueueCfgBuilder.build()); getResponse().setEntity(getHostedEntitiesRepresentation(clusterName)); getResponse().setStatus(Status.SUCCESS_OK); } catch (Exception e) { getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); LOG.error("Exception in posting job queue: " + entity, e); } return null; }
Example #8
Source File: JacksonRepresentationImpl.java From ontopia with Apache License 2.0 | 5 votes |
@Override protected ObjectMapper createObjectMapper() { ObjectMapper mapper = super.createObjectMapper(); mapper.addMixInAnnotations(LocatorIF.class, MLocator.class); mapper.addMixInAnnotations(TopicIF.class, MTopic.class); mapper.addMixInAnnotations(TopicNameIF.class, MTopicName.class); mapper.addMixInAnnotations(VariantNameIF.class, MVariantName.class); mapper.addMixInAnnotations(OccurrenceIF.class, MOccurrence.class); mapper.addMixInAnnotations(AssociationIF.class, MAssociation.class); mapper.addMixInAnnotations(AssociationRoleIF.class, MAssociationRole.class); mapper.addMixInAnnotations(TopicMapIF.class, MTopicMapAsValue.class); mapper.addMixInAnnotations(TopicMapReferenceIF.class, MTopicMapReference.class); mapper.addMixInAnnotations(TopicMapSourceIF.class, MTopicMapSource.class); @SuppressWarnings("unchecked") Map<Class<?>, Class<?>> additional = (Map<Class<?>, Class<?>>) Response.getCurrent().getAttributes().get(ADDITIONAL_MIXINS_ATTRIBUTE); if ((additional != null) && (!additional.isEmpty())) { for (Map.Entry<Class<?>, Class<?>> entry : additional.entrySet()) { mapper.addMixInAnnotations(entry.getKey(), entry.getValue()); } } for (JsonParser.Feature feature : JsonParser.Feature.values()) { Parameter parameter = ContextUtils.getParameter(ContextUtils.getCurrentApplicationContext(), JSONPARSER_FEATURE + feature.name()); if (parameter != null) { mapper.configure(feature, ContextUtils.getParameterAsBoolean(parameter, feature.enabledByDefault() || DEFAULT_PARSER_FEATURES.contains(feature))); } } return mapper; }
Example #9
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 #10
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 #11
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 #12
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 #13
Source File: FormUtils.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Indicates if the searched parameter is specified in the given media * range. * * @param searchedParam * The searched parameter. * @param mediaRange * The media range to inspect. * @return True if the searched parameter is specified in the given media * range. */ public static boolean isParameterFound(Parameter searchedParam, MediaType mediaRange) { boolean result = false; for (Iterator<Parameter> iter = mediaRange.getParameters().iterator(); !result && iter.hasNext();) { result = searchedParam.equals(iter.next()); } return result; }
Example #14
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 #15
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 #16
Source File: ContextUtils.java From ontopia with Apache License 2.0 | 4 votes |
public static boolean getParameterAsBoolean(Context context, String name, boolean fallback) { Parameter parameter = getParameter(context, name); return getParameterAsBoolean(parameter, fallback); }
Example #17
Source File: ContextUtils.java From ontopia with Apache License 2.0 | 4 votes |
public static boolean getParameterAsBoolean(Parameter parameter, boolean fallback) { if (parameter == null) { return fallback; } return Boolean.parseBoolean(parameter.getValue()); }
Example #18
Source File: ContextUtils.java From ontopia with Apache License 2.0 | 4 votes |
public static int getParameterAsInteger(Context context, String name, int fallback) { Parameter parameter = getParameter(context, name); return getParameterAsInteger(parameter, fallback); }
Example #19
Source File: ContextUtils.java From ontopia with Apache License 2.0 | 4 votes |
public static int getParameterAsInteger(Parameter parameter, int fallback) { if (parameter == null) { return fallback; } return Integer.parseInt(parameter.getValue()); }
Example #20
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 #21
Source File: FormReader.java From DeviceConnect-Android with MIT License | 4 votes |
/** * Reads the next parameter available or null. * * @return The next parameter available or null. * @throws IOException * If the next parameter could not be read. */ public Parameter readNextParameter() throws IOException { Parameter result = null; if (this.stream != null) { try { boolean readingName = true; boolean readingValue = false; StringBuilder nameBuffer = new StringBuilder(); StringBuilder valueBuffer = new StringBuilder(); int nextChar = 0; while ((result == null) && (nextChar != -1)) { nextChar = this.stream.read(); if (readingName) { if (nextChar == '=') { if (nameBuffer.length() > 0) { readingName = false; readingValue = true; } else { throw new IOException( "Empty parameter name detected. Please check your form data"); } } else if ((nextChar == this.separator) || (nextChar == -1)) { if (nameBuffer.length() > 0) { result = FormUtils.create(nameBuffer, null, this.decode, this.characterSet); } else if (nextChar == -1) { // Do nothing return null preference } else { Context.getCurrentLogger() .fine("Empty parameter name detected. Please check your form data"); } } else { nameBuffer.append((char) nextChar); } } else if (readingValue) { if ((nextChar == this.separator) || (nextChar == -1)) { result = FormUtils.create(nameBuffer, valueBuffer, this.decode, this.characterSet); } else { valueBuffer.append((char) nextChar); } } } } catch (UnsupportedEncodingException uee) { throw new IOException( "Unsupported encoding. Please contact the administrator"); } } return result; }
Example #22
Source File: WorkflowsResource.java From helix with Apache License 2.0 | 4 votes |
@Override public Representation post(Representation entity) { try { String clusterName = (String) getRequest().getAttributes().get("clusterName"); Form form = new Form(entity); // Get the workflow and submit it if (form.size() < 1) { throw new HelixException("yaml workflow is required!"); } Parameter payload = form.get(0); String yamlPayload = payload.getName(); if (yamlPayload == null) { throw new HelixException("yaml workflow is required!"); } String zkAddr = (String) getContext().getAttributes().get(RestAdminApplication.ZKSERVERADDRESS); HelixManager manager = HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR, zkAddr); manager.connect(); try { Workflow workflow = Workflow.parse(yamlPayload); TaskDriver driver = new TaskDriver(manager); driver.start(workflow); } finally { manager.disconnect(); } getResponse().setEntity(getHostedEntitiesRepresentation(clusterName)); getResponse().setStatus(Status.SUCCESS_OK); } catch (Exception e) { getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); LOG.error("Error in posting " + entity, e); } return null; }
Example #23
Source File: FormUtils.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Reads the first parameter with the given name. * * @param post * The web form representation. * @param name * The parameter name to match. * @return The parameter. * @throws IOException */ public static Parameter getFirstParameter(Representation post, String name) throws IOException { if (!post.isAvailable()) { throw new IllegalStateException( "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required"); } return new FormReader(post).readFirstParameter(name); }
Example #24
Source File: RequestParametersFormTest.java From geowave with Apache License 2.0 | 3 votes |
private Parameter mockedFormParameter(final String value) { final Parameter param = Mockito.mock(Parameter.class); Mockito.when(param.getValue()).thenReturn(value); return param; }
Example #25
Source File: FormUtils.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Reads the first parameter with the given name. * * @param query * The query string. * @param name * The parameter name to match. * @param characterSet * The supported character encoding. * @param separator * The separator character to append between parameters. * @param decode * Indicates if the parameters should be decoded using the given * character set. * @return The parameter. * @throws IOException */ public static Parameter getFirstParameter(String query, String name, CharacterSet characterSet, char separator, boolean decode) throws IOException { return new FormReader(query, characterSet, separator, decode) .readFirstParameter(name); }
Example #26
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; }