我想在我的 mule 应用程序中模拟 Google 自动完成功能。我正在使用 ajax 入站端点来捕获在浏览器中输入的文本(rpc 调用),流程中的下一步是调用 google 公开的 URL。 http://clients5.google.com/complete/search?client=ie8&q=##variable## 为了达到同样的效果,我使用了动态 HTTP 出站端点。为了清楚起见,我最后添加了文件出站端点,以便查看来自 HTTP 端点的完整响应。
<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&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>
我从 google 获得了 xml 的响应,并将其转换为 JSON,并且文件端点能够将其写入文件系统。但是我的 ajax 连接器失败了(如果我将出站 HTTP 端点设为静态,那么上述配置一切正常 - 但这每次都会给我相同的搜索结果)所以没有响应返回到浏览器。
我得到了这个例外。
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)
所以我有点困惑为什么 ajax 连接器正在获取 Http 方案的引用(仅在动态端点的情况下)。我最近才开始研究 Mule,所以我不确定我是否正确配置了一切。