Skip to content

gyotro/MessageHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAP Cloud Integration Utility Library

A comprehensive utility library for SAP Cloud Platform Integration (CPI) that simplifies common integration tasks and operations.

Table of Contents

Installation

  1. Clone this repository
  2. Build the project using Maven:
    mvn clean install
    
  3. Add the generated JAR to your SAP CPI project's dependencies

Features

  • MessageHelper: Simplify message processing and manipulation in SAP CPI
  • DateHelper: Comprehensive date and time manipulation utilities
  • JsonHelper: Streamlined JSON parsing and manipulation
  • ConverterUtil: Type conversion utilities for common data formats

Usage

MessageHelper

Simplify message processing in SAP CPI flows with these utility methods:

def messageHelper = new MessageHelper(message, messageLog)

// Get header values with optional defaults
String headerValue = messageHelper.getHeaderValue("headerName", "defaultValue")

// Get property values with optional defaults
String paramValue = messageHelper.getParamValue("paramName", "defaultValue")

// Add attachments
messageHelper.addAttachment("document.pdf", base64Content, "application/pdf")

// Add string content as attachment
messageHelper.addAttachmentAsString("log.txt", "Log content")

// Add custom header parameters
messageHelper.addHeaderParam("customHeader", "value")

// Convert JDBC result set to CSV
String csv = MessageHelper.JDBCResultSetToCSV(xmlContent)

DateHelper

Handle date and time operations with ease:

// Get current date/time
String currentDate = DateHelper.getActualDate.get()
String currentDateTime = DateHelper.getActualDateTime.get()

// Format dates
String formattedDate = DateHelper.parseLocalDate("2023-01-15", "yyyy-MM-dd", "dd/MM/yyyy")

// Time zone conversions
String zonedTime = DateHelper.getTimeOfZoneWithZoneId("Europe/Rome")

// Date differences
LocalDate startDate = LocalDate.of(2023, 1, 1)
LocalDate endDate = LocalDate.of(2023, 1, 15)
String daysBetween = DateHelper.diffPeriodDays.apply(startDate, endDate)

JsonHelper

Easily work with JSON data:

// Parse JSON and extract values
String jsonValue = JsonHelper.lookUpValueFieldFromJson(jsonString, "fieldName")

// Extract array of values
Object[] values = JsonHelper.lookUpValuesFieldFromJson(jsonArrayString, "fieldName")

// Convert epoch time to formatted date
String formattedDate = JsonHelper.convertEpoch_to_date(1675200000000, "yyyy-MM-dd HH:mm:ss")

ConverterUtil

Convert between different data types and handle streams:

// Convert String to InputStream
InputStream inputStream = ConverterUtil.getInputStreamFromString("content")

// Convert byte array to InputStream
byte[] bytes = ...
InputStream stream = ConverterUtil.getInputStreamFromByte(bytes)

// Convert InputStream to byte array
byte[] data = ConverterUtil.InputStreamToByteConverter(inputStream)

// Handle Base64 content
OutputStream output = ConverterUtil.Base64ToFile(inputStream, outputStream)

Examples

Processing a Message with Attachments

def messageHelper = new MessageHelper(message, messageLog)

try {
    // Get content from message
    String content = message.getBody(String.class)
    
    // Process content...
    
    // Add result as attachment
    messageHelper.addAttachmentAsString("result.txt", processedContent)
    
    // Add processing timestamp
    messageHelper.addHeaderParam("processedAt", DateHelper.getActualDateTime.get())
    
} catch (Exception e) {
    messageHelper.addAttachmentAsString("error.log", "Error: ${e.message}")
    throw e
}

Handling Date Operations

// Get first day of next month
String firstDayNextMonth = DateHelper.getFirstDayOfNextMonth.get()

// Format a date string from one format to another
String reformattedDate = DateHelper.parseLocalDate(
    "15-01-2023", 
    "dd-MM-yyyy", 
    "yyyy/MM/dd"
)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages