Created
January 31, 2018 13:35
-
-
Save mattisebastian/44c402136e4c37e8be45ae993ff195e2 to your computer and use it in GitHub Desktop.
How to extract json in groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The integration developer needs to create the method processData | |
* This method takes Message object of package com.sap.gateway.ip.core.customdev.util | |
* which includes helper methods useful for the content developer: | |
* | |
* The methods available are: | |
public java.lang.Object getBody() | |
//This method helps User to retrieve message body as specific type ( InputStream , String , byte[] ) - e.g. message.getBody(java.io.InputStream) | |
public java.lang.Object getBody(java.lang.String fullyQualifiedClassName) | |
public void setBody(java.lang.Object exchangeBody) | |
public java.util.Map<java.lang.String,java.lang.Object> getHeaders() | |
public void setHeaders(java.util.Map<java.lang.String,java.lang.Object> exchangeHeaders) | |
public void setHeader(java.lang.String name, java.lang.Object value) | |
public java.util.Map<java.lang.String,java.lang.Object> getProperties() | |
public void setProperties(java.util.Map<java.lang.String,java.lang.Object> exchangeProperties) | |
public void setProperty(java.lang.String name, java.lang.Object value) | |
* | |
*/ | |
import com.sap.gateway.ip.core.customdev.util.Message; | |
import groovy.json.*; | |
import java.lang.String; | |
def Message processData(Message message) { | |
def body = message.getBody(java.lang.String) as String; | |
def jsonSlurper = new JsonSlurper(); | |
def jsonDataObject = jsonSlurper.parseText(body); | |
//message.setBody(body + "Body is modified"); | |
//Headers | |
//def map = message.getHeaders(); | |
//def value = map.get("oldHeader"); | |
//message.setHeader("oldHeader", value + "modified"); | |
//message.setHeader("Authorization", "newHeader"); | |
//message.setHeader("newHeader", "newHeader"); | |
//Properties | |
//map = message.getProperties(); | |
//value = map.get("oldProperty"); | |
//message.setProperty("oldProperty", value + "modified"); | |
//message.setProperty("newProperty", "newProperty"); | |
message.setBody(new JsonBuilder(jsonDataObject.args.test).toPrettyString()) | |
return message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment