Sample endpoint : http://localhost:9003/mas/v1/events?ids=["e1","e2","e3"]
我正在尝试将查询参数映射到字符串[], 以下是完成的服务呼叫和休息呼叫映射
//Mapping the query parameter to array of string
ServiceCall<NotUsed, String> getEvents(String[] ids);
restCall(Method.GET, "/mas/v1/events?ids", this::getEvents);
当我尝试将查询参数映射到 te String[] 时,我得到以下结果
Caused by: java.lang.IllegalStateException: Unable to resolve method for service call with ID RestCallId{method=GET, pathPattern='/mas/v1/events?ids'}. Ensure that the you have passed a method reference (ie, this::someMethod). Passing anything else, for example lambdas, anonymous classes or actual implementation classes, is forbidden in declaring a service descriptor.
at com.lightbend.lagom.internal.javadsl.api.ServiceReader$$anonfun$4.apply(ServiceReader.scala:103)
at com.lightbend.lagom.internal.javadsl.api.ServiceReader$$anonfun$4.apply(ServiceReader.scala:88)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.Iterator$class.foreach(Iterator.scala:893)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at com.lightbend.lagom.internal.javadsl.api.ServiceReader$.resolveServiceDescriptor(ServiceReader.scala:88)
at com.lightbend.lagom.internal.javadsl.server.JavadslServerBuilder.resolveDescriptor(JavadslServerBuilder.scala:66)
at com.lightbend.lagom.internal.javadsl.server.JavadslServerBuilder$$anonfun$1.apply(JavadslServerBuilder.scala:55)
at com.lightbend.lagom.internal.javadsl.server.JavadslServerBuilder$$anonfun$1.apply(JavadslServerBuilder.scala:49)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at com.lightbend.lagom.internal.javadsl.server.JavadslServerBuilder.resolveServices(JavadslServerBuilder.scala:49)
at
Caused by: java.lang.ClassNotFoundException: [Ljava/lang/String
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.lightbend.lagom.internal.javadsl.api.MethodRefResolver$.loadClass(MethodRefResolver.scala:58)
at com.lightbend.lagom.internal.javadsl.api.MethodRefResolver$.parseArgumentClasses$1(MethodRefResolver.scala:73)
at com.lightbend.lagom.internal.javadsl.api.MethodRefResolver$.getArgumentClasses(MethodRefResolver.scala:95)
at com.lightbend.lagom.internal.javadsl.api.MethodRefResolver$.resolveMethodRef(MethodRefResolver.scala:49)
at com.lightbend.lagom.internal.javadsl.api.ServiceReader$$anonfun$4.apply(ServiceReader.scala:100)
... 66 more
您可以简单地将ids
参数设为String
。
因此,您的服务调用和休息调用映射将如下所示。
ServiceCall<NotUsed, String> getEvents(String ids);
restCall(Method.GET, "/mas/v1/events?ids", this::getEvents);
因此,示例终结点将如下所示。
Sample endpoint : http://localhost:9003/mas/v1/events?ids=e1,e2,e3
然后使用 String.split(regex)
方法将String
Ids
转换为服务调用实现方法中的数组。
@Override
public ServiceCall<NotUsed, String> getEvents(String ids) {
String[] idsArray = ids.split(",");
return request -> CompletableFuture.completedFuture("");
}