下面列出了javax.ws.rs.core.FeatureContext#property() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean configure(final FeatureContext context) {
final Configuration config = context.getConfiguration();
final String jsonFeature = getValue(config.getProperties(), config.getRuntimeType(),
JSON_FEATURE, ST_JSON_FEATURE, String.class);
// Do not register our JSON feature if another one is already registered
if (!ST_JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
LOGGER.warn("Skipping registration of: {} as JSON support is already provided by: {}",
ST_JSON_FEATURE, jsonFeature);
return false;
}
// Prevent other not yet registered JSON features to register themselves
context.property(getPropertyNameForRuntime(JSON_FEATURE, config.getRuntimeType()),
ST_JSON_FEATURE);
if (!config.isRegistered(JacksonSerializerMessageBodyReaderWriter.class)) {
context.register(SerializationExceptionMapper.class);
context.register(JacksonSerializerMessageBodyReaderWriter.class);
}
return true;
}
@Override
public boolean configure(FeatureContext context) {
final Configuration config = context.getConfiguration();
final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
InternalProperties.JSON_FEATURE, JSON_FEATURE_CLASSNAME, String.class);
// Other JSON providers registered.
if (!JSON_FEATURE_CLASSNAME.equalsIgnoreCase(jsonFeature)) {
LOGGER.error("Another JSON provider has been registered: {}", jsonFeature);
return false;
}
// Disable other JSON providers.
context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()),
JSON_FEATURE_CLASSNAME);
context.register(DACJacksonJaxbJsonProvider.class);
return true;
}
@Override
public boolean configure(FeatureContext context) {
final Configuration config = context.getConfiguration();
if (CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
CommonProperties.MOXY_JSON_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) {
return false;
}
final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);
// Other JSON providers registered.
if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
return false;
}
// Disable other JSON providers.
context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE,
config.getRuntimeType()), JSON_FEATURE);
final int workerPriority = Priorities.USER + 3000;
context.register(ParsecMoxyProvider.class, workerPriority);
return true;
}
private void applyInternalCommonConfig(FeatureContext context, InternalCommonConfig internalCommonConfig)
{
for ( Class<?> clazz : internalCommonConfig.getClasses() )
{
log.info(String.format("Registering %s as a component", clazz));
context.register(clazz);
}
for ( Object obj : internalCommonConfig.getInstances() )
{
log.info(String.format("Registering instance of %s as a component", obj.getClass()));
context.register(obj);
}
for ( Map.Entry<String, Object> entry : internalCommonConfig.getProperties().entrySet() )
{
String key = entry.getKey();
Object value = entry.getValue();
log.info(String.format("Registering property key: %s\tvalue: %s", key, value));
context.property(key, value);
}
}
@Override
public boolean configure(FeatureContext context) {
// this gives everyone access to the Agrest services
context.property(AgRuntime.AGREST_CONTAINER_PROPERTY, injector);
@SuppressWarnings("unchecked")
Map<String, Class> bodyWriters =
injector.getInstance(Key.getMapOf(String.class, Class.class, AgRuntime.BODY_WRITERS_MAP));
for (Class<?> type : bodyWriters.values()) {
context.register(type);
}
context.register(ResponseStatusDynamicFeature.class);
context.register(EntityUpdateReader.class);
context.register(EntityUpdateCollectionReader.class);
for (Feature f : extraFeatures) {
f.configure(context);
}
return true;
}
public boolean configure(final FeatureContext context) {
final Configuration config = context.getConfiguration();
final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE,
String.class);
// Other JSON providers registered.
if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
return false;
}
// Disable other JSON providers.
context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
// Register FastJson.
if (!config.isRegistered(FastJsonProvider.class)) {
context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
}
return true;
}
public boolean configure(final FeatureContext context) {
final String disableMoxy = CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.'
+ context.getConfiguration().getRuntimeType().name().toLowerCase();
context.property(disableMoxy, true);
context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
return true;
}
@Override
public boolean configure(final FeatureContext context) {
try {
final Configuration config = context.getConfiguration();
final String jsonFeature = CommonProperties.getValue(
config.getProperties()
, config.getRuntimeType()
, InternalProperties.JSON_FEATURE, JSON_FEATURE,
String.class
);
// Other JSON providers registered.
if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
return false;
}
// Disable other JSON providers.
context.property(
PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType())
, JSON_FEATURE);
// Register FastJson.
if (!config.isRegistered(FastJsonProvider.class)) {
context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
}
} catch (NoSuchMethodError e) {
// skip
}
return true;
}
/** {@inheritDoc} */
@Override
public boolean configure(final FeatureContext context) {
// disable Jersey default BeanValidation feature
context.property(ServerProperties.BV_FEATURE_DISABLE, "true");
context.register(new ValidationBinder())
.register(ValidationExceptionMapper.class)
.register(ValidationConfigurationContextResolver.class);
return true;
}
private void addAll(Map<String, Object> map, FeatureContext context) {
for(String key : map.keySet()){
context.property(key,map.get(key));
}
}