import play.api._
import play.api.libs.ws._
import play.api.mvc._
//import javax.inject.Inject
import play.api.Play.current
import scala.concurrent.ExecutionContext.Implicits.global
import play.api.libs.ws.WSAuthScheme
import com.ning.http.client.AsyncHttpClient
import com.ning.http.client.multipart.FilePart
import com.ning.http.client.multipart.StringPart
import java.io.File
import org.apache.commons.codec.binary.Base64.encodeBase64
class Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
def postUpload=Action(parse.multipartFormData){request=>
val groupingType= request.body.dataParts("Grouping type").mkString
val email=request.body.dataParts("NotificationRecepients").mkString
val custId=request.body.dataParts("CustomerId").mkString
val custIdFinal:Int=custId.toInt
request.body.file("file").map { file =>
val file1=file.ref.file.getAbsolutePath;
val fileName = file.filename
val contentType = file.contentType
//file.ref.moveTo(new File("/home/kanchan/Desktop/"+fileName),true)
val url="myUrl";
val user = "myUser";
val password = "myPassword";
val encodedCredentials =
new String(encodeBase64("%s:%s".format(user, password).getBytes))
val asyncHttpClient:AsyncHttpClient =WS.client.underlying
val postBuilder = asyncHttpClient.preparePost(url)
val builder = postBuilder
.addHeader("Authorization", "Basic " + encodedCredentials)
.addBodyPart(new StringPart("selectedGroupType", "Functional Grouping", "UTF-8"))
.addBodyPart(new StringPart("mailRecipients", "kancgupt@cisco.com", "UTF-8"))
.addBodyPart(new StringPart("selectedFile", "Sample_group_upload_file.xlsx", "UTF-8"))
.addBodyPart(new FilePart("file",new File("/home/kanchan/Downloads/Sample_group_upload_file.xlsx")))
val response = asyncHttpClient.executeRequest(builder.build()).get();
Ok(response.getResponseBody)
}.getOrElse {
Ok( "Missing file")
}
}
}
This code is working for one rest api but when I am calling another webservice I am getting this error stack trace:
[error] play - Cannot invoke the action, eventually got an error: java.util.conc
urrent.ExecutionException: java.util.concurrent.TimeoutException: No response re
ceived after 120000
[error] application -
! @6nmc6dl9k - Internal server error, for (POST) [/uploads] ->
play.api.Application$$anon$1: Execution exception[[ExecutionException: java.util
.concurrent.TimeoutException: No response received after 120000]]
at play.api.Application$class.handleError(Application.scala:287) ~[play_
2.10.jar:2.1.5]
at play.api.DefaultApplication.handleError(Application.scala:381) [play_
2.10.jar:2.1.5]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleActi
on$1$2$$anonfun$apply$21.apply(PlayDefaultUpstreamHandler.scala:413) [play_2.10.
jar:2.1.5]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleActi
on$1$2$$anonfun$apply$21.apply(PlayDefaultUpstreamHandler.scala:413) [play_2.10.
jar:2.1.5]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleActi
on$1$2.apply(PlayDefaultUpstreamHandler.scala:413) [play_2.10.jar:2.1.5]
java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException:
No response received after 120000
at com.ning.http.client.providers.netty.NettyResponseFuture.get(NettyRes
ponseFuture.java:223) ~[async-http-client.jar:na]
at com.ning.http.client.providers.netty.NettyResponseFuture.get(NettyRes
ponseFuture.java:187) ~[async-http-client.jar:na]
at controllers.Application$$anonfun$postUpload$1$$anonfun$apply$2.apply(
Application.scala:123) ~[na:na]
at controllers.Application$$anonfun$postUpload$1$$anonfun$apply$2.apply(
Application.scala:88) ~[na:na]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at controllers.Application$$anonfun$postUpload$1.apply(Application.scala
:88) ~[na:na]
Caused by: java.util.concurrent.TimeoutException: No response received after 120
000
at com.ning.http.client.providers.netty.NettyResponseFuture.get(NettyRes
ponseFuture.java:215) ~[async-http-client.jar:na]
at com.ning.http.client.providers.netty.NettyResponseFuture.get(NettyRes
ponseFuture.java:187) ~[async-http-client.jar:na]
at controllers.Application$$anonfun$postUpload$1$$anonfun$apply$2.apply(
Application.scala:123) ~[na:na]
at controllers.Application$$anonfun$postUpload$1$$anonfun$apply$2.apply(
Application.scala:88) ~[na:na]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at controllers.Application$$anonfun$postUpload$1.apply(Application.scala
:88) ~[na:na]
my play version :2.1.5 my scala:2.10.4
I am getting error of time out exception while I am calling web service while for another web service it is working fine while I am calling another web service getting this error can someone tell me what I can do for resolving this issue. or can some one tell me how can I increase time out for response in play 2.1.5