Blog Archive

Saturday, July 1, 2017

My custom groovy script for my reference

/*
 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()
    public void setBody(java.lang.Object exchangeBody)
    public java.util.Map getHeaders()
    public void setHeaders(java.util.Map exchangeHeaders)
    public void setHeader(java.lang.String name, java.lang.Object value)
    public java.util.Map getProperties()
    public void setProperties(java.util.Map exchangeProperties)
       public void setProperty(java.lang.String name, java.lang.Object value)
 */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.StreamingMarkupBuilder;
import groovy.xml.*;
def Message processData(Message message) {
    //Body
def body = message.getBody(java.lang.String);
//def body1 =message.getBody(java.lang.String) as byte[];
def input_xml=body.replace("NewElement1","NewElement2");
                       def xml2 =""+body.substring(10,11)+"";



//message log
 def messageLog = messageLogFactory.getMessageLog(message);
    if(messageLog != null){
        messageLog.setStringProperty("Logging#1", body.toString());
messageLog.setStringProperty("Logging#2", input_xml);

     //   messageLog.addAttachmentAsString("ResponsePayload:", body, "text/plain");
     }


//def root = new XmlSlurper().parseText(body); // change1
def root = new XmlParser().parseText(body); //change2

root.NewElement[0].value= "mychange"; // chnage2
/* change1

  def outputBuilder = new StreamingMarkupBuilder()

def axml = '''
 
  ABC
  123
  XXX
  567890
 
'''
def root1=new XmlSlurper().parseText(axml);

  outputBuilder.encoding = "UTF-8"

  def outxml = {

  mkp.declareNamespace('ns0':'http://xiTest.com/xi/COD')

  ns0.Target{
mkp.yield root.children()
mkp.yield root1.children()


  }

  }

  String result = outputBuilder.bind(outxml)



  message.setBody(result);
*/
//message.setBody(XmlUtil.serialize(root));
message.setBody(input_xml+xml2);

       return message


}

No comments:

Post a Comment