user-agent
ヘッダーを抽出し、抽出されたユーザー エージェントに基づいてステータス コードを返す REST コンポーネントに渡す単純なミュール フローを作成しようとしています。
これが私のラバの流れです
<flow name="restflowFlow1" doc:name="restflowFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9595" path="rest" doc:name="HTTP"/>
<jersey:resources doc:name="REST">
<component class="com.test.RestClass"/>
</jersey:resources>
</flow>
そして、これが対応するクラスです
@Path("restClass")
public class RestClass implements Callable {
public Response getExample(String toBeValidated)
{
if(toBeValidated.contains("Apple"))
{
return Response.status(Status.OK).entity("hello " + toBeValidated).build();
}
return Response.status(Status.UNAUTHORIZED).entity("hello " + toBeValidated).build();
}
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
String requiredHeader= eventContext.getMessage().getProperty("user-agent", PropertyScope.INBOUND);
return getExample(requiredHeader);
}
}
上記のフローを実行しようとすると、次のエラーが発生します。
ERROR 2014-11-21 13:49:47,909 [[muletestproject].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to invoke JerseyResourcesComponent{restflowFlow1.component.418586223}. Component that caused exception is: JerseyResourcesComponent{restflowFlow1.component.418586223}. Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. String index out of range: -1 (java.lang.StringIndexOutOfBoundsException)
java.lang.String:1875 (null)
2. Failed to invoke JerseyResourcesComponent{restflowFlow1.component.418586223}. Component that caused exception is: JerseyResourcesComponent{restflowFlow1.component.418586223}. Message payload is of type: String (org.mule.component.ComponentException)
org.mule.component.AbstractComponent:144 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1875)
PS Im はラバにはまったく新しいものです。したがって、私は他のエレガントなアプローチにもオープンです。