禁用身份验证时在MuleStudio中配置MongoDB连接器 - “连接失败”错误

时间:2013-10-10 18:48:54

标签: mongodb mule mule-studio

我正在MuleStudio中编写一些保存并查询MongoDB数据库的流程。当指向具有一个具有dbAdmin和userAdmin角色的用户并使用该用户的凭据配置的数据库时,流可以正常工作。但是,当我将其指向不添加用户的其他数据库时,我收到以下错误。我将用户名和密码保存在Mule中的MongoDB连接器配置中,作为文档中建议的虚拟文本,然后将它们取出,但无济于事。我正在使用3.3.1 CE运行时。

虚拟凭据的错误消息:

ERROR 2013-10-10 14:48:08,176 [[sso-mds].connector.http.mule.default.receiver.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: Could not create a validated object, cause: Couldn't connect with the given credentials. Type: class java.util.NoSuchElementException
ERROR 2013-10-10 14:48:08,181 [[sso-mds].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to invoke findObjectsUsingQueryMap. Message payload is of type: LinkedHashMap
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Could not create a validated object, cause: Couldn't connect with the given credentials (java.util.NoSuchElementException)
  org.apache.commons.pool.impl.GenericKeyedObjectPool:1219 (null)
2. Failed to invoke findObjectsUsingQueryMap. Message payload is of type: LinkedHashMap (org.mule.api.MessagingException)
  org.mule.module.mongo.processors.FindObjectsUsingQueryMapMessageProcessor:177 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.util.NoSuchElementException: Could not create a validated object, cause: Couldn't connect with the given credentials
    at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1219)
    at org.mule.module.mongo.connectivity.MongoCloudConnectorConnectionManager.acquireConnection(MongoCloudConnectorConnectionManager.java:437)
    at org.mule.module.mongo.connectivity.MongoCloudConnectorConnectionManager.acquireConnection(MongoCloudConnectorConnectionManager.java:27)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

没有凭据的错误消息:

ERROR 2013-10-10 14:19:48,572 [[sso-mds].connector.http.mule.default.receiver.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: null. Type: class java.lang.NullPointerException
ERROR 2013-10-10 14:19:48,574 [[sso-mds].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to invoke findObjectsUsingQueryMap. Message payload is of type: LinkedHashMap
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. null (java.lang.NullPointerException)
  org.mule.module.mongo.connectivity.MongoCloudConnectorConnectionKey:86 (null)
2. Failed to invoke findObjectsUsingQueryMap. Message payload is of type: LinkedHashMap (org.mule.api.MessagingException)
  org.mule.module.mongo.processors.FindObjectsUsingQueryMapMessageProcessor:177 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
    at org.mule.module.mongo.connectivity.MongoCloudConnectorConnectionKey.hashCode(MongoCloudConnectorConnectionKey.java:86)
    at java.util.HashMap.hash(Unknown Source)
    at java.util.HashMap.getEntry(Unknown Source)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Mule config:

<mongo:config name="Mongo_DB"  doc:name="Mongo DB" database="${mongo.db}" host="${mongo.host}" port="${mongo.port}" password="${db.password}" username="${db.username}>
    <mongo:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</mongo:config>
<flow name="user_gets_simple" doc:name="user_gets_simple">
    <composite-source doc:name="Composite Source">
        <http:inbound-endpoint exchange-pattern="request-response" host="${my.host}" port="${my.ID}" path="user/getAll" doc:name="HTTP /user/getAll"/>
        <http:inbound-endpoint exchange-pattern="request-response" host="${my.host}" port="${my.ID}" path="user/getByUsername" doc:name="HTTP /user/getByUsername"/>
        <http:inbound-endpoint exchange-pattern="request-response" host="${my.host}" port="${my.ID}" path="user/getById" doc:name="HTTP /user/getById"/>
        <http:inbound-endpoint exchange-pattern="request-response" host="${my.host}" port="${my.ID}" path="user/getByEmail" doc:name="HTTP /user/getByEmail"/>
    </composite-source>
    <flow-ref name="get_from_MongoDB" doc:name="Get from MongoDB subflow"/>
</flow>

<flow name="user_save_flow" doc:name="user_save_flow">
    <http:inbound-endpoint exchange-pattern="request-response" host="${my.host}" port="${my.ID}" path="user/save" doc:name="HTTP /user/save" />
    <byte-array-to-string-transformer doc:name="Byte Array to String"/>
    <json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Map"/>
    <mongo:insert-object-from-map config-ref="Mongo_DB" collection="${mongo.collection}" doc:name="Insert in Mongo DB"  >
        <mongo:element-attributes>
            <mongo:element-attribute key="firstName">#[payload.firstName]</mongo:element-attribute>
            <mongo:element-attribute key="lastName">#[payload.lastName]</mongo:element-attribute>
            <mongo:element-attribute key="location">#[payload.location]</mongo:element-attribute>
        </mongo:element-attributes>
    </mongo:insert-object-from-map>
    <set-payload value="Saved successfully" doc:name="Set Payload"/>
</flow>

<sub-flow name="get_from_MongoDB" doc:name="get_from_MongoDB">
    <byte-array-to-string-transformer doc:name="Byte Array to String"/>
    <json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
    <mongo:find-objects-using-query-map config-ref="Mongo_DB" collection="${mongo.collection}" doc:name="Find objects in Mongo DB" limit="5">
        <mongo:query-attributes ref="#[payload]"/>
    </mongo:find-objects-using-query-map>
    <mongo:mongo-collection-to-json doc:name="Mongo collection to JSON"/>
</sub-flow>

有关如何在不添加用户的情况下连接到此数据库的任何建议吗?

3 个答案:

答案 0 :(得分:1)

不确定如何将任何虚拟值放置,因为连接器会将其作为用户名和密码传递。但我尝试了这个技巧,它的确有效。 ${db.user}和mule-app.properties只有一个空条目db.user=,并且工作正常。

答案 1 :(得分:0)

嗨,这是一个问题,因为Mule ESB无法在没有身份验证的情况下工作... 用户和密码字段不是“@optional”。

用于在mongo中创建用户并在身份验证模式下运行mongo

http://www.mkyong.com/mongodb/mongodb-authentication-example/

然后你可以把它放在Mule ESB中,你就可以了 ....

答案 2 :(得分:0)

只需添加mongo-java-driver:2.13.3依赖项。检查maven对冲突的依赖性。