sarah w
sarah w

Reputation: 3475

playframework-2.6: not enough arguments for method apply:

I am using Play-Framework-2.6 i am getting this error /myproject/app/controllers/Application.scala:151: not enough

arguments for method apply: (data: akka.stream.scaladsl.Source[akka.util.ByteString, _], contentLength: Option[Long], contentType: Option[String])play.api.http.HttpEntity.Streamed in object Streamed.
[error] Unspecified value parameters contentLength, contentType.
[error]         body = HttpEntity.Streamed(responseStream)
[error]                                   ^

here is my code

def prometheusMetrics = Action {
    val responseStream = Concurrent.unicast[Array[Byte]] { channel =>
      val writer = new WriterAdapter(channel)
      TextFormat.write004(writer, CollectorRegistry.defaultRegistry.metricFamilySamples())
      writer.close()
    }
    Result(
     header = ResponseHeader(200, Map.empty),
        body = HttpEntity.Streamed(responseStream)
  ).as(TextFormat.CONTENT_TYPE_004)
  }

i researched this but i did not find any suitable solution for it .please guide me

Update # 1 answer given by user @James Whiteley after doing this

Result(
     header = ResponseHeader(200, Map.empty),
        body = HttpEntity.Streamed(responseStream, None, None)
  ).as(TextFormat.CONTENT_TYPE_004)

i am getting

type mismatch;
[error]  found   : play.api.libs.iteratee.Enumerator[Array[Byte]]{implicit val pec: scala.concurrent.ExecutionContext}
[error]  required: akka.stream.scaladsl.Source[akka.util.ByteString, _]
[error]         body = HttpEntity.Streamed(responseStream, None, None)

Upvotes: 0

Views: 1206

Answers (1)

James Whiteley
James Whiteley

Reputation: 3468

HttpEntity.Streamed seems to take three parameters, not one. Try

body = HttpEntity.Streamed(responseStream, None, None)

if you don't want to specify contentLength and contentType - these are optional parameters but still need to be defined.

Upvotes: 1

Related Questions