on ‎2022 Mar 03 8:49 AM
Hi,
I have seen some blog post where people are using java.io.Reader in Groovy to read the body content. For example:
def body = message.getBody(java.io.Reader)<br>body.eachLine { line -><br> .... Some code here <br>}
But then if I try the same code, I get the following error message:
javax.script.ScriptException: java.lang.Exception: java.lang.NullPointerException: Cannot invoke method eachLine() on null object@ line 26 in script1.groovy, cause: java.lang.NullPointerException: Cannot invoke method eachLine() on null object
Is there something that I missed?
EDIT: I realized it is error if I used conversion XML to CSV before the script step. If I remove the conversion step this error does not occur.
Thank you.
Request clarification before answering.
Can you please give us the groovy code you used and input payload you sent?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is the groovy script:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Body
def objReader = message.getBody(java.io.Reader);
def array = []
objReader.eachLine { String line ->
array.add(line)
}
return message;
}<br>And this is the input payload:
"0047224526,449 ,0006429 ,LIV ,20210429092751"
"0047241670,449 ,0006429 ,LIV ,20210420092958"
"0047242774,437 ,0006429 ,LIV ,20210429101150"
"0047244164,321 ,0006429 ,LIV ,20210420093320" <br>Error is at line 26: objReader.eachLine { String line ->
I realized it is error if I used conversion XML to CSV before the script step. If I remove the conversion step this error does not occur.
Thank you.
Well. I have tried to run the code with given input. I dont see issue with this.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Body
def objReader = message.getBody(java.io.Reader);
def array = []
objReader.eachLine { String line ->
array.add(line)
}
return message;
}
input
"0047224526,449 ,0006429 ,LIV ,20210429092751"
"0047241670,449 ,0006429 ,LIV ,20210420092958"
"0047242774,437 ,0006429 ,LIV ,20210429101150"
"0047244164,321 ,0006429 ,LIV ,20210420093320" <br>
| User | Count |
|---|---|
| 12 | |
| 9 | |
| 7 | |
| 5 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.