フォームで構成されるHTMLファイルがあり、ユーザーから特定のパラメーターを受け取り、URLがヒットすると、Muleサービス(Javaで記述)が呼び出され、JSON文字列が返されます。では、MuleまたはJavaのいずれかでContent-type
=を設定して、ブラウザーがJSONを取得していることを認識できるようにするにはどうすればよいですか?application/json
私のMule設定ファイルは:
<custom-transformer name="HttpParams" class="org.mule.transport.http.transformers.HttpRequestBodyToParamMap" />
<message-properties-transformer name="HttpResponse">
<add-message-property key="Content-Type" value="application/json" />
<add-message-property key="http.status" value="303" />
</message-properties-transformer>
<flow name="jcars">
<http:inbound-endpoint address="http://localhost:11221/jcars" transformer-refs="HttpParams" responseTransformer-refs="HttpResponse">
<not-filter>
<wildcard-filter pattern="/favicon.ico"/>
</not-filter>
</http:inbound-endpoint>
<component class="defaults.basicapp.jcars"/>
</flow>
そして私のJavaクラスは(Jcars)です:
public String onEvent(Object obj){
String json = "{{"id":0,"model":"suzuki","make":"2002","ps":true,"price":101.2,"bhp":12.6},{"id":0,"model":"suzuki","make":"2003","ps":true,"price":101.2,"bhp":12.6},{"id":0,"model":"suzuki","make":"2004","ps":true,"price":101.2,"bhp":12.6},{"id":0,"model":"suzuki","make":"2005","ps":true,"price":101.2,"bhp":12.6},{"id":0,"model":"suzuki","make":"2006","ps":true,"price":101.2,"bhp":12.6}}";
return json;
}
ブラウザは文字列をそのまま表示しています。コンテンツタイプがであるかどうかはわかりませんapplication/json
。私は何をすべきか?