private static <T> Map<String, T> parseAndValidateMappings(final String property, final Object mappings, final TypeParser<T> parser) { if (mappings == null) { return Collections.emptyMap(); } if (mappings instanceof Map) { return (Map<String, T>) mappings; } final HashMap<String, T> mappingsMap = new HashMap<>(); if (mappings instanceof String) { parseMappings(property, (String) mappings, mappingsMap, parser); } else if (mappings instanceof String[]) { final String[] mappingsArray = (String[]) mappings; for (final String aMappingsArray : mappingsArray) { parseMappings(property, aMappingsArray, mappingsMap, parser); } } else { throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_TYPE(property)); } encodeKeys(mappingsMap); return mappingsMap; }
/** * Create a filter that reads the configuration (media type and language mappings) * from the provided {@link ResourceConfig} instance. * This constructor will be called by the Jersey runtime when the filter * class is returned from {@link javax.ws.rs.core.Application#getClasses()}. * The {@link ResourceConfig} instance will get auto-injected. * * @param rc ResourceConfig instance that holds the configuration for the filter. */ public UriConnegFilter(@Context final Configuration rc) { this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)), extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS))); }
private static Map<String, MediaType> extractMediaTypeMappings(final Object mappings) { // parse and validate mediaTypeMappings set through MEDIA_TYPE_MAPPINGS property return parseAndValidateMappings(ServerProperties.MEDIA_TYPE_MAPPINGS, mappings, new TypeParser<MediaType>() { public MediaType valueOf(final String value) { return MediaType.valueOf(value); } }); }
@Override public void run(ApplicationConfiguration configuration, Environment environment) throws Exception { environment.jersey().register(new UriConnegFilter(new MediaTypeMappings(), Collections.<String, String>emptyMap())); Map<String, Object> props = new HashMap<>(); props.put(MessageProperties.LEGACY_WORKERS_ORDERING, true); environment.jersey().getResourceConfig().addProperties(props); addWriters(environment.jersey()); configureCors(environment); //TODO: This path should not be hard coded. configureSwagger(environment, "scigraph"); environment.servlets(). addFilter("Swagger Filter", factory.getInjector().getInstance(SwaggerFilter.class)) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/swagger.json", "/swagger"); environment.servlets().addFilter("swaggerDocResolver", new SwaggerDocUrlFilter()) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); DynamicCypherResourceFactory cypherFactory = factory.getInjector().getInstance(DynamicCypherResourceFactory.class); for (Map.Entry<String,Path> config: configuration.getCypherResources().entrySet()) { environment.jersey().getResourceConfig().registerResources(cypherFactory.create(config.getKey(), config.getValue()).getBuilder().build()); } }
/** * Create a filter that reads the configuration (media type and language mappings) * from the provided {@link ResourceConfig} instance. * This constructor will be called by the Jersey runtime when the filter * class is returned from {@link javax.ws.rs.core.Application#getClasses()}. * The {@link ResourceConfig} instance will get auto-injected. * * @param rc ResourceConfig instance that holds the configuration for the filter. */ public UriConnegFilter(@Context final Configuration rc) { this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)), extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS))); }
private static <T> Map<String, T> parseAndValidateMappings(final String property, final Object mappings, final TypeParser<T> parser) { if (mappings == null) { return Collections.emptyMap(); } if (mappings instanceof Map) { return (Map<String, T>) mappings; } final HashMap<String, T> mappingsMap = new HashMap<>(); if (mappings instanceof String) { parseMappings(property, (String) mappings, mappingsMap, parser); } else if (mappings instanceof String[]) { final String[] mappingsArray = (String[]) mappings; for (final String aMappingsArray : mappingsArray) { parseMappings(property, aMappingsArray, mappingsMap, parser); } } else { throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_TYPE(property)); } encodeKeys(mappingsMap); return mappingsMap; }
private static Map<String, String> extractLanguageMappings(final Object mappings) { // parse and validate languageMappings set through LANGUAGE_MAPPINGS property return parseAndValidateMappings(ServerProperties.LANGUAGE_MAPPINGS, mappings, new TypeParser<String>() { public String valueOf(final String value) { return LanguageTag.valueOf(value).toString(); } }); }
/** * Create a filter that reads the configuration (media type and language mappings) * from the provided {@link ResourceConfig} instance. * This constructor will be called by the Jersey runtime when the filter * class is returned from {@link javax.ws.rs.core.Application#getClasses()}. * The {@link ResourceConfig} instance will get auto-injected. * * @param rc ResourceConfig instance that holds the configuration for the filter. */ public UriConnegFilter(@Context final Configuration rc) { this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)), extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS))); }
private static <T> Map<String, T> parseAndValidateMappings(final String property, final Object mappings, final TypeParser<T> parser) { if (mappings == null) { return Collections.emptyMap(); } if (mappings instanceof Map) { return (Map<String, T>) mappings; } final HashMap<String, T> mappingsMap = new HashMap<>(); if (mappings instanceof String) { parseMappings(property, (String) mappings, mappingsMap, parser); } else if (mappings instanceof String[]) { final String[] mappingsArray = (String[]) mappings; for (final String aMappingsArray : mappingsArray) { parseMappings(property, aMappingsArray, mappingsMap, parser); } } else { throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_TYPE(property)); } encodeKeys(mappingsMap); return mappingsMap; }
private static Map<String, MediaType> extractMediaTypeMappings(final Object mappings) { // parse and validate mediaTypeMappings set through MEDIA_TYPE_MAPPINGS property return parseAndValidateMappings(ServerProperties.MEDIA_TYPE_MAPPINGS, mappings, new TypeParser<MediaType>() { public MediaType valueOf(final String value) { return MediaType.valueOf(value); } }); }
/** * Create a filter that reads the configuration (media type and language mappings) * from the provided {@link ResourceConfig} instance. * This constructor will be called by the Jersey runtime when the filter * class is returned from {@link javax.ws.rs.core.Application#getClasses()}. * The {@link ResourceConfig} instance will get auto-injected. * * @param rc ResourceConfig instance that holds the configuration for the filter. */ public UriConnegFilter(@Context final Configuration rc) { this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)), extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS))); }
private static <T> Map<String, T> parseAndValidateMappings(final String property, final Object mappings, final TypeParser<T> parser) { if (mappings == null) { return Collections.emptyMap(); } if (mappings instanceof Map) { return (Map<String, T>) mappings; } final HashMap<String, T> mappingsMap = new HashMap<>(); if (mappings instanceof String) { parseMappings(property, (String) mappings, mappingsMap, parser); } else if (mappings instanceof String[]) { final String[] mappingsArray = (String[]) mappings; for (final String aMappingsArray : mappingsArray) { parseMappings(property, aMappingsArray, mappingsMap, parser); } } else { throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_TYPE(property)); } encodeKeys(mappingsMap); return mappingsMap; }
private static Map<String, String> extractLanguageMappings(final Object mappings) { // parse and validate languageMappings set through LANGUAGE_MAPPINGS property return parseAndValidateMappings(ServerProperties.LANGUAGE_MAPPINGS, mappings, new TypeParser<String>() { public String valueOf(final String value) { return LanguageTag.valueOf(value).toString(); } }); }
/** * Create a filter that reads the configuration (media type and language mappings) * from the provided {@link ResourceConfig} instance. * This constructor will be called by the Jersey runtime when the filter * class is returned from {@link javax.ws.rs.core.Application#getClasses()}. * The {@link ResourceConfig} instance will get auto-injected. * * @param rc ResourceConfig instance that holds the configuration for the filter. */ public UriConnegFilter(@Context final Configuration rc) { this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)), extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS))); }
private static <T> Map<String, T> parseAndValidateMappings(final String property, final Object mappings, final TypeParser<T> parser) { if (mappings == null) { return Collections.emptyMap(); } if (mappings instanceof Map) { return (Map<String, T>) mappings; } final HashMap<String, T> mappingsMap = Maps.newHashMap(); if (mappings instanceof String) { parseMappings(property, (String) mappings, mappingsMap, parser); } else if (mappings instanceof String[]) { final String[] mappingsArray = (String[]) mappings; for (final String aMappingsArray : mappingsArray) { parseMappings(property, aMappingsArray, mappingsMap, parser); } } else { throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_TYPE(property)); } encodeKeys(mappingsMap); return mappingsMap; }
private static Map<String, String> extractLanguageMappings(final Object mappings) { // parse and validate languageMappings set through LANGUAGE_MAPPINGS property return parseAndValidateMappings(ServerProperties.LANGUAGE_MAPPINGS, mappings, new TypeParser<String>() { public String valueOf(final String value) { return LanguageTag.valueOf(value).toString(); } }); }
/** * Create a filter that reads the configuration (media type and language mappings) * from the provided {@link ResourceConfig} instance. * This constructor will be called by the Jersey runtime when the filter * class is returned from {@link javax.ws.rs.core.Application#getClasses()}. * The {@link ResourceConfig} instance will get auto-injected. * * @param rc ResourceConfig instance that holds the configuration for the filter. */ public UriConnegFilter(@Context final Configuration rc) { this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)), extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS))); }
private static <T> Map<String, T> parseAndValidateMappings(final String property, final Object mappings, final TypeParser<T> parser) { if (mappings == null) { return Collections.emptyMap(); } if (mappings instanceof Map) { return (Map<String, T>) mappings; } final HashMap<String, T> mappingsMap = Maps.newHashMap(); if (mappings instanceof String) { parseMappings(property, (String) mappings, mappingsMap, parser); } else if (mappings instanceof String[]) { final String[] mappingsArray = (String[]) mappings; for (final String aMappingsArray : mappingsArray) { parseMappings(property, aMappingsArray, mappingsMap, parser); } } else { throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_TYPE(property)); } encodeKeys(mappingsMap); return mappingsMap; }
private static Map<String, MediaType> extractMediaTypeMappings(final Object mappings) { // parse and validate mediaTypeMappings set through MEDIA_TYPE_MAPPINGS property return parseAndValidateMappings(ServerProperties.MEDIA_TYPE_MAPPINGS, mappings, new TypeParser<MediaType>() { public MediaType valueOf(final String value) { return MediaType.valueOf(value); } }); }
/** * Create a filter that reads the configuration (media type and language mappings) * from the provided {@link ResourceConfig} instance. * This constructor will be called by the Jersey runtime when the filter * class is returned from {@link javax.ws.rs.core.Application#getClasses()}. * The {@link ResourceConfig} instance will get auto-injected. * * @param rc ResourceConfig instance that holds the configuration for the filter. */ public UriConnegFilter(@Context final Configuration rc) { this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)), extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS))); }