aws / aws-sdk-java

The official AWS SDK for Java 1.x (In Maintenance Mode, End-of-Life on 12/31/2025). The AWS SDK for Java 2.x is available here: https://github.com/aws/aws-sdk-java-v2/
https://aws.amazon.com/sdkforjava
Apache License 2.0
4.13k stars 2.83k forks source link

SDK 1.11.96 sends empty Content-Type causing Internal Server Error #1035

Closed unoexperto closed 7 years ago

unoexperto commented 7 years ago

Gentelmen, this is quite urgent issue. I hope you respond soon.

I just switched from 1.10.52 to 1.11.96 (no code changes in my code) and all requests to AWS API fail now.

After some debugging I identified that empty (but not missing) Content-Type http header is sent to API server which causes server to return Internal Server Error.

What should I do ?

Here is snippet of my code

      val json = items.toJson.prettyPrint
      val bytes = json.getBytes("UTF-8")
      val contentLength = bytes.length.toLong
      val req = new UploadDocumentsRequest().
        withContentType(ContentType.Applicationjson).
        withDocuments(new ByteArrayInputStream(bytes)).
        withContentLength(contentLength)

      cloudSearchDomain.uploadDocuments(req).getAdds

I'm still debugging it but it looks like problem lies in class UploadDocumentsRequestProtocolMarshaller. Variable initialized in line

final ProtocolRequestMarshaller<UploadDocumentsRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    uploadDocumentsRequest);

has protocolMarshaller.delegate.contentType with empty String.

Here is how client is initalized

  private val cloudSearchDomain = new AmazonCloudSearchDomainClient(new BasicAWSCredentials(awsAccessKey, awsSecretKey))
  cloudSearchDomain.setRegion(aws_region)
  cloudSearchDomain.setEndpoint(conf.getString("aws_cloudsearch_doc_endpoint"))

in case you need to see my dependencies here they are

      libraryDependencies ++= {
        val akkaV = "2.4.17"
        val scalaTestV = "3.0.0"
        val scalaLoggingV = "3.5.0"
        val doobieV = "0.4.1"
        Seq(
          "org.tpolecat" %% "doobie-core-cats" % doobieV withSources(),
          "org.tpolecat" %% "doobie-postgres-cats" % doobieV withSources(),
          "org.tpolecat" %% "doobie-hikari-cats" % doobieV withSources(),

          "com.typesafe.akka" %% "akka-actor" % akkaV withSources(),
          "com.typesafe.akka" %% "akka-stream" % akkaV withSources(),

          "com.typesafe.akka" %% "akka-slf4j" % akkaV withSources(),

          "org.scala-lang.modules" %% "scala-async" % "0.9.6",

          "com.chuusai" %% "shapeless" % "2.3.1",

          "io.kamon" %% "kamon-core" % "0.6.0",
          "io.kamon" %% "kamon-statsd" % "0.6.3",
          "io.kamon" %% "kamon-system-metrics" % "0.6.3",
          "io.kamon" %% "kamon-autoweave" % "0.6.3",
          "io.kamon" %% "kamon-akka" % "0.6.3",
          "io.kamon" %% "kamon-jdbc" % "0.6.3",

          "com.github.etaty" %% "rediscala" % "1.8.0",

          "com.esotericsoftware" % "kryo" % "4.0.0" withSources(),
          "org.scodec" %% "scodec-core" % "1.10.3",
          "org.scodec" %% "scodec-bits" % "1.1.2",

          "net.sf.saxon" % "Saxon-HE" % "9.6.0-7",

          "io.scalac" %% "reactive-rabbit" % "1.1.4",

          "org.reflections" % "reflections" % "0.9.10" withSources(),
          "com.amazonaws" % "aws-java-sdk" % "1.11.96",
          "com.twilio.sdk" % "twilio-java-sdk" % "6.3.0" withSources(),

          "io.spray" %%  "spray-json" % "1.3.3",
          "org.scala-lang.modules" %% "scala-xml" % "1.0.6",

          "joda-time" % "joda-time" % "2.9.6" % "provided",

          "org.jasypt" % "jasypt" % "1.9.2" withSources(),

          "org.scalatest"     %% "scalatest"                          % scalaTestV % "test",
          "com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingV,
          "ch.qos.logback" % "logback-classic" % "1.1.+"
        )
      },

Thoughts ?

unoexperto commented 7 years ago

And looks like marshaller set correct Content-Type but it gets overwritten at the end in

            return protocolMarshaller.finishMarshalling();
kiiadi commented 7 years ago

A fix to the content-type bug was released in 1.11.97, the problem should be resolved by upgrading to the latest version.

unoexperto commented 7 years ago

Yep, it helped. Thanks!