New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[management] Dynamic properties services crash when the response is an array #1051

Closed
JulienFauvel opened this Issue Feb 1, 2018 · 0 comments

Comments

Projects
None yet
3 participants
@JulienFauvel

JulienFauvel commented Feb 1, 2018

The Dynamic properties services crash when the response is an array

Expected Behavior

An array should be a valid response

Current Behavior

Crashes when an array is received (see below for stacktrace)

Possible Solution

In JoltMapper.java, call JsonUtils.jsonToList if the JSON is an array or call JsonUtils.jsonToMap if it's an object

Steps to Reproduce (for bugs)

  1. Setup a dynamic properties with an url which returns an array
    Example :
[
   {
       "key": "test",
       "value": "test-value"
   }
]
  1. Set a Jolt that do nothing
[
  { 
    "operation": "default",
    "spec": {}
  }
]
  1. Watch logs
10:34:05.088 [sync-1] ERROR o.s.s.s.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
com.bazaarvoice.jolt.exception.JsonUnmarshalException: Unable to unmarshal JSON to a List.
        at com.bazaarvoice.jolt.JsonUtilImpl.jsonToList(JsonUtilImpl.java:157)
        at com.bazaarvoice.jolt.JsonUtilImpl.jsonToList(JsonUtilImpl.java:144)
        at com.bazaarvoice.jolt.JsonUtilImpl.jsonToList(JsonUtilImpl.java:138)
        at com.bazaarvoice.jolt.JsonUtils.jsonToList(JsonUtils.java:133)
        at io.gravitee.management.services.dynamicproperties.provider.http.mapper.JoltMapper.<init>(JoltMapper.java:50)
        at io.gravitee.management.services.dynamicproperties.provider.http.HttpProvider.<init>(HttpProvider.java:59)
        at io.gravitee.management.services.dynamicproperties.DynamicPropertiesService.startDynamicProperties(DynamicPropertiesService.java:101)
        at io.gravitee.management.services.dynamicproperties.DynamicPropertiesService.onEvent(DynamicPropertiesService.java:89)
        at io.gravitee.common.event.impl.EventManagerImpl.publishEvent(EventManagerImpl.java:44)
        at io.gravitee.common.event.impl.EventManagerImpl.publishEvent(EventManagerImpl.java:36)
        at io.gravitee.management.services.sync.ApiManager.update(ApiManager.java:57)
        at io.gravitee.management.services.sync.SyncManager.lambda$refresh$5(SyncManager.java:114)
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
        at java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1691)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
        at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
        at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
        at io.gravitee.management.services.sync.SyncManager.refresh(SyncManager.java:96)
        at io.gravitee.management.services.sync.ScheduledSyncService.doSync(ScheduledSyncService.java:86)
        at io.gravitee.management.services.sync.ScheduledSyncService.run(ScheduledSyncService.java:76)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
 at [Source: java.io.ByteArrayInputStream@6ccdadfb; line: 1, column: 1]
        at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270)
        at com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1234)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1122)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1075)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:338)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:269)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:259)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3798)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2915)
        at com.bazaarvoice.jolt.JsonUtilImpl.jsonToList(JsonUtilImpl.java:154)
        ... 32 common frames omitted

Context

I have a webservice that returns an array and don't need any modifications to be injected in the dynamic properties

Your Environment

  • Version used: 1.12.5
  • Browser Name and version: x
  • Operating System and version: Debian

@NicolasGeraud NicolasGeraud added this to the 1.14.0 milestone Feb 1, 2018

@NicolasGeraud NicolasGeraud self-assigned this Feb 1, 2018

NicolasGeraud added a commit to gravitee-io/gravitee-management-rest-api that referenced this issue Feb 1, 2018

NicolasGeraud added a commit to gravitee-io/gravitee-management-rest-api that referenced this issue Feb 1, 2018

NicolasGeraud added a commit to gravitee-io/gravitee-management-rest-api that referenced this issue Feb 1, 2018

brasseld added a commit to gravitee-io/gravitee-management-rest-api that referenced this issue Feb 1, 2018

@NicolasGeraud NicolasGeraud modified the milestones: 1.14.0, 1.13.2 Feb 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment