Retrofit 2 error - End of input at line 1 column 1 path $ - retrofit2

Im using Retrofit 2 with RxJava -
#retrofit2.http.Multipart
#retrofit2.http.POST(APIEndPoint.BATCHES)
fun submitGenericMultiPart(#retrofit2.http.Part("data") batchRequests: RequestBody, #retrofit2.http.Part("identifier") multipartTypedOutput: MultipartBody): Single<Array<BatchRequestResponse>>
mDataManager.submitGenericMultiPart(body, files)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : SingleObserver<Array<BatchRequestResponse>> {
override fun onSubscribe(d: Disposable) {
if(d!=null) compositeDisposable.add(d)
}
override fun onSuccess(it: Array<BatchRequestResponse>) {
// success block
}
override fun onError(e: Throwable) {
// error block
}
})
Is there any error in the way I have declared the data types handling it in RxJava because every time, I get the error - End of input at line 1 column 1 path $

Cause: data response is empty, you can add NullOnEmptyConverterFactory to handle when the data response is empty.
Issue: https://github.com/square/retrofit/issues/1968
Solution: https://github.com/square/retrofit/issues/1554

Related

Kotlin unresolved reference when using mutlithreading

So I'm trying to use kotlin together with selenium and threading, but one parameter doesnt work. Here's my code:
class myClass(parameter1 : String, parameter2 : String, parameter3 : Int) : Thread(){
init{
var driver : ChromeDriver = ChromeDriver()
}
override fun run() {
driver.get("somewebsite")
var id_field = driver.findElementByName("iD")
id_field.sendKeys(parameter1)
id_field.submit()
name = parameter2 + parameter3.toString()
//At this Point, Intellij Idea tells me: Unresolved reference: parameter3
name_field = driver.findElementByName("name")
name_field.sendKeys(name)
name_field.submit()
}
}
fun main() {
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver")
val threads: Array<myClass> = Array(2) { myClass("some_id", "name", it)}
}
What should happen is that the script goes to my website, enters the name and iD. But I want to be able to run mutiple threads of my script where the threads "iteration" (which is parameter 3) is being added to my name.
So for example:
- thread 1 logs in with: name1
- thread 2 logs in with: name2
(...)
- thread 20 logs in with: name20
But my question is:
Why doesnt kotlin say: Unsolved reference: parameter 3?

Using find{ } on a map where the whole map is evaluated not each element

I created some mixin methods. Code and example below:
URL.metaClass.withCreds = { u, p ->
delegate.openConnection().tap {
setRequestProperty('Authorization', "Basic ${(u + ':' + p).bytes.encodeBase64()}")
}
}
URLConnection.metaClass.fetchJson = {
delegate.setRequestProperty('Accept', 'application/json')
delegate.connect()
def code = delegate.responseCode
def result = new JsonSlurper().parse(code >= 400 ? delegate.errorStream : delegate.inputStream as InputStream)
[
ok : code in (200..299),
body: result,
code: code
]
}
example usage:
new URL("$baseUrl/projects/$name").withCreds(u, p).fetchJson().find {
it.ok
}?.tap{
it.repos = getRepos(it.key).collectEntries { [(it.slug): it] }
}
}
When I dont use find(), my object is, as expected, a map with those 3 elements. When I use find it is a Map.Entry with key ok and value true
which produces this error:
groovy.lang.MissingPropertyException: No such property: ok for class: java.util.LinkedHashMap$Entry
Possible solutions: key
It occured to me when I wrote this post that it was treated the map as an iterable and thus looking at every entry which I have subsequently verified. How do I find on the whole map? I want it.ok because if it's true, I need to carry it forward
There is no such method in Groovy SDK. Map.find() runs over an entry set of the map you call method on. Based on expectation you have defined I'm guessing you are looking for a function that tests map with a given predicate and returns the map if it matches the predicate. You may add a function that does to through Map.metaClass (since you already add methods to URL and URLConnection classes). Consider following example:
Map.metaClass.continueIf = { Closure<Boolean> predicate ->
predicate(delegate) ? delegate : null
}
def map = [
ok : true,
body: '{"message": "ok"}',
code: 200
]
map.continueIf { it.ok }?.tap {
it.repos = "something"
}
println map
In this example we introduced a new method Map.continueIf(predicate) that tests if map matches given predicate and returns a null otherwise. Running above example produces following output:
[ok:true, body:{"message": "ok"}, code:200, repos:something]
If predicate is not met, map does not get modified.
Alternatively, for more strict design, you could make fetchJson() method returning an object with corresponding onSuccess() and onError() methods so you can express more clearly that you add repos when you get a successful response and optionally you create an error response otherwise.
I hope it helps.

kotlin fuel gson Error BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

Response from api. How to get data from this result. Use Fuel connect api
Error :
BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
I don't understand it
{
"data": {
"translations": [
{
"translatedText": "คุณชอ`enter code here`บฉันไหม คุณชอบใคร? ถึง 12 ML 2. 19. 9. 19 ROADSHOW kiele หัวเราะและร้องไห้และร้องไห้ผิวรักเป็นประวัติการณ์เกิด",
"detectedSourceLanguage": "ja"
}
]
}
}
class Textmodel {
#SerializedName("translations")
#Expose
var translation: List<MessageResult>? = null
class MessageResult {
#SerializedName("translatedText")
#Expose
var message: String? = null
#SerializedName("detectedSourceLanguage")
#Expose
var originalLanguage: String? = null
constructor(message: String?, originalLanguage: String?) {
this.message = message
this.originalLanguage = originalLanguage
}
}
class ListDeserializer : ResponseDeserializable<List<Textmodel>> {
override fun deserialize(content: String) =
Gson().fromJson<List<Textmodel>>(content,object :TypeToken<List<Textmodel>>(){}.type)
}
I want to get data form this object.
Thank you
This error means that your parsing code was expecting to find a BEGIN_ARRAY delimiter ([), but it found a BEGIN_OBJECT delimiter ({) instead. Essentially, your objects that GSON is attempting to parse are expecting an array in a place where the JSON input is providing on object.
It's a little bit tough to debug with just a small snippet of code, but you want to make sure that the object models you are providing to GSON for deserialization are able to parse the JSON input from the root down to the data you're interested in accessing. My hunch is that you're missing the part that parses the "data" object.

What does the word "loop" mean in Actor example of GPars?

In the following HelloWorld GPars example we have the word loop:
def decryptor = actor {
loop {
react { message ->
if (message instanceof String) reply message.reverse()
else stop()
}
}
}
def console = actor {
decryptor.send 'lellarap si yvoorG'
react {
println 'Decrypted message: ' + it
decryptor.send false
}
}
[decryptor, console]*.join()
How to be definitely sure, what is it? If I Ctrl click it in IntelliJ I get nothing. Simultaneously, if I Ctrl click the work react, go to the method react in GPars.
It also has loop methods. But neither has single Closure as argument.
Can I be sure, that some of loop methods are called here?

How can I retrieve the build parameters from a queued job?

I would like to write a system groovy script which inspects the queued jobs in Jenkins, and extracts the build parameters (and build cause as a bonus) supplied as the job was scheduled. Ideas?
Specifically:
def q = Jenkins.instance.queue
q.items.each { println it.task.name }
retrieves the queued items. I can't for the life of me figure out where the build parameters live.
The closest I am getting is this:
def q = Jenkins.instance.queue
q.items.each {
println("${it.task.name}:")
it.task.properties.each { key, val ->
println(" ${key}=${val}")
}
}
This gets me this:
4.1.next-build-launcher:
com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty$ScannerJobPropertyDescriptor#b299407=com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty#5e04bfd7
com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty$DescriptorImpl#40d04eaa=com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty#16b308db
hudson.model.ParametersDefinitionProperty$DescriptorImpl#b744c43=hudson.mod el.ParametersDefinitionProperty#440a6d81
...
The params property of the queue element itself contains a string with the parameters in a property file format -- key=value with multiple parameters separated by newlines.
def q = Jenkins.instance.queue
q.items.each {
println("${it.task.name}:")
println("Parameters: ${it.params}")
}
yields:
dbacher params:
Parameters:
MyParameter=Hello world
BoolParameter=true
I'm no Groovy expert, but when exploring the Jenkins scripting interface, I've found the following functions to be very helpful:
def showProps(inst, prefix="Properties:") {
println prefix
for (prop in inst.properties) {
def pc = ""
if (prop.value != null) {
pc = prop.value.class
}
println(" $prop.key : $prop.value ($pc)")
}
}
def showMethods(inst, prefix="Methods:") {
println prefix
inst.metaClass.methods.name.unique().each {
println " $it"
}
}
The showProps function reveals that the queue element has another property named causes that you'll need to do some more decoding on:
causes : [hudson.model.Cause$UserIdCause#56af8f1c] (class java.util.Collections$UnmodifiableRandomAccessList)

Resources