Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, July 21, 2014

Convert binary data in OSB context variable into string

The function will be use to convert binary data in OSB context variable into string.

Another useful POJO to add to your OSBToolkit.java.

public class OSBToolkit
{

    public OSBToolkit()
    {
    }

    public static String convertOSBBinaryContentToString(DataSource ds) throws Exception
    {
        InputStream is=ds.getInputStream();
        BufferedReader din = new BufferedReader(new InputStreamReader(is));
        StringBuffer sb = new StringBuffer();
        try {
            String line = null;
            while((line=din.readLine()) != null){
                sb.append(line+"\n");
            }
        }
        finally{
            try{
                is.close();
            } catch(IOException ex){}
        }
        return sb.toString();
    }
}

 

Convert Siebel datetime to XML

Class to parse Siebel datetime format into XML standard format.

Another useful POJO to add to your OSBToolkit.java.

public class OSBToolkit
{

    public OSBToolkit()
    {
    }

    public static Date convertSiebelDateTimeToXML(String dateString) {
        Date stringDate = null;
       
        try
        { //If dateTime
            if(dateString.trim().length() > 10)
            {
                stringDate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(dateString);

            }// If just a date
            else if(dateString.trim().length() > 0)
            {
                stringDate = new SimpleDateFormat("MM/dd/yyyy").parse(dateString);
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();   
        }
       
        return stringDate;
     }
 
 
    public static String convertXMLToSiebelDate(Date date) {
      String formattedDate ="";
      if(date != null)
      {
          SimpleDateFormat format =
            new SimpleDateFormat("MM/dd/yyyy");
          formattedDate = format.format(date);
      }
      else
      {
         
      }
        return formattedDate;
     }
}

 

Sleep/pause/throttle the transaction in OSB

From time-to-time you have requirement to sleep/pause/throttle the transaction in OSB. You can do this by using a simple POJO.

Below is a class to add to your OSBToolkit.java.

public class OSBToolkit
{

    public OSBToolkit()
    {
    }

    public static String sleep(long l)
    {
        String s;
        try
        {
            Thread.sleep(l);
            s = "Success";
        }
        catch(Exception exception)
        {
            s = "Error";
        }
        return s;
    }
}


Then from OSB, reference to the OSBToolkit and the sleep class, specify the following value as input:
xs:long(5000)