Friday, 9 April 2021

String to QR Code Image Generator Using Java

 Hi ,


Hope You are doing well.


I came up with the requirement, where I need to generate QR code Image file for the input String.


package demo;


import com.google.zxing.BarcodeFormat;

import com.google.zxing.BinaryBitmap;

import com.google.zxing.ChecksumException;

import com.google.zxing.DecodeHintType;

import com.google.zxing.FormatException;

import com.google.zxing.MultiFormatReader;

import com.google.zxing.NotFoundException;

import com.google.zxing.Result;

import com.google.zxing.WriterException;


import com.google.zxing.client.j2se.BufferedImageLuminanceSource;

import com.google.zxing.client.j2se.MatrixToImageWriter;

import com.google.zxing.common.BitMatrix;

import com.google.zxing.common.HybridBinarizer;

import com.google.zxing.qrcode.QRCodeReader;

import com.google.zxing.qrcode.QRCodeWriter;


import java.awt.image.BufferedImage;


import java.io.ByteArrayInputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;


import java.nio.file.FileSystems;

import java.nio.file.Path;


import java.util.Base64;


import java.util.HashMap;

import java.util.Map;


import javax.imageio.ImageIO;


public class QRCodeGenerator {

    private static final String QR_CODE_IMAGE_PATH = "C:\\Users\\sah75706.DS\\Desktop\\POC\\GeneratedFiles\\MyQRCoderr.png";


    private static void generateQRCodeImage(String text, int width, int height, String filePath) throws WriterException,

                                                                                                        IOException {

        QRCodeWriter qrCodeWriter = new QRCodeWriter();

        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);


        Path path = FileSystems.getDefault().getPath(filePath);

        MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);

    }


    public static void main(String[] args) throws NotFoundException {

        try {

            generateQRCodeImage("This is my first QR Code", 350, 350, QR_CODE_IMAGE_PATH);

            System.out.println("QRCode Generated");


        } catch (WriterException e) {

            System.out.println("Could not generate QR Code, WriterException :: " + e.getMessage());

        } catch (IOException e) {

            System.out.println("Could not generate QR Code, IOException :: " + e.getMessage());

        }

    }

}




Cheers!!

Format the date column in XSLT and Remove the column from Target XML if Source element is with Null Value

Hi,

Hope you are doing well. 

I came up with the requirement where I need to format the source CREATION_DATE to tns:recordStamp "2021-04-09T22:52:02" format in XSLT. Also I am checking If creation date is not coming from source then tns:recordStamp element should not be in target XML Payload.


XSLT : 

<xsl:if test="/ns0:OutputParameters/ns0:P_PAYLOAD_CUST_SEND_TBL/ns0:P_PAYLOAD_CUST_SEND_TBL_ITEM/ns0:CREATION_DATE !=''">
        <tns:recordStamp>
          <xsl:value-of select="xp20:format-dateTime (/ns0:OutputParameters/ns0:P_PAYLOAD_CUST_SEND_TBL/ns0:P_PAYLOAD_CUST_SEND_TBL_ITEM/ns0:CREATION_DATE, '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]' )"/>
        </tns:recordStamp>
      </xsl:if>


Cheers!!

ADVANCE: JCA PROPERTIES FOR ORACLE FILE/FTP ADAPTER

 JCA Properties for Oracle File and FTP Adapters:


  • ConcurrentThreshold: The maximum number of translation activities that can be allowed to execute in parallel for a particular outbound scenario. The translation step during the outbound operation is CPU-intensive and must be guarded because it might cause other applications or threads to starve. The maximum value is 100.
  • Lenient: If set to true, then the Orcle File Adapter does not complain if it does not have enough permission to read or write to the inbound directory. The default value of this property is false.
  • NumberMessages: This property is used for outbound batching. The outgoing file is created when the number of messages condition is met. The parameter is of type intand is not mandatory. The default value is 1.
  • Recursive: If this property is set to true, then the adapter can process all the sub-directories under the main input directory recursively.
  • ThreadCount: If this property is available, then the adapter creates its own processor threads rather than depend on the global thread pool processor threads (by deafult, 4 of them). In other words, this parameter partitions the in-memory queue and each composite application gets its own in-memory queue.
    • If the ThreadCount property is set to 0, then the threading behavior equals that of the single-threaded model.
    • If the ThreadCount property is set to -1, then the global thread pool is used, which equals the default threading model.
    • The maximum value for the ThreadCount property is 40.
  • UseStaging: If set to true, then the outbound Oracle File or FTP Adapter writes translated data to a staging file, and later it streams the staging file to the target file. If set to false, then the outbound Oracle File or FTP Adapter does not use an intermediate staging file.
  • UseRemoteArchive: Set this property to true to notify the Oracle FTP Adapter that the archival directory is on the same FTP server. If set to false, the Oracle FTP Adapter uses a local file system folder for archival.
  • inMemoryTranslation: This property is applicable only if UseStaging is set to false .If UseStaging is set to true, then the translation step occurs in-memory (that is, an in-memory byte array is created). If set to false, then the adapter creates an output stream to the target file (FTP, FTPS, and SFTP included) and allows the translator to translate and write directly to the stream.
  • useFileSystem: This property is used by inbound Oracle File or FTP Adapter during read-only polling in a clustered environment. Setting it to true causes the adapter to use the file system to store the metadata of the processed files. Setting it to false causes the adapter  to use a database table.
  • timestampOffset: This property is used by the Oracle FTP Adapter to handle time zone issues, typically to convert the time difference between the FTP server and the system on which the Oracle FTP Adapter is running to millisecond.

JCA Properties for Oracle JMS Adapter:
  • EnableStreaming: When this property is set to "true", the payload from the queue or topic is streamed instead of being processed as an in-memory DOM. You must use this feature while handling large payloads.
  • DeliveryMode: Represents the delivery mode to use. The message producer's default delivery mode is PERSISTENT. This can be overridden on a per message basis using normalized message property jca.aq.JMSDeliveryMode.
  • adapter.jms.encoding:Used to encode inbound text messages. This property is superseded by the newly supported property called jca.message.encoding that is applicable for both inbound and outbound messages.

Cheers!!

ADD/DELETE HOURS/MINUTES IN XQUERY

Hi,

Recently i came up with a requirement where due to different timezone we have to send received date with 4 hour difference, We tried same thing to control in XSLT but in that case we have to write one XSLT template which will handle it.

Yes that work for us as we need to handle time part only, in-respect of what's going to be happen with Date but for feature we must be prepared to handle date also, so we come up with some pre-defined xquery function who will take care our this timezone issue.



  • Subtract minutes from date.
    • {xs:dateTime(runTs)  -  xs:dayTimeDuration("PT15M")}


  • Subtract hours from date
    • {xs:dateTime(runTs)  -  xs:dayTimeDuration("PT4H")}

  • Add hours in date
    • {xs:dateTime(runTs)  + xs:dayTimeDuration("PT4H")}
  • Add minutes in date.
    • {xs:dateTime(runTs)  +  xs:dayTimeDuration("PT15M")}


Sample Test case: 4 Hours subtract from input dateTime 

Input:  <runTs>2020-08-12T02:28:25.786</runTs>
Output (Subtract hours from date): <whe:runTs>2020-08-11T22:28:25.786</whe:runTs>


Cheers!!

Calling REST API to POST input parameters Data Using JAVA Embedding in BPEL

Hi , 

I came up with a requirement where I need to send Highlighted Parameters Data to below API. 

REST APIURI : 
https://api-abc.io/OrderService.asmx/SubmitNewOrdersWithPaymentAdvanced?ClientName=

When we assign the xml payload to String type XMLPayloadData variable , we use ora:getContentAsString($XMLPayload)   ---to-> XMLPayloadData   in Assign Activity



JAVA Embedding code : 

try {      
addAuditTrailEntry("JAVA activity Started");      
String lvar_ClientName = (String)getVariableData("ClientName");           
String lvar_GUID = (String)getVariableData("guid");           
String lvar_InboundXML = (String)getVariableData("XMLPayloadData");    
String lvar_ProcessingOptions = (String)getVariableData("ProcessingOptions");       
String lvar_EOMURL=(String)getVariableData("APIURI");     
addAuditTrailEntry("APIURI: " + lvar_EOMURL); 
     
 addAuditTrailEntry("JAVA activity Started  ---  1...");     
URL url = new URL(lvar_EOMURL);         
Map<String, Object> params = new LinkedHashMap<>();         
params.put("ClientName", lvar_ClientName);         
params.put("GUID", lvar_GUID);         
params.put("InboundXML",lvar_InboundXML);         
params.put("ProcessingOptions",  lvar_ProcessingOptions);         
 addAuditTrailEntry("JAVA activity Started  ---  2...");     
                addAuditTrailEntry(lvar_InboundXML);    
StringBuilder postData = new StringBuilder();         
for (Map.Entry<String, Object> param : params.entrySet()) {         
if (postData.length() != 0)         
postData.append('&');         
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));         
postData.append('=');         
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));         
}         
addAuditTrailEntry(postData.toString());    
addAuditTrailEntry("JAVA activity Started  ---  3...");     
byte[] postDataBytes = postData.toString().getBytes("UTF-8");         
     
HttpURLConnection conn = (HttpURLConnection) url.openConnection();         
conn.setRequestMethod("POST");         
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");         
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));         
conn.setDoOutput(true);         
conn.getOutputStream().write(postDataBytes);         
     
//Reader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));         
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));         
StringBuilder sb = new StringBuilder();         
String line;         
//for (int c; (c = in.read()) >= 0;)         
//System.out.print((char) c);         
while ((line = rd.readLine()) != null) {         
sb.append(line);         
}         
rd.close();         
addAuditTrailEntry(sb.toString());     
                setVariableData("APIResponse",sb.toString());   
 
} catch (MalformedURLException me) {         
addAuditTrailEntry("MalformedURLException " + me.getMessage());         
} catch (ProtocolException pe) {         
addAuditTrailEntry("ProtocolException " + pe.getMessage());         
} catch (IOException ioe) {         
addAuditTrailEntry("IOException" + ioe.getMessage());         
} catch (Exception e) {         
addAuditTrailEntry("We got an Exception " + e.getMessage());         
}



At last Do below in assign Activity -- APIResponse Type String

oraext:parseXML($APIResponse)   -- to -> $ResponseXML  Type Element

You will get the API response on $ResponseXML  Type Element of API response XSD


Task is done!
Cheers!!

Removing Namespaces from XML using JAVA Embedding



Hi,


Recently I came up with a requirement where I need to remove xmlns="" from below XML. So I did it using JAVA Embedding in BPEL.

Sample XML :

<?xml version="1.0" encoding="UTF-8"?>
<stores xmlns="http://www.demandware.com/xml/impex/store/2007-04-30">
<store store-id="R00591"  xmlns="">
<name>Irvine, CA</name>
<address1>YCC - IRVINE, CA #0591</address1>
<address2>735 SPECTRUM CENTER DRIVE</address2>
<city>IRVINE</city>
<postal-code>92618</postal-code>
<state-code>CA</state-code>
<country-code>US</country-code>
<phone>949-450-0725</phone>
<store-hours>Sunday 11:00 - 19:00|Monday 11:00 - 19:00|Tuesday 11:00 - 19:00|Wednesday 11:00 - 19:00|Thursday 11:00 - 19:00|Friday 11:00 - 20:00|Saturday 11:00 - 20:00</store-hours>
<latitude>33.6490286</latitude>
<longitude>-117.7449241</longitude>
<store-locator-enabled-flag>true</store-locator-enabled-flag>
<demandware-pos-enabled-flag>false</demandware-pos-enabled-flag>
<pos-enabled-flag>false</pos-enabled-flag>
<custom-attributes>
<custom-attribute attribute-id="ctaUrl">/stores/california/irvine-ca</custom-attribute>
</custom-attributes>
</store>
<store store-id="R00001"  xmlns="">
<name>Deerfield, MA</name>
<address1>YCC -SOUTH DEERFIELD, MA #0001</address1>
<address2>25 GREENFIELD ROAD</address2>
<city>SOUTH DEERFIELD</city>
<postal-code>01373</postal-code>
<state-code>MA</state-code>
<country-code>US</country-code>
<phone>413-665-2929</phone>
<store-hours>Sunday 10:00 - 18:00|Monday 10:00 - 18:00|Tuesday 10:00 - 18:00|Wednesday 10:00 - 18:00|Thursday 10:00 - 18:00|Friday 10:00 - 18:00|Saturday 10:00 - 18:00</store-hours>
<latitude>42.4744</latitude>
<longitude>-72.614073</longitude>
<store-locator-enabled-flag>true</store-locator-enabled-flag>
<demandware-pos-enabled-flag>false</demandware-pos-enabled-flag>
<pos-enabled-flag>false</pos-enabled-flag>
<custom-attributes>
<custom-attribute attribute-id="ctaUrl">/stores/massachusetts/south-deerfield-ma</custom-attribute>
</custom-attributes>
</store>
</stores>

We can remove  xmlns="" from payload using JAVA Embedding activity.ust follow below steps- 

Step 1. Assign "InvokeSFCCArchive_Write_InputVariable.body" Element type variable data as String using ora:getContentAsString() function to InputVar String type variable 

Example-

ora:getContentAsString($InvokeSFCCArchive_Write_InputVariable.body)   to $InputVar Type String


Step 2. Add below code to Java Embedding activity-

try{  

addAuditTrailEntry("JAVA activity Started");        

String inputXml = (String)getVariableData("InputVar");    

String input=inputXml.replace("xmlns=\"\"", "");

addAuditTrailEntry("String after Removing of xmlns  : "+input);      

setVariableData("tempXML",input.toString());  // Assigning processed xml to tempXML String Var

addAuditTrailEntry("inputtoString  : "+input.toString()); 

}   catch (Exception e) {           

addAuditTrailEntry("We got an Exception " + e.getMessage());           

}

Step 3. parseXML from tempXML to Element Type variable in Assign Activity

oraext:parseXML($tempXML)  to $InvokeSFCCArchive_Write_InputVariable.body


Processed XML :

<?xml version="1.0" encoding="UTF-8"?>
<stores xmlns="http://www.demandware.com/xml/impex/store/2007-04-30">
<store store-id="R00591">     <!-- No xmlns=""  -->
<name>Irvine, CA</name>
<address1>YCC - IRVINE, CA #0591</address1>
<address2>735 SPECTRUM CENTER DRIVE</address2>
<city>IRVINE</city>
<postal-code>92618</postal-code>
<state-code>CA</state-code>
<country-code>US</country-code>
<phone>949-450-0725</phone>
<store-hours>Sunday 11:00 - 19:00|Monday 11:00 - 19:00|Tuesday 11:00 - 19:00|Wednesday 11:00 - 19:00|Thursday 11:00 - 19:00|Friday 11:00 - 20:00|Saturday 11:00 - 20:00</store-hours>
<latitude>33.6490286</latitude>
<longitude>-117.7449241</longitude>
<store-locator-enabled-flag>true</store-locator-enabled-flag>
<demandware-pos-enabled-flag>false</demandware-pos-enabled-flag>
<pos-enabled-flag>false</pos-enabled-flag>
<custom-attributes>
<custom-attribute attribute-id="ctaUrl">/stores/california/irvine-ca</custom-attribute>
</custom-attributes>
</store>
<store store-id="R00001">  <!-- No xmlns=""  -->
<name>Deerfield, MA</name>
<address1>YCC -SOUTH DEERFIELD, MA #0001</address1>
<address2>25 GREENFIELD ROAD</address2>
<city>SOUTH DEERFIELD</city>
<postal-code>01373</postal-code>
<state-code>MA</state-code>
<country-code>US</country-code>
<phone>413-665-2929</phone>
<store-hours>Sunday 10:00 - 18:00|Monday 10:00 - 18:00|Tuesday 10:00 - 18:00|Wednesday 10:00 - 18:00|Thursday 10:00 - 18:00|Friday 10:00 - 18:00|Saturday 10:00 - 18:00</store-hours>
<latitude>42.4744</latitude>
<longitude>-72.614073</longitude>
<store-locator-enabled-flag>true</store-locator-enabled-flag>
<demandware-pos-enabled-flag>false</demandware-pos-enabled-flag>
<pos-enabled-flag>false</pos-enabled-flag>
<custom-attributes>
<custom-attribute attribute-id="ctaUrl">/stores/massachusetts/south-deerfield-ma</custom-attribute>
</custom-attributes>
</store>
</stores>


Your task is done!

Enjoy, Cheers !!


Tuesday, 25 February 2020

All About JMS and Queue Configuration


How to configure JMS on Weblogic Server 12c

JMS Server:
A JMS server acts as a management container for resources which are available in JMS  modules. Some of its responsibilities include the maintenance of  persistence and state of messages and subscribers. A JMS server is  required in order to create a JMS module.

JMS Module:
A JMS module contains JMS resources such as queues/topics. A JMS module is required in order to create a JMS queue.

Subdeployment:
JMS modules are targeted to one or more WLS instances or a cluster.  Resources within a JMS module, such as queues and topics are also targeted to a JMS server or WLS server instances. A subdeployment is a grouping of targets. It is also known as advanced targeting.

Connection Factory:
A connection factory is a resource that enables JMS clients to create connections to JMS destinations.

JMS Queue:
A JMS queue (as opposed to a JMS topic) is a point-to-point destination type. A message is written to a specific queue or received from a specific queue.

The objects used in this example are:

Object Name
Type
JNDI Name
DemoJMSServer
JMS Server

DemoJMSModule
JMS Module

DemoSubDeployment
Subdeployment

DemoConnectionFactory
Connection Factory
jms/DemoConnectionFactory
DemoJMSQueue
JMS Queue
jms/DemoJMSQueue





--------------------------------------------------

   1. JMS Server Configuration Steps:

    1.1. Create a JMS Server: Services > Messaging > JMS Servers




1.2. Select New

1.3  Name: DemoJMSServer


                  Persistent Store: (Click on Create a New Store )- 

Select Type ="JDBC Store" and click next

Provide below details - 


Click next and finish. then select the newly created JDBC Store and click next -
1.4. Target: soa_server1 (or choose an available server)



1.5.  Finish - Click Finish.
The JMS server should now be visible in the list with Health OK.



--------------------------------------------

2. JMS Module Configuration Steps :


2.1.  Services > Messaging > JMS Modules
2.2.  Select New
2.3.  Name: DemoJMSModule  and  Leave the other options to  default



2.4.  Targets: soa_server1 (or choose the same one as the JMS server)
        PressNext


2.5.  Leave “Would you like to add resources to this JMS system
        module” unchecked and  pressFinish.


DemoJMSModule   is created successfully.



--------------------------------------------------

3. Create a SubDeployment : 

A subdeployment is not necessary for the JMS queue to work, but it allows you to easily target subcomponents of the JMS module to a single target or group of targets. We will use the subdeployment in this example to target the following connection factory and JMS queue to the JMS server we created earlier.

3.1. Services > Messaging > JMS Modules
3.2. Select DemoJMSModule
3.3. Click on Subdeployments tab and New



3.4. Subdeployment Name: DemoSubdeployment



3.5. Press Next
3.6. Select Target - Here you can select the target(s) for the subdeployment. You can choose either Servers (i.e. WebLogic managed servers, such as the soa_server1) or JMS Servers such as the JMS Server created earlier. 
As the purpose of our subdeployment in this example is to target a specific JMS server, we will choose the JMS Server option.
Select the DemoJMSServer created earlier

3.7. Press Finish


--------------------------------------

4. Create a Connection Factory

4.1. Services > Messaging > JMS Modules
4.2. Click on DemoJMSModule and press New


4.3. Select Connection Factory and Next



4.4. Name: DemoConnectionFactory
JNDI Name: jms/DemoConnectionFactory
Leave the other values at default



4.5. On the Targets page, select the Advanced Targeting button and select DemoSubdeployment



4.6. Press Finish
The connection factory should be listed on the following page with DemoSubdeployment and DemoJMSServer as the target.
----------------------------------------------

5 Create a JMS Queue

5.1. Services > Messaging > JMS Modules
5.2. Click on  DemoJMSModule and press New
5.3. Select Queue and Next



5.4. Name: DemoJMSQueue
JNDI Name: jms/DemoJMSQueue
Template:None
PressNext



5.5. Subdeployments: DemoSubdeployment



5.6. Finish
The DemoJMSQueue should be listed on the following page with  DemoSubdeployment and DemoJMSServer.




Release Configuration.

The JMS queue is now complete and can be accessed using the JNDI names
jms/DemoConnectionFactory
jms/DemoJMSQueue.



Keep Learning ! Cheers Guys!!

Kavindra Sahu


String to QR Code Image Generator Using Java

 Hi , Hope You are doing well. I came up with the requirement, where I need to generate QR code Image file for the input String. package dem...