pathikrit
pathikrit

Reputation: 33409

Play WS Exception: java.lang.IllegalArgumentException: name contains one of the following prohibited characters: =,;: \t\r\n\v\f: Agent,

I am on Play 2.2.x and I have the following snippet of code:

def call(server: String, api: String) = {
  import play.api.libs.ws._
  import scala.concurrent.Await
  import scala.concurrent.duration._
  val request = WS.url(server + api)
  Await.result(request.get(), 1 minute)
}

I am getting this error:

java.lang.IllegalArgumentException: name contains one of the following prohibited characters: =,;: \t\r\n\v\f: Agent,
        at org.jboss.netty.handler.codec.http.HttpCodecUtil.validateHeaderName(HttpCodecUtil.java:38)
        at org.jboss.netty.handler.codec.http.HttpHeaders.validateHeaderName(HttpHeaders.java:834)
        at org.jboss.netty.handler.codec.http.HttpHeaders.addHeader(HttpHeaders.java:838)
        at org.jboss.netty.handler.codec.http.DefaultHttpMessage.addHeader(DefaultHttpMessage.java:44)
        at org.jboss.netty.handler.codec.http.HttpMessageDecoder.readHeaders(HttpMessageDecoder.java:496)
        at org.jboss.netty.handler.codec.http.HttpMessageDecoder.decode(HttpMessageDecoder.java:193)
        at org.jboss.netty.handler.codec.http.HttpClientCodec$Decoder.decode(HttpClientCodec.java:143)
        at org.jboss.netty.handler.codec.http.HttpClientCodec$Decoder.decode(HttpClientCodec.java:127)
        at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:500)
        at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435)
        at org.jboss.netty.handler.codec.http.HttpClientCodec.handleUpstream(HttpClientCodec.java:92)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
        at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:109)
        at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:90)
        at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

What am I doing wrong? The server + api does not have any special characters whatsoever.

Also not sure why this is so verbose to do in Scala - why does the API require me to import 3 things to make a simple GET call...

EDIT: Verified this happens when server is https://example.com but not when it is http: http://example.com

Upvotes: 2

Views: 1853

Answers (1)

Tair
Tair

Reputation: 3809

The stacktrace indicates that your server (example.com) is responding with illegal HTTP headers. Namely, it sends back Agent, as a header name. Notice the comma in the text.

As to the question of why it is so verbose in scala -- the problem of your code is that it is trying to fit the asynchronous nature of play-framework's web-service API to synchronous call function. This is not how you usually work with Scala's Future api.

Upvotes: 1

Related Questions