jamee
jamee

Reputation: 573

mule's http-proxy cannot be used in flow?

I would like to do a proxy for backend rest service, but before I forward the request to backend, I need to do some checks. I checked the docments, there is a http-proxy can be used to do the proxy, but when I put into the flow, there are exceptions. If I use the http:outbound-endpoint the method cannot be a dynamic MEL expression(rest method could be POST, GET, PUT, DELTE etc).

Could you give me a suggestion? An example will be better, Thanks a lot. My Configuration:

<flow name="demo.routerFlow1" doc:name="demo.routerFlow1">
  <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="HTTP" />
  <logger
    message="Method: #[message.inboundProperties['http.method']], URI: #[message.inboundProperties['http.request.path']], Params: #[message.inboundProperties['http.query.params']]"
    level="INFO" doc:name="Logger" />
  <http:body-to-parameter-map-transformer doc:name="Body to Parameter Map" />
  <choice doc:name="Choice">
    <when expression="(payload['timestamp'] == null || payload['nonce'] == null)">
      <expression-component doc:name="Check Required Params"><![CDATA[payload="{\"code\":\"PA001\", \"message\":\"missing required parameter timestamp and nonce\"}"]]>
      </expression-component>
    </when>
    <otherwise>
      <choice doc:name="Choice">
        <when expression="!replayAttackCheck.validate(payload)" evaluator="groovy">
          <expression-component doc:name="Check Required Params"><![CDATA[payload="{\"code\":\"PA002\", \"message\":\"timestamp or nonce is illegal\"}"]]>
          </expression-component>
        </when>
        <otherwise>
          <processor-chain doc:name="Processor Chain">
            <pattern:http-proxy name="http-proxy-sample"> <!--line 38-->
              <http:inbound-endpoint address="http://localhost:8080/"></http:inbound-endpoint>
              <http:outbound-endpoint address="http://localhost:8081/"></http:outbound-endpoint>
            </pattern:http-proxy>
          </processor-chain>
        </otherwise>
      </choice>
    </otherwise>
  </choice>
</flow>

Error:

Caused by: org.xml.sax.SAXParseException; lineNumber: 38; columnNumber: 31; cvc-complex-type.2.4.b: The content of element 'processor-chain' is not complete. One of '{"http://www.mulesoft.org/schema/mule/core":annotations, "http://www.mulesoft.org/schema/mule/core":description, "http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' is expected.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

Upvotes: 1

Views: 1529

Answers (2)

Ryan Carter
Ryan Carter

Reputation: 11606

Configuration patterns are standalone and separate from any flow and cannot be configured within one. They are predefined integration patterns for common scenarios. Flows are for rolling your own. See here: http://www.mulesoft.org/documentation/display/current/Choosing+Between+Flows+and+Patterns

As a side note: Your already listening on localhost:8080, so I think you just want a http:outbound-endpoint to the service your running on 8081

<http:outbound-endpoint address="http://localhost:8081/" />

Upvotes: 1

user1760178
user1760178

Reputation: 6697

You just need a http:outbound to the actual rest service in your otherwise block.

Try using the following.

<otherwise>
          <http:outbound-endpoint address="http://localhost:8081/"></http:outbound-endpoint>
</otherwise>

Hope this helps.

Upvotes: 1

Related Questions