com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper Java Examples

The following examples show how to use com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper. 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: KsqlRestApplication.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
@Override
public void configureBaseApplication(Configurable<?> config, Map<String, String> metricTags) {
  // Would call this but it registers additional, unwanted exception mappers
  // super.configureBaseApplication(config, metricTags);
  // Instead, just copy+paste the desired parts from Application.configureBaseApplication() here:
  JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(getJsonMapper());
  config.register(jsonProvider);
  config.register(JsonParseExceptionMapper.class);

  // Don't want to buffer rows when streaming JSON in a request to the query resource
  config.property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0);
  if (isUiEnabled) {
    loadUiWar();
    config.property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/(static/.*|.*html)");
  }
}
 
Example #2
Source File: APIServer.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
protected void init(ScanResult result) {
  // FILTERS
  register(JSONPrettyPrintFilter.class);
  register(MediaTypeFilter.class);

  // RESOURCES
  for (Class<?> resource : result.getAnnotatedClasses(APIResource.class)) {
    register(resource);
  }

  // FEATURES
  register(DACAuthFilterFeature.class);
  register(DACJacksonJaxbJsonFeature.class);
  register(DACExceptionMapperFeature.class);

  // EXCEPTION MAPPERS
  register(JsonParseExceptionMapper.class);
  register(JsonMappingExceptionMapper.class);

  // PROPERTIES
  property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true");

  final String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(CommonProperties.MOXY_JSON_FEATURE_DISABLE,
    getConfiguration().getRuntimeType());
  property(disableMoxy, true);
}
 
Example #3
Source File: Jersey2BackstopperConfigHelperTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test
public void backstopperOnlyExceptionMapperFactory_removes_all_exception_mappers_except_Jersey2ApiExceptionHandler()
    throws NoSuchFieldException, IllegalAccessException {
    // given
    AbstractBinder lotsOfExceptionMappersBinder = new AbstractBinder() {
        @Override
        protected void configure() {
            bind(JsonMappingExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
            bind(JsonParseExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
            bind(generateJerseyApiExceptionHandler(projectApiErrors, utils)).to(ExceptionMapper.class);
        }
    };

    ServiceLocator locator = ServiceLocatorUtilities.bind(lotsOfExceptionMappersBinder);

    // when
    BackstopperOnlyExceptionMapperFactory overrideExceptionMapper = new BackstopperOnlyExceptionMapperFactory(locator);

    // then
    Set<Object> emTypesLeft = overrideExceptionMapper.getFieldObj(
        ExceptionMapperFactory.class, overrideExceptionMapper, "exceptionMapperTypes"
    );
    assertThat(emTypesLeft).hasSize(1);
    ServiceHandle serviceHandle = overrideExceptionMapper.getFieldObj(emTypesLeft.iterator().next(), "mapper");
    assertThat(serviceHandle.getService()).isInstanceOf(Jersey2ApiExceptionHandler.class);
}
 
Example #4
Source File: JaxRSClientJacksonFeature.java    From JaxRSProviders with Apache License 2.0 5 votes vote down vote up
@Override
public boolean configure(final FeatureContext context) {
	if (!context.getConfiguration().isRegistered(JacksonJaxbJsonProvider.class)) {
		context.register(JsonParseExceptionMapper.class);
		context.register(JsonMappingExceptionMapper.class);
		context.register(new JaxRSClientJacksonJaxbJsonProvider(reg, cl));
	}
	return true;
}
 
Example #5
Source File: CXFJaxRSServerContainer.java    From JaxRSProviders with Apache License 2.0 5 votes vote down vote up
@Override
protected void registerExtensions(Configurable<?> configurable, RSARemoteServiceRegistration registration) {
	// This overrides/replaces superclass implementation to setup
	// ObjectMapperContextResolver, and Jackson Jaxb Json parsing/writing
	configurable.register(new ObjectMapperContextResolver(), ContextResolver.class);
	configurable.register(JsonParseExceptionMapper.class);
	configurable.register(JsonMappingExceptionMapper.class);
	configurable.register(new JacksonJaxbJsonProvider(), jacksonPriority);
}
 
Example #6
Source File: JaxRSServerJacksonFeature.java    From JaxRSProviders with Apache License 2.0 5 votes vote down vote up
@Override
public boolean configure(final FeatureContext context) {
	if (!context.getConfiguration().isRegistered(JacksonJaxbJsonProvider.class)) {
		context.register(JsonParseExceptionMapper.class);
		context.register(JsonMappingExceptionMapper.class);
		context.register(new JaxRSServerJacksonJaxbJsonProvider(registration));
	}
	return true;
}
 
Example #7
Source File: RestPlugin.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private void addJacksonProviders(Collection<Class<?>> providers) {
    providers.add(JsonMappingExceptionMapper.class);
    providers.add(JsonParseExceptionMapper.class);
    if (Classes.optional("javax.xml.bind.JAXBElement").isPresent()) {
        LOGGER.debug("JSON/XML support is enabled");
        providers.add(JacksonJaxbJsonProvider.class);
    } else {
        LOGGER.debug("JSON support is enabled");
        providers.add(JacksonJsonProvider.class);
    }
}
 
Example #8
Source File: Application.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Register a body provider and optional exception mapper for (de)serializing JSON in
 * request/response entities.
 * @param config The config to register the provider with
 * @param restConfig The application's configuration
 * @param registerExceptionMapper Whether or not to register an additional exception mapper for
 *                                handling errors in (de)serialization
 */
protected void registerJsonProvider(
    Configurable<?> config,
    T restConfig,
    boolean registerExceptionMapper
) {
  ObjectMapper jsonMapper = getJsonMapper();
  JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(jsonMapper);
  config.register(jsonProvider);
  if (registerExceptionMapper) {
    config.register(JsonParseExceptionMapper.class);
  }
}
 
Example #9
Source File: DrillRestServer.java    From Bats with Apache License 2.0 4 votes vote down vote up
public DrillRestServer(final WorkManager workManager, final ServletContext servletContext, final Drillbit drillbit) {
  register(DrillRoot.class);
  register(StatusResources.class);
  register(StorageResources.class);
  register(ProfileResources.class);
  register(QueryResources.class);
  register(MetricsResources.class);
  register(ThreadsResources.class);
  register(LogsResources.class);

  property(FreemarkerMvcFeature.TEMPLATE_OBJECT_FACTORY, getFreemarkerConfiguration(servletContext));
  register(FreemarkerMvcFeature.class);

  register(MultiPartFeature.class);
  property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, true);

  final boolean isAuthEnabled =
      workManager.getContext().getConfig().getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED);

  if (isAuthEnabled) {
    register(LogInLogOutResources.class);
    register(AuthDynamicFeature.class);
    register(RolesAllowedDynamicFeature.class);
  }

  //disable moxy so it doesn't conflict with jackson.
  final String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(CommonProperties.MOXY_JSON_FEATURE_DISABLE,
      getConfiguration().getRuntimeType());
  property(disableMoxy, true);

  register(JsonParseExceptionMapper.class);
  register(JsonMappingExceptionMapper.class);
  register(GenericExceptionMapper.class);

  JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
  provider.setMapper(workManager.getContext().getLpPersistence().getMapper());
  register(provider);

  // Get an EventExecutor out of the BitServer EventLoopGroup to notify listeners for WebUserConnection. For
  // actual connections between Drillbits this EventLoopGroup is used to handle network related events. Though
  // there is no actual network connection associated with WebUserConnection but we need a CloseFuture in
  // WebSessionResources, so we are using EvenExecutor from network EventLoopGroup pool.
  final EventExecutor executor = workManager.getContext().getBitLoopGroup().next();

  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bind(drillbit).to(Drillbit.class);
      bind(workManager).to(WorkManager.class);
      bind(executor).to(EventExecutor.class);
      bind(workManager.getContext().getLpPersistence().getMapper()).to(ObjectMapper.class);
      bind(workManager.getContext().getStoreProvider()).to(PersistentStoreProvider.class);
      bind(workManager.getContext().getStorage()).to(StoragePluginRegistry.class);
      bind(new UserAuthEnabled(isAuthEnabled)).to(UserAuthEnabled.class);
      if (isAuthEnabled) {
        bindFactory(DrillUserPrincipalProvider.class).to(DrillUserPrincipal.class);
        bindFactory(AuthWebUserConnectionProvider.class).to(WebUserConnection.class);
      } else {
        bindFactory(AnonDrillUserPrincipalProvider.class).to(DrillUserPrincipal.class);
        bindFactory(AnonWebUserConnectionProvider.class).to(WebUserConnection.class);
      }
    }
  });
}
 
Example #10
Source File: RestServerV2.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
protected void init(ScanResult result) {
  // FILTERS //
  register(JSONPrettyPrintFilter.class);
  register(MediaTypeFilter.class);

  // RESOURCES //
  for (Class<?> resource : result.getAnnotatedClasses(RestResource.class)) {
    register(resource);
  }

  // FEATURES
  property(FreemarkerMvcFeature.TEMPLATE_OBJECT_FACTORY, getFreemarkerConfiguration());
  register(FreemarkerMvcFeature.class);
  register(MultiPartFeature.class);
  register(FirstTimeFeature.class);
  register(DACAuthFilterFeature.class);
  register(DACExceptionMapperFeature.class);
  register(DACJacksonJaxbJsonFeature.class);
  register(JSONJobDataFilter.class);
  register(TestResourcesFeature.class);

  // LISTENERS //
  register(TimingApplicationEventListener.class);

  // EXCEPTION MAPPERS //
  register(JsonParseExceptionMapper.class);
  register(JsonMappingExceptionMapper.class);


  //  BODY WRITERS //
  register(QlikAppMessageBodyGenerator.class);
  register(TableauMessageBodyGenerator.class);


  // PROPERTIES //
  property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true");

  final String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(CommonProperties.MOXY_JSON_FEATURE_DISABLE,
      getConfiguration().getRuntimeType());
  property(disableMoxy, true);
  property(TableauMessageBodyGenerator.CUSTOMIZATION_ENABLED, false);
}