org.restlet.representation.Variant Java Examples
The following examples show how to use
org.restlet.representation.Variant.
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: PolygeneConverter.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public Representation toRepresentation( Object source, Variant target, Resource resource ) { Representation result = null; if( source instanceof JsonRepresentation ) { result = (JsonRepresentation<?>) source; } else { if( target.getMediaType() == null ) { target.setMediaType( MediaType.APPLICATION_JSON ); } if( isCompatible( target ) ) { result = create( target.getMediaType(), source ); } } return result; }
Example #2
Source File: EntitiesResource.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override protected Representation post( Representation entity, Variant variant ) throws ResourceException { try { /* * InputStream in = entity.getStream(); ObjectInputStream oin = new ObjectInputStream( in ); String reference * = oin.readUTF(); Usecase usecase = (Usecase) oin.readUnshared(); MetaInfo unitofwork = (MetaInfo) * oin.readUnshared(); Iterable<UnitOfWorkEvent> events = (Iterable<UnitOfWorkEvent>) oin.readUnshared(); * * // Store state try { entityStore.apply( reference, events, usecase, unitofwork ).commit(); } catch( * ConcurrentEntityStateModificationException e ) { throw new ResourceException( * Status.CLIENT_ERROR_CONFLICT ); } */ } catch( Exception e ) { throw new ResourceException( e ); } return new EmptyRepresentation(); }
Example #3
Source File: AbstractOSGiResource.java From concierge with Eclipse Public License 1.0 | 6 votes |
protected AbstractOSGiResource(final PojoReflector<T> reflector, final MediaType mediaType) { this.reflector = reflector; this.xmlMediaType = new MediaType(mediaType.toString() + MT_XML); this.jsonMediaType = new MediaType(mediaType.toString() + MT_JSON); this.setNegotiated(true); getVariants().add(new Variant(jsonMediaType)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); getVariants().add(new Variant(xmlMediaType)); getVariants().add(new Variant(MediaType.APPLICATION_XML)); getVariants().add(new Variant(MediaType.TEXT_XML)); getVariants().add(new Variant(MediaType.TEXT_PLAIN)); }
Example #4
Source File: IndexResource.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public Representation get( Variant variant ) throws ResourceException { if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_XML ) ) { return new RdfXmlOutputRepresentation(); } else if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_TRIG ) ) { return new RdfTrigOutputRepresentation( MediaType.APPLICATION_RDF_TRIG ); } else if( variant.getMediaType().equals( MediaType.TEXT_PLAIN ) ) { return new RdfTrigOutputRepresentation( MediaType.TEXT_PLAIN ); } return null; }
Example #5
Source File: BundleHeaderResource.java From concierge with Eclipse Public License 1.0 | 6 votes |
@Override public Representation get(final Variant variant) { try { final List<Preference<Language>> acceptedLanguages = getClientInfo() .getAcceptedLanguages(); final String locale = acceptedLanguages == null || acceptedLanguages.isEmpty() ? null : acceptedLanguages .get(0).getMetadata().toString(); final org.osgi.framework.Bundle bundle = getBundleFromKeys(RestService.BUNDLE_ID_KEY); if (bundle == null) { return ERROR(Status.CLIENT_ERROR_NOT_FOUND); } return getRepresentation( mapFromDict(locale == null ? bundle.getHeaders() : bundle.getHeaders(locale)), variant); } catch (final Exception e) { return ERROR(e, variant); } }
Example #6
Source File: EntitiesResource.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override protected Representation get( Variant variant ) throws ResourceException { // Generate the right representation according to its media type. if( MediaType.APPLICATION_JSON.equals( variant.getMediaType() ) ) { return representJson(); } else if( MediaType.APPLICATION_RDF_XML.equals( variant.getMediaType() ) ) { return representRdf(); } else if( MediaType.TEXT_HTML.equals( variant.getMediaType() ) ) { return representHtml(); } else if( MediaType.APPLICATION_ATOM.equals( variant.getMediaType() ) ) { return representAtom(); } throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); }
Example #7
Source File: FrameworkStartLevelResource.java From concierge with Eclipse Public License 1.0 | 6 votes |
@Override public Representation put(final Representation r, final Variant variant) { try { final FrameworkStartLevelPojo sl = fromRepresentation(r, r.getMediaType()); final FrameworkStartLevel fsl = getFrameworkStartLevel(); if (sl.getStartLevel() != 0) { fsl.setStartLevel(sl.getStartLevel()); } if (sl.getInitialBundleStartLevel() != 0) { fsl.setInitialBundleStartLevel(sl.getInitialBundleStartLevel()); } return SUCCESS(Status.SUCCESS_NO_CONTENT); } catch (final Exception e) { return ERROR(e, variant); } }
Example #8
Source File: AbstractResponseWriter.java From attic-polygene-java with Apache License 2.0 | 6 votes |
protected Variant getVariant( Request request, List<Language> possibleLanguages, List<MediaType> possibleMediaTypes ) { Language language = request.getClientInfo().getPreferredLanguage( possibleLanguages ); if( language == null ) { language = possibleLanguages.get( 0 ); } MediaType responseType = request.getClientInfo().getPreferredMediaType( possibleMediaTypes ); if( responseType == null && request.getClientInfo() .getPreferredMediaType( Collections.singletonList( MediaType.ALL ) ) == MediaType.ALL ) { responseType = possibleMediaTypes.get( 0 ); } Variant variant = new Variant( responseType, language ); variant.setCharacterSet( CharacterSet.UTF_8 ); return variant; }
Example #9
Source File: BundleStartLevelResource.java From concierge with Eclipse Public License 1.0 | 6 votes |
@Override public Representation put(final Representation value, final Variant variant) { try { final Bundle bundle = getBundleFromKeys(RestService.BUNDLE_ID_KEY); if (bundle == null) { return ERROR(Status.CLIENT_ERROR_NOT_FOUND); } final BundleStartLevelPojo sl = fromRepresentation(value, value.getMediaType()); final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class); bsl.setStartLevel(sl.getStartLevel()); return getRepresentation(new BundleStartLevelPojo(bsl), variant); } catch (final Exception e) { return ERROR(e, variant); } }
Example #10
Source File: EntityResource.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override protected Representation delete( Variant variant ) throws ResourceException { Usecase usecase = UsecaseBuilder.newUsecase( "Remove entity" ); EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, usecase, SystemTime.now() ); try { EntityReference reference = EntityReference.create( identity ); uow.entityStateOf( module, reference ).remove(); uow.applyChanges().commit(); getResponse().setStatus( Status.SUCCESS_NO_CONTENT ); } catch( EntityNotFoundException e ) { uow.discard(); getResponse().setStatus( Status.CLIENT_ERROR_NOT_FOUND ); } return new EmptyRepresentation(); }
Example #11
Source File: ValidationRestletResource.java From uReplicator with Apache License 2.0 | 6 votes |
public ValidationRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _validationManager = (ValidationManager) getApplication().getContext() .getAttributes().get(ValidationManager.class.toString()); if (getApplication().getContext().getAttributes() .containsKey(SourceKafkaClusterValidationManager.class.toString())) { _srcKafkaValidationManager = (SourceKafkaClusterValidationManager) getApplication().getContext() .getAttributes().get(SourceKafkaClusterValidationManager.class.toString()); } else { _srcKafkaValidationManager = null; } }
Example #12
Source File: TopicManagementRestletResource.java From uReplicator with Apache License 2.0 | 6 votes |
public TopicManagementRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _managerControllerHelix = (ManagerControllerHelix) getApplication().getContext() .getAttributes().get(ManagerControllerHelix.class.toString()); _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; } }
Example #13
Source File: SPARQLResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
public SPARQLResource() { getVariants().addAll( Arrays.asList( new Variant( MediaType.TEXT_HTML ), new Variant( MediaType.APPLICATION_RDF_XML ), new Variant( RestApplication.APPLICATION_SPARQL_JSON ) ) ); setNegotiated( true ); }
Example #14
Source File: FrameworkStartLevelResource.java From concierge with Eclipse Public License 1.0 | 5 votes |
@Override public Representation get(final Variant variant) { try { return getRepresentation(new FrameworkStartLevelPojo( getFrameworkStartLevel()), variant); } catch (final Exception e) { return ERROR(e, variant); } }
Example #15
Source File: BundleRepresentationsResource.java From concierge with Eclipse Public License 1.0 | 5 votes |
@Override public Representation get(final Variant variant) { try { final Representation rep = getRepresentation( new BundleRepresentationsList(getBundles()), variant); return rep; } catch (final Exception e) { return ERROR(e, variant); } }
Example #16
Source File: EntitiesResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
public EntitiesResource() { super(); // Define the supported variants. getVariants().addAll( Arrays.asList( new Variant( MediaType.TEXT_HTML ), new Variant( MediaType.APPLICATION_RDF_XML ), new Variant( MediaType.APPLICATION_JSON ), new Variant( MediaType.APPLICATION_ATOM ) ) ); setNegotiated( true ); }
Example #17
Source File: BundleStartLevelResource.java From concierge with Eclipse Public License 1.0 | 5 votes |
@Override public Representation get(final Variant variant) { try { final Bundle bundle = getBundleFromKeys(RestService.BUNDLE_ID_KEY); if (bundle == null) { return ERROR(Status.CLIENT_ERROR_NOT_FOUND); } final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class); final BundleStartLevelPojo sl = new BundleStartLevelPojo(bsl); return getRepresentation(sl, variant); } catch (final Exception e) { return ERROR(e, variant); } }
Example #18
Source File: TopicManagementRestletResource.java From uReplicator with Apache License 2.0 | 5 votes |
public TopicManagementRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _conf = (ManagerConf) getApplication().getContext().getAttributes() .get(ManagerConf.class.toString()); _helixMirrorMakerManager = (ControllerHelixManager) getApplication().getContext() .getAttributes().get(ControllerHelixManager.class.toString()); KafkaClusterValidationManager kafkaValidationManager = (KafkaClusterValidationManager) getApplication() .getContext().getAttributes().get(KafkaClusterValidationManager.class.toString()); _clusterToObserverMap = kafkaValidationManager.getClusterToObserverMap(); }
Example #19
Source File: BundlesResource.java From concierge with Eclipse Public License 1.0 | 5 votes |
@Override public Representation get(final Variant variant) { try { final Representation rep = getRepresentation(new BundlePojoList( getBundles()), variant); return rep; } catch (final Exception e) { return ERROR(e, variant); } }
Example #20
Source File: IndexResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
public IndexResource() { getVariants().addAll( Arrays.asList( new Variant( MediaType.TEXT_PLAIN ), new Variant( MediaType.APPLICATION_RDF_TRIG ), new Variant( MediaType.APPLICATION_RDF_XML ) ) ); setNegotiated( true ); }
Example #21
Source File: TicketGrantingTicketResource.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Override public void init(final Context context, final Request request, final Response response) { super.init(context, request, response); this.ticketGrantingTicketId = (String) request.getAttributes().get("ticketGrantingTicketId"); this.setNegotiated(false); this.getVariants().add(new Variant(MediaType.APPLICATION_WWW_FORM)); }
Example #22
Source File: PolygeneConverter.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public List<Class<?>> getObjectClasses( Variant source ) { List<Class<?>> result = new ArrayList<>(); if( isCompatible( source ) ) { result = addObjectClass( result, Object.class ); result = addObjectClass( result, JsonRepresentation.class ); } return result; }
Example #23
Source File: PolygeneConverter.java From attic-polygene-java with Apache License 2.0 | 5 votes |
/** * Indicates if the given variant is compatible with the media types * supported by this converter. * * @param variant The variant. * * @return True if the given variant is compatible with the media types * supported by this converter. */ protected boolean isCompatible( Variant variant ) { //noinspection SimplifiableIfStatement if( variant == null ) { return false; } return VARIANT_JSON.isCompatible( variant ) || VARIANT_WWW_FORM_URLENCODED.isCompatible( variant ) ; }
Example #24
Source File: PolygeneConverter.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public float score( Object source, Variant target, Resource resource ) { float result; if( source instanceof JsonRepresentation<?> ) { result = 1.0F; } else { if( target == null ) { result = 0.5F; } else if( isCompatible( target ) ) { result = 0.8F; } else { result = 0.5F; } } return result; }
Example #25
Source File: PolygeneEntityRestlet.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private void get( Request request, Response response ) { execute( request, response, resource -> { try { T result = resource.get(); if( result != null ) { if( result instanceof EntityComposite ) { result = locator.find( identityType ).toValue( result ); } Representation representation = converter.toRepresentation( result, new Variant(), null ); response.setEntity( representation ); response.setStatus( Status.SUCCESS_OK ); } else { response.setStatus( Status.CLIENT_ERROR_NOT_FOUND ); } } catch( NoSuchEntityException e ) { response.setStatus( Status.CLIENT_ERROR_NOT_FOUND, e, "Entity not found." ); } } ); }
Example #26
Source File: AbstractPagedResource.java From ontopia with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public Representation toRepresentation(Object source, Variant target) throws IOException { boolean pageable = isPageable(source, target); if (pageable) { source = page((Collection) source); } return super.toRepresentation(source, target); }
Example #27
Source File: AbstractConverter.java From ontopia with Apache License 2.0 | 5 votes |
@Override public float score(Object source, Variant target, Resource resource) { for (VariantInfo v : variants) { if (v.isCompatible(target)) { if (source != null) { return 1F; } } } return -1.0F; }
Example #28
Source File: AbstractConverter.java From ontopia with Apache License 2.0 | 5 votes |
@Override public <T> float score(Representation source, Class<T> target, Resource resource) { for (Variant v : variants) { if (v.getMediaType().isCompatible(source.getMediaType())) { return .5F; } } return -1F; }
Example #29
Source File: AbstractConverter.java From ontopia with Apache License 2.0 | 5 votes |
@Override public Representation toRepresentation(final Object source, final Variant target, Resource resource) throws IOException { return new OutputRepresentation(target.getMediaType()) { @Override public void write(OutputStream outputStream) throws IOException { CharacterSet characterSet = target.getCharacterSet(); if (characterSet == null) { characterSet = CharacterSet.UTF_8; } writeFragment(outputStream, source, characterSet); } }; }
Example #30
Source File: FoxbpmConverService.java From FoxBPM with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public Representation toRepresentation(Object source, Variant target, UniformResource resource) { Representation representation = super.toRepresentation(source, target, resource); if(representation instanceof JacksonRepresentation){ ((JacksonRepresentation)representation).getObjectMapper().setDateFormat(df); } return representation; }