Skip to main content

#""0 人正在讨论

I am getting below error as I have a HTTP requester node where we have a PUT call so there is no response body.

 

So while creating inbound response we get below error on Transform node.

Unable to parse empty input, while reading `payload` as Json

 

If I do a setPaylod like below with empty body then it works.

<set-payload value="#{}" doc:name="Set Payload" doc:id="4d3edefb-a8c4-43af-bfa4-4625f536509f" />

 

However I am looking for a solution to handle this in the transform node itself.Unable to parse empty input, while reading `payload` as JsonPlease let me know how to handle this in transform node in the best possible way ?

11 个回答
  1. Shekh Muenuddeen (NTTData) Forum Ambassador
    2021年11月24日 16:01

    Hey,

     

    check once with below code in dataweave 2 mule 4

    %dw 2.0

    output application/java

    ---

    if(!isEmpty(payload))

    payload

    else

    null

    As per article its seem content type issue, means request body without content type

    https://help.mulesoft.com/s/article/Unable-to-parse-empty-input-error-with-Dataweave-Mule-4

0/9000

As part of settings we kept Total ttl=120 and Token ttl timeout unit= Seconds.

 

But after 120 seconds when client tries to use the expired access token, he is still able to by-pass the validation, where are our expectation is that Oauth2.0 validation should fail with error type 'OAUTH2-PROVIDER:TOKEN_UNAUTHORIZED'.

 

Please find below details configuration xml for reference.

 

Note:

As of now we are going with a workaround using component Revoke token, which we are applying it after specified time in async scope which is doing the job. But as per our understanding this is not an ideal solution.

 

Reference XML:

 

<mule

 xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"

 xmlns:oauth="http://www.mulesoft.org/schema/mule/oauth"

 xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"

 xmlns:os="http://www.mulesoft.org/schema/mule/os"

 xmlns:oauth2-provider="http://www.mulesoft.org/schema/mule/oauth2-provider"

 xmlns:http="http://www.mulesoft.org/schema/mule/http"

 xmlns="http://www.mulesoft.org/schema/mule/core"

 xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd

http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd

http://www.mulesoft.org/schema/mule/oauth2-provider http://www.mulesoft.org/schema/mule/oauth2-provider/current/mule-oauth2-provider.xsd

http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd

http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd

http://www.mulesoft.org/schema/mule/oauth http://www.mulesoft.org/schema/mule/oauth/current/mule-oauth.xsd

http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">

 <http:listener-config name="HTTP_Listener_config"

  doc:name="HTTP Listener config"

  doc:id="778f937f-a80a-4060-be6c-8f5212c8b73b">

  <http:listener-connection host="0.0.0.0"

   port="8080" />

 </http:listener-config>

 <os:object-store name="client-os"

  doc:name="Object store" doc:id="91296a69-57d5-4766-ac76-ec1ff662acc8" />

 <os:object-store name="token-os"

  doc:name="Object store" doc:id="82a51666-3c83-4b32-9c06-32e97abb6ab6" />

 <oauth2-provider:config

  name="OAuth2_Provider_Config" doc:name="OAuth2 Provider Config"

  doc:id="66ea9233-dfeb-44af-bf79-8a2e01b56cbb"

  listenerConfig="HTTP_Listener_config" clientStore="client-os"

  supportedGrantTypes="CLIENT_CREDENTIALS">

  <oauth2-provider:client-validation-rate-limiter >

   <oauth2-provider:period-rate-limiter duration="60" />

  </oauth2-provider:client-validation-rate-limiter>

  <oauth2-provider:token-config tokenStore="token-os" tokenTtl="120" >

  </oauth2-provider:token-config>

 </oauth2-provider:config>

 <flow name="create-client" doc:id="8373609a-4a30-4662-bf4e-93a316d1619f" >

  <http:listener doc:name="Listener" doc:id="3371c037-6f19-4f07-adb8-fb8435dfa0bb" config-ref="HTTP_Listener_config" path="/create"/>

  <oauth2-provider:create-client doc:name="Create client" doc:id="d1a9fdf4-fe08-4bb9-9e39-264c3489bd39" config-ref="OAuth2_Provider_Config" clientId="#attributes.headers.client_id" type="CONFIDENTIAL" secret="#attributes.headers.client_secret" description='#""' principal='#""' redirectUris='#["abc.com"]' authorizedGrantTypes='#["CLIENT_CREDENTIALS"]' failIfPresent="true"/>

  <ee:transform doc:name="Transform Message" doc:id="fd369b5a-ccf6-47e2-9a54-507c4aa1d4d2" >

   <ee:message >

    <ee:set-payload ><![CDATA[%dw 2.0

output application/json

---

"Client Created"]]></ee:set-payload>

   </ee:message>

  </ee:transform>

 </flow>

 <flow name="validate-token" doc:id="23febab6-588e-46fe-9487-82711b26f291" >

  <http:listener doc:name="Listener" doc:id="89b2d88f-7532-46bc-b9db-576bc6c8dd1b" config-ref="HTTP_Listener_config" path="/validate"/>

  <oauth2-provider:validate-token doc:name="Validate token" doc:id="ef60d50a-c3a9-497f-8f3f-49c6b992e317" config-ref="OAuth2_Provider_Config"/>

  <ee:transform doc:name="Transform Message" doc:id="06f69772-b600-407e-aa97-c5a796356af1">

   <ee:message>

    <ee:set-payload><![CDATA[%dw 2.0

output application/json

---

payload]]></ee:set-payload>

   </ee:message>

  </ee:transform>

 </flow>

</mule>

13 个回答
  1. 2020年7月22日 13:40

    Correct, you could give it one final try by using the in-memory object store (uncheck v2 os store from runtime and set the config as non-persistent), I think then it will work.

     

    Using the in-memory object-store is not ideal because you will lose horizontal scaling.

    In either case, be aware of the object store v2 - 30 day expiry of your values if you continue using it.

0/9000

In the Oauth2 provider config settings I kept Token ttl=120 and Token ttl timeout unit= Seconds. 

But after 120 seconds the token is not getting expired, its still able to by-pass the validation, but I expect Invalid/expired token error.

I also tried setting in the Token object store Entry ttl as 30 sec, but still it does not work..

 

Help please.. I am stuck...

6 个回答
0/9000

I am using the default mongodb connector and can't see how to use the connector to search for a specific document by fields. I have the following,

 

<mongo:find-documents collectionName="nest" doc:name="Find documents" doc:id="e882996d-3af2-46f8-a638-db2f86c94e21" config-ref="MongoDB_Config" fields='#"_id"'>

<mongo:query ><![CDATA[#[{

"_id": "5f05c70ff50ecf4fb1a06135"

}]]]></mongo:query>

</mongo:find-documents>

...

 

Ok I changed to the following below, this seems to find all documents. How can I get the query to work, I will try payload. And I had to add the fields to return all fields

 

<mongo:find-documents collectionName="nest" doc:name="Find documents" doc:id="e882996d-3af2-46f8-a638-db2f86c94e21" config-ref="MongoDB_Config" fields='#""'>

 ...

 

Message        : org.bson.json.JsonParseException: JSON reader was expecting a value but found 'abc'.

Element        : lexis-nexis-mongodb-implFlow/processors/5 @ accounts-clients-info-sys:lexis-nexis-mongodb-impl.xml:53 (Find documents)

Element XML      : <mongo:find-documents collectionName="nest" doc:name="Find documents" doc:id="e882996d-3af2-46f8-a638-db2f86c94e21" config-ref="MongoDB_Config" fields="#""">

            <mongo:query>abc</mongo:query>

            </mongo:find-documents>

Error type      : MULE:UNKNOWN

1 个回答
  1. 2020年7月10日 13:20

    This is what I ended up with, this was not documented. Seems to work and filters down to a specific document. And the payload will have the search criteria.

     

    <mongo:find-documents collectionName="nest" doc:name="Find documents - Search" doc:id="e882996d-3af2-46f8-a638-db2f86c94e21" config-ref="MongoDB_Config" fields='#""'>

    <mongo:query><![CDATA[#payload]]></mongo:query>

    </mongo:find-documents>

0/9000