使用Esper和Twitter进行复杂事件处理会产生twitter4j.internal.org.json.JSONException:JSONArray文本必须以'['开头

时间:2014-02-20 12:42:52

标签: mule complex-event-processing esper

嗨,我正在尝试http://www.mulesoft.org/connectors/es的例子...但它正在给出以下例外。引起:

  

twitter4j.internal.org.json.JSONException:必须启动JSONArray文本   用'['在1 [字符2第1行]处   twitter4j.internal.org.json.JSONTokener.syntaxError(JSONTokener.java:335)   在twitter4j.internal.org.json.JSONArray。(JSONArray.java:107)at at   twitter4j.internal.http.HttpResponse.asJSONArray(HttpResponse.java:185)   ... 54更多

任何人都试过同样的例子。或任何人都有解决方案。 谢谢。

1 个答案:

答案 0 :(得分:0)

在使用 get-home-timeline 操作时,有关twitter连接器的问题似乎存在某些问题(我刚刚为此提交了jira)。

我已经设法使用Esper连接器进行简单的mule应用程序来测试它,并且它正常工作。如果这有帮助,请告诉我(代码如下)

文件: esper-config.xml      

<esper-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.espertech.com/schema/esper" xsi:schemaLocation=" http://www.espertech.com/schema/esper http://www.espertech.com/schema/esper/esper-configuration-2.0.xsd">
    <event-type name="Person" class="org.mule.Person"/>
</esper-configuration>

file: Person.java

package org.mule;

import java.io.Serializable;

public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    private String name;
    private Integer age;

    public Person(String name, Integer age) {
        super();
        this.name = name;
        this.age = age;
    }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public Integer getAge() { return age; }
    public void setAge(Integer age) { this.age = age; }
}

文件: simple_esper.xml

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:json="http://www.mulesoft.org/schema/mule/json"
    xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:esper="http://www.mulesoft.org/schema/mule/esper" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
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/esper http://www.mulesoft.org/schema/mule/esper/1.0/mule-esper.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">

   <esper:config name="Esper" configuration="esper-config.xml" doc:name="Esper"/>


   <flow name="Esper_saving_people" doc:name="Esper_saving_people">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        <scripting:component doc:name="People creation">
            <scripting:script engine="Groovy"><![CDATA[def persons=[];
persons.add(new org.mule.Person("mule", 23));
persons.add(new org.mule.Person("ESB", 42));
persons.add(new org.mule.Person("mule", 42));
return persons;]]></scripting:script>
        </scripting:component>
        <foreach doc:name="Iteragint over people">
            <esper:send config-ref="Esper" eventPayload-ref="#[payload]" eventName="people" doc:name="Esper"/>
        </foreach>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>

    <flow name="Esper_amount_of_people" doc:name="Esper_amount_of_people">
        <esper:listen config-ref="Esper" statement="select count(*) from Person" doc:name="Esper (Streaming)"/>
        <logger message="Esper, amount of people: #[payload]" level="INFO"    doc:name="Logger"/>
    </flow> 

    <flow name="Esper_average_age" doc:name="Esper_other_listen">
        <esper:listen config-ref="Esper" statement="select avg(age) from Person " doc:name="Esper (Streaming)"/>
        <logger message="Esper, average age: #[payload]" level="INFO"    doc:name="Logger"/>
    </flow> 

</mule>

干杯, 劳塔罗