Я создаю HTTP-пост для регистрации источника данных в каталоге данных Azure. Код генерирует исключение с кодом ошибки 400.
Для устранения этой проблемы я использовал вывод Json из кода Scala (новый Gson (). ToJson (payLoad)) в Python и смог успешно зарегистрировать источник данных. Я не уверен, что не так с кодом Scala. Может кто-нибудь, пожалуйста, помогите мне?
/*payload Json
"""{
"properties": {
"name": "Test",
"dsl": {
"address": {
"domain": "some.domain.net",
"account": "storageaccountname",
"container": "testcontainer",
"name": "Test"
},
"protocol": "azure-blobs",
"authentication": "azure-access-key"
},
"dataSource": {
"sourceType": "Azure Storage",
"objectType": "Blob"
},
"lastRegisteredBy": {
"upn": "someupn"
},
"fromSourceSystem": "true",
"containerId": someId"
}
}"""*/
import org.apache.http.HttpResponse
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.HttpPost
import java.util.ArrayList
import org.apache.http.message.BasicNameValuePair
import org.apache.http.client.entity.UrlEncodedFormEntity
import com.google.gson.Gson
case class Address (domain: String, account: String, container: String, name: String)
case class Dsl (address: Address, protocol: String, authentication: String)
case class DataSource(sourceType: String, objectType: String)
case class LastRegisteredBy(upn: String)
case class Properties(name: String, dsl: Dsl, dataSource: DataSource, lastRegisteredBy: LastRegisteredBy, fromSourceSystem: String, containerId: String)
case class PayLoad (properties: Properties)
val sourceAddress = Address("some.domain.net","storageaccountname","testcontainer", "Test")
val dataSourceLocation = Dsl(sourceAddress,"azure-blobs", "azure-access-key")
val dataSource = DataSource( "Azure Storage" , "Blob" )
val lastRegisteredBy = LastRegisteredBy("someupn")
val properties = Properties("Test",dataSourceLocation,dataSource,lastRegisteredBy, "true","someId")
val payLoad= PayLoad(properties)
val payLoadJson = new Gson().toJson(payLoad)
val nameValuePairs = new ArrayList[NameValuePair]()
nameValuePairs.add(new BasicNameValuePair("JSON", payLoadJson))
/* Setting up url etc.. */
val requestUrl = "someurl"
val client = HttpClientBuilder.create().build()
val post = new HttpPost(requestUrl)
post.setHeader("Content-Type", "application/json")
post.setHeader("Accept", "application/json")
post.setEntity(new UrlEncodedFormEntity(nameValuePairs))
val response = (client.execute(post))