You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在OCP上用Camel-K搭建WebLogic队列桥接时遇类转换错误

在OpenShift上用Camel-K搭建WebLogic JMS队列桥接时遇到ClassCastException错误

我在OpenShift Container Platform(OCP)上尝试使用Camel-K搭建两个WebLogic队列之间的桥接,但在定义Kamelet的队列连接逻辑时,启动应用抛出ClassCastException错误。

我的Kamelet YAML代码

apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: jms-weblogic-mq-source
  annotations:
    camel.apache.org/kamelet.group: "JMS"
  labels:
    camel.apache.org/kamelet.type: "source"
    camel.apache.org/requires.runtime: camel-k
spec:
  definition:
    name: jms-weblogic-mq-source
    properties:
      queueName:
        type: string
        title: Queue Name
        description: Name of the JMS queue to consume messages from
        required: true
      transacted:
        type: boolean
        title: Transacted
        description: Whether to use transacted sessions for consuming messages
        default: false
      acknowledgementModeName:
        type: string
        title: Acknowledgement Mode
        description: JMS acknowledgement mode to use when consuming messages
        default: AUTO_ACKNOWLEDGE
        enum:
          - AUTO_ACKNOWLEDGE
          - CLIENT_ACKNOWLEDGE
          - DUPS_OK_ACKNOWLEDGE
          - SESSION_TRANSACTED
      jndiInitialContextFactory:
        type: string
        title: JNDI Initial Context Factory
        description: JNDI Initial Context Factory for the WebLogic JMS server
        required: true
      jndiProviderUrl:
        type: string
        title: JNDI Provider URL
        description: JNDI Provider URL for the WebLogic JMS server
        required: true
      jndiConnectionFactoryName:
        type: string
        title: JNDI Connection Factory Name
        description: JNDI name of the connection factory to use
        required: true
      userName:
        type: string
        title: User Name
        description: User name to use when connecting to the WebLogic JMS server
        required: true
      password:
        type: string
        title: Password
        description: Password to use when connecting to the WebLogic JMS server
        required: true
  dependencies:
  - "camel:jms"
  - "camel:kamelet"
  - "mvn:com.oracle.weblogic:wlthint3client:12.1.3"
  - "mvn:org.springframework:spring-context:5.3.23"

  template:
    beans:
      - name: jndiTemplate
        type: "#class:org.springframework.jndi.JndiTemplate"
        properties:
          environment:
            - key: java.naming.factory.initial
              value: '{{jndiInitialContextFactory}}'
            - key: java.naming.provider.url
              value: '{{jndiProviderUrl}}'
            - key: java.naming.security.principal
              value: '{{userName}}'
            - key: ava.naming.security.credentials
              value: '{{password}}'
      - name: jndiObjectFactoryBean
        type: "#class:org.springframework.jndi.JndiObjectFactoryBean"
        properties:
            jndiTemplate: '#bean:jndiTemplate'
            jndiName: '{{jndiConnectionFactoryName}}'
            proxyInterface: javax.jms.ConnectionFactory
    from:
      uri: "jms:queue:{{queueName}}"
      parameters:
        connectionFactory: '#bean:jndiObjectFactoryBean#getObject'
        transacted: "{{transacted}}"
        deliveryMode: "{{acknowledgementModeName}}"
      steps:
      - to:
          uri: "kamelet:sink"

启动错误日志

[2023-03-15 14:00:37,449 ERROR org.apa.cam.qua.mai.CamelMainRuntime
Failed to start application: java.lang.ClassCastException: class java.util.HashMap cannot be cast to class java.lang.String (java.util.HashMap and java.lang.String are in module java.base of loader 'bootstrap')
[1]     at org.apache.camel.dsl.yaml.deserializers.BeanFactoryDefinitionDeserializer.lambda$setProperty$0(BeanFactoryDefinitionDeserializer.java:61)
[1]     at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
[1]     at java.base/java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1764)
[1]     at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
[1]     at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
[1]     at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
[1]     at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[1]     at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
[1]     at org.apache.camel.dsl.yaml.deserializers.BeanFactoryDefinitionDeserializer.setProperty(BeanFactoryDefinitionDeserializer.java:62)

问题分析与修复

错误原因

  1. Environment属性格式错误:Spring JndiTemplate 的 environment 属性要求是 Map<String, String> 类型,但当前YAML中用了数组形式的key-value列表,Camel YAML DSL解析时将其转换为 List<HashMap>,赋值给期望接收String类型Map的属性时触发类型转换异常。
  2. JNDI属性拼写错误:ava.naming.security.credentials 少写了字母j,正确应为 java.naming.security.credentials。
  3. JMS参数映射错误:deliveryMode 参数与定义的 acknowledgementModeName 不匹配,JMS组件中对应的参数是 acknowledgementMode。

修正后的YAML代码

apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: jms-weblogic-mq-source
  annotations:
    camel.apache.org/kamelet.group: "JMS"
  labels:
    camel.apache.org/kamelet.type: "source"
    camel.apache.org/requires.runtime: camel-k
spec:
  definition:
    name: jms-weblogic-mq-source
    properties:
      queueName:
        type: string
        title: Queue Name
        description: Name of the JMS queue to consume messages from
        required: true
      transacted:
        type: boolean
        title: Transacted
        description: Whether to use transacted sessions for consuming messages
        default: false
      acknowledgementModeName:
        type: string
        title: Acknowledgement Mode
        description: JMS acknowledgement mode to use when consuming messages
        default: AUTO_ACKNOWLEDGE
        enum:
          - AUTO_ACKNOWLEDGE
          - CLIENT_ACKNOWLEDGE
          - DUPS_OK_ACKNOWLEDGE
          - SESSION_TRANSACTED
      jndiInitialContextFactory:
        type: string
        title: JNDI Initial Context Factory
        description: JNDI Initial Context Factory for the WebLogic JMS server
        required: true
      jndiProviderUrl:
        type: string
        title: JNDI Provider URL
        description: JNDI Provider URL for the WebLogic JMS server
        required: true
      jndiConnectionFactoryName:
        type: string
        title: JNDI Connection Factory Name
        description: JNDI name of the connection factory to use
        required: true
      userName:
        type: string
        title: User Name
        description: User name to use when connecting to the WebLogic JMS server
        required: true
      password:
        type: string
        title: Password
        description: Password to use when connecting to the WebLogic JMS server
        required: true
  dependencies:
  - "camel:jms"
  - "camel:kamelet"
  - "mvn:com.oracle.weblogic:wlthint3client:12.1.3"
  - "mvn:org.springframework:spring-context:5.3.23"

  template:
    beans:
      - name: jndiTemplate
        type: "#class:org.springframework.jndi.JndiTemplate"
        properties:
          environment:
            java.naming.factory.initial: '{{jndiInitialContextFactory}}'
            java.naming.provider.url: '{{jndiProviderUrl}}'
            java.naming.security.principal: '{{userName}}'
            java.naming.security.credentials: '{{password}}'
      - name: jndiObjectFactoryBean
        type: "#class:org.springframework.jndi.JndiObjectFactoryBean"
        properties:
            jndiTemplate: '#bean:jndiTemplate'
            jndiName: '{{jndiConnectionFactoryName}}'
            proxyInterface: javax.jms.ConnectionFactory
    from:
      uri: "jms:queue:{{queueName}}"
      parameters:
        connectionFactory: '#bean:jndiObjectFactoryBean#getObject'
        transacted: "{{transacted}}"
        acknowledgementMode: "{{acknowledgementModeName}}"
      steps:
      - to:
          uri: "kamelet:sink"

内容的提问来源于stack exchange,提问作者zoubir ouarab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 10:30:04