java 2.1中的java.util.concurrent.TimeoutException

时间:2015-10-12 08:22:15

标签: scala rest playframework

    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")

      }
    }
    }

此代码适用于一个rest api但是当我调用另一个webservice时,我收到此错误堆栈跟踪:

[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]

我的播放版:2.1.5 我的scala:2.10.4

我在调用Web服务时遇到异常错误,而对于另一个Web服务,它正常工作,而我正在调用另一个Web服务时遇到此错误,有人可以告诉我我可以做些什么来解决此问题。 或者有人可以告诉我如何在游戏中增加响应时间2.1.5

0 个答案:

没有答案