Camel DataFormat Jackson using blueprint XML DSL t

2019-06-14 14:28发布

问题:

No matter where I place the dataformats in XML DSL blueprint, I get this error just starting at different places. if I remove it, it works but of course I can't convert JSON to POJO. ??? any help or tell me what I'm doing wrong, what i'm missing. thanks!

Error

Unable to start blueprint container for bundle passthrumt1.core/1.0.1.SNAPSHOT
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'endpoint'. One of '{"http://camel.apache.org/schema/blueprint":redeliveryPolicyProfile, "http://camel.apache.org/schema/blueprint":onException, "http://camel.apache.org/schema/blueprint":onCompletion, "http://camel.apache.org/schema/blueprint":intercept, "http://camel.apache.org/schema/blueprint":interceptFrom, "http://camel.apache.org/schema/blueprint":interceptSendToEndpoint, "http://camel.apache.org/schema/blueprint":restConfiguration, "http://camel.apache.org/schema/blueprint":rest, "http://camel.apache.org/schema/blueprint":route}' is expected.

XML DSL

   <camelContext     
      id="com.passthru.coreCamelContext"
      trace="true"
      xmlns="http://camel.apache.org/schema/blueprint"
      allowUseOriginalMessage="false"
      streamCache="true"
      errorHandlerRef="deadLetterErrorHandler" >

    <properties>
        <property key="http.proxyHost" value="PITC-Zscaler-Americas.proxy.corporate.com"/>
        <property key="http.proxyPort" value="80"/>
    </properties>

    <streamCaching  id="CacheConfig" 
                    spoolUsedHeapMemoryThreshold="70" 
                    anySpoolRules="true"/>
<!--  -->
    <dataFormats>
            <json id="Json2Pojo" library="Jackson" unmarshalTypeName="com.passthru.core.entities.TokenEntities">
            </json>
    </dataFormats>

    <endpoint id="predixConsumer" uri="direct:preConsumer" />
    <endpoint id="predixProducer" uri="direct:preProducer" />
    <endpoint id="getToken" uri="direct:getToken" />

      <onException>
        <exception>com.passthru.dataservice.PDXDataServiceInvalidDataException</exception>
        <redeliveryPolicy maximumRedeliveries="3" />
        <handled>
          <constant>true</constant>
        </handled>
        <log
          message="Invalid Data From Data Service"
          loggingLevel="ERROR" />
        <setBody>
          <simple>${body.toString}</simple>
        </setBody>
        <to uri="file:{{errorArchive}}" />
      </onException>

If I place the dataformats above properties, it complains, I have to remove properties and streamcache statements in order for it to work. but I need the proxy properties. any suggestions??? thanks again

If the

<camelContext     
  id="com.ge.digital.passthru.coreCamelContext"
  trace="true"
  xmlns="http://camel.apache.org/schema/blueprint"
  allowUseOriginalMessage="false"
  streamCache="true"
  errorHandlerRef="deadLetterErrorHandler" >
<dataFormats>
    <json id="Json2Pojo" library="Jackson" unmarshalTypeName="com.passthru.core.entities.TokenEntities"/>
</dataFormats>
<properties>
    <property key="http.proxyHost" value="PITC-Zscaler-Americas-Cincinnati3PR.proxy.corporate.com"/>
    <property key="http.proxyPort" value="80"/>
</properties>

i get this

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'properties'. One of '{"http://camel.apache.org/schema/blueprint":redeliveryPolicyProfile, "http://camel.apache.org/schema/blueprint":onException, "http://camel.apache.org/schema/blueprint":onCompletion, "http://camel.apache.org/schema/blueprint":intercept, "http://camel.apache.org/schema/blueprint":interceptFrom, "http://camel.apache.org/schema/blueprint":interceptSendToEndpoint, "http://camel.apache.org/schema/blueprint":restConfiguration, "http://camel.apache.org/schema/blueprint":rest, "http://camel.apache.org/schema/blueprint":route}' is expected.

what am I missing?

回答1:

Camel blueprint XML is validated against camel-blueprint.xsd. You are interested in complex type with name camelContextFactoryBean which contains sequence of available elements with fixed order.

Correct order of camelContext elements defined in this sequence is:

  • properties
  • globalOptions
  • propertyPlaceholder
  • package
  • packageScan
  • contextScan
  • jmxAgent
  • streamCaching
  • export
  • defaultServiceCallConfiguration
  • serviceCallConfiguration
  • defaultHystrixConfiguration
  • hystrixConfiguration
  • routeBuilder
  • routeContextRef
  • restContextRef
  • threadPoolProfile
  • threadPool
  • endpoint
  • dataFormats
  • transformers
  • validators
  • redeliveryPolicyProfile
  • onException
  • onCompletion
  • intercept
  • interceptFrom
  • interceptSendToEndpoint
  • restConfiguration
  • rest
  • route

To solve your problem move all endpoint declarations right above dataFormats.