Cómo upsert documento sub JSONArray en couchbase

votos
2

Estoy tratando de upsert un JSONArray y algunos otros campos de un documento JSON existente en el couchbase, pero conseguir un error al llamar couchbase. ¡Por favor ayuda!

Aquí, estoy opción para fijar un JSONArray a la JsonBody que se establece a continuación al cuerpo de Exchange (ver más abajo)

    JSONArray smsRequestArray = new JSONArray();
    for(String camelSmppId : camelSmppIdList) {
        JSONObject obj = new JSONObject();
        obj.put(smsRequestId, camelSmppId);
        obj.put(status, InProgress);
        smsRequestArray.put(obj);
    }

jsonBody.put(smsRequest, smsRequestArray);
exchange.getIn().setBody(jsonBody.toString());

Ahora, quiero actualizar el documento Couchbase con esta matriz JSON

JSONArray updateObj = new JSONArray();
JSONObject smsRequest = new JSONObject();
smsRequest.put(VALUE, (JSONArray) jsonBody.get(smsRequest));
smsRequest.put(KEY, smsRequest);
updateObj.put(smsRequest);

Sin embargo, cuando el código de abajo se llama a actualizar el documento en couchbase, me sale un error.

operationObj.put(upsert, updateObj);

JSONObject cbMutateDocument = new JSONObject();       

cbMutateDocument.put(operations, operationObj);

newExchange.setProperty(BODY_PARAMETERS, cbMutateDocument.toString());

RouteHelper.sendRequest(getProducerTemplate(exchange), cbservice://mutate?key=+keyId+&bucket=notification, newExchange);

Por favor, hágamelo saber lo que está mal aquí.

Error:

2018-10-19 02:57:47,674 | ERROR | nsumer[smsQueue] | CBConnectorEndPointProcessor     |  |  |  |  |  |  |  |  | 383 - bil-cbconnector - 1.0.0.SNAPSHOT | Exception processing request :

com.couchbase.client.java.error.TranscodingException: Couldn't encode MutationSpec #1 (DICT_UPSERT on smsRequest) in 130f0781-925f-461d-8fe5-e53f1ca032c9

                at com.couchbase.client.java.transcoder.subdoc.AbstractByteArrayFragmentTranscoder.doEncodeSingle(AbstractByteArrayFragmentTranscoder.java:65)

                at com.couchbase.client.java.transcoder.subdoc.AbstractFragmentTranscoder.encodeWithMessage(AbstractFragmentTranscoder.java:50)

                at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$2.call(AsyncMutateInBuilder.java:1245)

                at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$2.call(AsyncMutateInBuilder.java:1232)

                at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)

                at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)

                at rx.Observable.unsafeSubscribe(Observable.java:10327)

                at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)

                at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)

                at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)

                at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)

                at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)

                at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)

                at rx.Observable.subscribe(Observable.java:10423)

                at rx.Observable.subscribe(Observable.java:10390)

                at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:443)

                at rx.observables.BlockingObservable.single(BlockingObservable.java:340)

                at com.couchbase.client.java.subdoc.MutateInBuilder.execute(MutateInBuilder.java:280)

                at com.couchbase.client.java.subdoc.MutateInBuilder.execute(MutateInBuilder.java:103)

                at com.amdocs.cb.component.CBConnectorEndPointProcessor.processRequest(CBConnectorEndPointProcessor.java:441)

                at com.amdocs.cb.component.CBConnectorEndPointProcessor.process(CBConnectorEndPointProcessor.java:244)

                at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:103)

                at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)

                at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:68)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:412)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:380)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:270)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:380)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:205)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:119)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:105)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at com.amdocs.bl.common.util.RouteHelper.sendRequest(RouteHelper.java:35)

                at com.amdocs.bil.notificationdispatcher.NotificationDispatchPostProcessor.process(NotificationDispatchPostProcessor.java:207)[398:bil-notification-dispatcher:1.0.0.SNAPSHOT]

                at com.amdocs.bil.notificationdispatcher.processors.MessageProcessor.processMessage(MessageProcessor.java:81)[398:bil-notification-dispatcher:1.0.0.SNAPSHOT]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_66]

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_66]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_66]

                at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_66]

                at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:408)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:279)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:252)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:177)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.Throttler.process(Throttler.java:164)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.component.directvm.DirectVmProcessor.process(DirectVmProcessor.java:55)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.component.directvm.DirectVmProducer.process(DirectVmProducer.java:63)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:68)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:412)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:380)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:270)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:380)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:205)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:119)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:105)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at com.amdocs.bil.notificationdispatcher.processors.MessageProcessor.process(MessageProcessor.java:58)[398:bil-notification-dispatcher:1.0.0.SNAPSHOT]

                at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.processNext(AsyncProcessorConverterHelper.java:87)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:82)[231:org.apache.camel.camel-core:2.17.0.redhat-630329]

                at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:112)[243:org.apache.camel.camel-jms:2.17.0.redhat-630329]

                at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:555)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:515)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:485)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1103)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1095)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:992)[242:org.apache.servicemix.bundles.spring-jms:3.2.18.RELEASE_1]

                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_66]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_66]

                at java.lang.Thread.run(Thread.java:745)[:1.8.0_66]

Caused by: com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.codehaus.jettison.json.JSONArray and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )

                at com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270)

                at com.couchbase.client.deps.com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:68)

                at com.couchbase.client.deps.com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)

                at com.couchbase.client.deps.com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130)

                at com.couchbase.client.deps.com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3631)

                at com.couchbase.client.deps.com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:3022)

                at com.couchbase.client.java.transcoder.subdoc.JacksonFragmentTranscoder.writeValueAsBytes(JacksonFragmentTranscoder.java:80)

                at com.couchbase.client.java.transcoder.subdoc.AbstractByteArrayFragmentTranscoder.doEncodeSingle(AbstractByteArrayFragmentTranscoder.java:63)

                ... 83 more
Publicado el 20/10/2018 a las 10:24
fuente por usuario
En otros idiomas...                            


2 respuestas

votos
2

Los tipos de Couchbase Java se nombran JsonDocument, JSONArray y JSONObject, en lugar de JSONDocument, JSONArray y JSONObject. Parece que puede que esté utilizando otra biblioteca JSON por error?

Respondida el 20/10/2018 a las 15:55
fuente por usuario

votos
0

He encontrado la solución.

Tuve que crear una matriz vacía en el documento Couchbase en el momento de la creación de documentos. Sólo entonces esa matriz puede mutarse mediante el uso de ' arrayAppend operación'.

A la hora de crear

JSONObject cbDocument = new JSONObject(messageBody);
cbDocument.put("smsRequest", new JSONArray());
exchange.setProperty("bodyParameters", cbDocument.toString());
RouteHelper.sendRequest(producerTemplate, "cbservice://create?bucket=notification", exchange);

Al momento de la actualización

List<JSONObject> operations = new ArrayList<JSONObject>();

JSONArray smsRequestArray = (JSONArray)jsonBody.get("smsRequest");
                for(int i=0; i<smsRequestArray.length(); i++) {
                    JSONArray arrayAppendOperationArray = new JSONArray();
                    JSONObject smsArrayAppendOperationObject = new JSONObject();

                    JSONObject smsRequest = new JSONObject();
                    smsRequest.put(VALUE, smsRequestArray.optJSONObject(i));
                    smsRequest.put(KEY, "smsRequest");
                    arrayAppendOperationArray.put(smsRequest);
                    smsArrayAppendOperationObject.put("arrayAppend", arrayAppendOperationArray);
                    operations.add(smsArrayAppendOperationObject);
                }

JSONObject cbMutateDocument = new JSONObject();

    for(int i=0; i < operations.size(); i++) {
                        cbMutateDocument.put("operations", operations.get(i));
                        newExchange.setProperty(BODY_PARAMETERS, cbMutateDocument.toString());  
                        RouteHelper.sendRequest(getProducerTemplate(exchange), "cbservice://mutate?key="+keyId+"&bucket=notification", newExchange);
                    }
Respondida el 11/11/2018 a las 17:06
fuente por usuario

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more