2
votes

I wanted to simulate the Google autocomplete in my mule application. I am using an ajax inbound endpoint to capture the text that is being entered in the browser (rpc call), the next step in the flow is to make a call to URL exposed by google. http://clients5.google.com/complete/search?client=ie8&q=##variable## So as to achieve the same I have used Dynamic HTTP outbound endpoint. For my clarity I added File outbound endpoint at last so as to see the full response from the HTTP endpoint.

<ajax:connector name="AjaxConnectorForSpelling" serverUrl="http://localhost:8081/Ajax" resourceBase="src/main/app/docroot" jsonCommented="false" doc:name="AjaxConnectorForSpelling"/>  

<http:connector name="HTTP_HTTPS" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" proxyHostname="bci****" proxyPort="8080" doc:name="HTTP\HTTPS"/>  

<http:endpoint exchange-pattern="request-response" method="GET" name="httpgoogle" address="http://clients5.google.com/complete/search?client=ie8&amp;q=#[header:INVOCATION:q]" connector-ref="HTTP_HTTPS" doc:name="HTTP"/>  

<flow name="GoogleAutoComplete" doc:name="GoogleAutoComplete">
    <ajax:inbound-endpoint channel="/services/echo" responseTimeout="10000" connector-ref="AjaxConnectorForSpelling" doc:name="Ajax Channel"/>       
    <message-properties-transformer doc:name="Message Properties" scope="invocation">
        <add-message-property key="q" value="#[payload.get('q')]"/>
    </message-properties-transformer>
    <http:outbound-endpoint ref="httpgoogle" responseTransformer-refs="xml_to_json" doc:name="HTTP"/>   

    <file:outbound-endpoint path="C:\Documents and Settings\I300543\Desktop\proxyfiles\xslt" responseTimeout="10000" doc:name="File"/>

</flow>

I am getting response from google as xml and its getting transformed in to JSON and the file endpoint is able to write it to filesystem. But my ajax connector is failing ( everthing works fine with the above configuration If I make the Outbound HTTP endpoint static- but that would give me the same search result each time)so there is no response that is being returned to back to brower.

I am getting this exception.

Caused by: org.mule.api.MessagingException: Endpoint scheme must be compatible with the connector scheme. Connector is: "ajax", endpoint is "http://clients5.google.com/complete/search?client=ie8&q=ask" (java.lang.IllegalArgumentException). Message payload is of type: String
at org.mule.endpoint.AbstractEndpointBuilder.doBuildOutboundEndpoint(AbstractEndpointBuilder.java:254)
at org.mule.endpoint.AbstractEndpointBuilder.buildOutboundEndpoint(AbstractEndpointBuilder.java:122)
at org.mule.endpoint.DefaultEndpointFactory.getOutboundEndpoint(DefaultEndpointFactory.java:89)
at org.mule.transport.ajax.AjaxReplyToHandler.processReplyTo(AjaxReplyToHandler.java:66)
at org.mule.routing.requestreply.AbstractReplyToPropertyRequestReplyReplier.processReplyTo(AbstractReplyToPropertyRequestReplyReplier.java:69)

So I am kind of confused why ajax connector is getting the reference of Http scheme ( only in case of Dynamic endpoint). I have just started working on Mule very recently, so I am not sure if I am configuring everthing correctly.

1

1 Answers

0
votes

Have you tried (as an experiment):

<ajax:connector name="AjaxConnectorForSpelling" ... disableReplyTo="true" />

Which should enable the File to get written but nothing returned to the browser. You could also try an ajax:outbound-endpoint to route responses back on a separate AJAX Bayeux channel.

This may be related to MULE-5783 , fixed in 3.2.1.