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


Tuesday, 18 February 2020

DataSource, JNDI Creation DB & FTP on Weblogic Server

******************* DataSource Creation on Weblogic Server **************************


1. Login into WebLogic Console. The default URL is http://<HOSTNAME>:<PORT>/console


2. Click Data Sources under services,





Click New and select Generic Data Source


3. Input a Name, Scope as Global, JNDI Name for your code to lookup, and Database Type (Oracle, My SQL, etc.,)



4.  Accept the default and click Next



5.
6.


7. Click on test configuration- Then click on next


8. Then click on next, select target, then click on finish.




This way data source has been created.





****************    JNDI Configurations for Database ***************** 



1. JNDI Configurations for DB

----------------------------------------------
1.a. Log into  Console -  http://<HOSTNAME>:<PORT>/console
1.b Lock and Edit

Create  outbound Connection poll in DBAdapter
----------------------------------------------

1.c    Goto Deployments --> DBAdapter --> Configuration --> Outbound Connection Pools ---> New



1.d   Select javax.resource.cci.ConnectionFactory --> Next -> Privde JNDI Name below --> Finish



     JNDI Name: eis/DB/TestDB


1.e  Expand javax.resource.cci.ConnectionFactory--> Click on eis/DB/TESTDB


Enter below details  in Outbound Connection Properties


     PlatformClass: org.eclipse.persistence.platform.database.Oracle10Platform --> Enter to Save



     XADataSourceName: jdbc/TestDB--> Enter to Save





1.f Save and Activate changes


Again take lock & Edit then -
1.g   Goto Deployments --> Select DBAdapter and update DBAdapter.

After successful update , it will show like below.




JNDI           - eis/DB/TESTDB
DataSource -  jdbc/TestDB

JNDI is confifured successfully.
-----------------------------------------

======================================================================

****************    JNDI Configurations for FTP ***************** 


2. JNDI Configurations for FTP
----------------------------------------------

2.a. Log into  Weblogic Console -  http://<HOSTNAME>:<PORT>/console

2.b Lock and Edit
Create FTP outboundpool connection.
 -------------------------------

2.c    Goto Deployments --> FTPAdapter --> Configuration --> Outbound Connection Pools ---> New

Select javax.resource.cci.ConnectionFactory --> Next -> Privde JNDI Name below --> Finish


     JNDI: eis/sftp/testftp


2.d Click on eis/sftp/testftp

Enter below details  in Outbound Connection Properties
     username: username Enter to Save
     password:Password Enter to Save
     Host: ftp.abcftp.com
     UseSftp : true Enter to Save


2.e Save and Activate changes 

First Take lock & Edit then 
2.f   Goto Deployments --> and select FTP Adapter and update FTP Adapter.


Release Configuration.

Keep Learning ! Cheers Guys!!

Kavindra Sahu

Thursday, 16 January 2020

Web Services

Web services are web based applications.It is a collection of standards or protocols for exchanging information between two devices or application.
The Web Service is a standard software system used for communication between two devices (client and server) over the network. Web services provide a common platform for various applications written in different languages to communicate with each other over the network.

Web services are the types of internet software that uses standardized messaging protocol over the distributed environment. It integrates the web-based application using the REST, SOAP, WSDL, and UDDI over the network.


There are mainly two types of web services.
1. SOAP web services.
2. RESTful web services.

These are some of the important advantages of web services:

Interoperability: With the help of web services, an application can communicate with other application developed in any language.
Reusability: We can expose the web service so that other applications can use it.
Modularity: With the help of web service, we can create a service for a specific task such as tax calculation.

A Standard protocol for every application program: Web services use standard protocol so that all the client applications written in different languages can understand it. This Standard protocol helps in achieving cross-platform.

Cheaper cost for communication: Web services uses SOAP over HTTP so that anybody can use existing internet for using web services.


Following is a list of main features of web services:

It is available over the Internet or private (intranet) networks.
It uses a standardized XML messaging system.
It is not tied to any one operating system or programming language.
It is self-describing via a common XML grammar.
It is discoverable via a simple find mechanism.



------------------------------------------------- SOAP Web Services -----------------------------------------------


SOAP stands for Simple Object Access Protocol. It is a XML-based protocol for accessing web services.
SOAP is a W3C recommendation for communication between two applications.
SOAP is XML based protocol. It is platform independent and language independent. By using SOAP, you will be able to interact with other programming language applications.


Advantages of Soap Web Services:
WS Security: SOAP defines its own security known as WS Security.
Language and Platform independent: SOAP web services can be written in any programming language and executed in any platform.


Disadvantages of Soap Web Services
Slow: SOAP uses XML format that must be parsed to be read. It defines many standards that must be followed while developing the SOAP applications. So it is slow and consumes more bandwidth and resource.
WSDL dependent: SOAP uses WSDL and doesn't have any other mechanism to discover the service.


------------------------------------------------ RESTful Web Services ---------------------------------------------

RESTful Web Services:

  • REST stands for REpresentational State Transfer.
  • REST is an architectural style not a protocol.

It is developed by Roy Thomas Fielding who also developed HTTP. The main goal of RESTful web services is to make web services more effective. RESTful web services try to define services using the different concepts that are already present in HTTP. REST is an architectural approach, not a protocol.
It does not define the standard message exchange format. We can build REST services with both XML and JSON. JSON is more popular format with REST. The key abstraction is a resource in REST. A resource can be anything. It can be accessed through a Uniform Resource Identifier (URI).
For example:
The resource has representations like XML, HTML, and JSON. The current state is captured by representational resource. When we request a resource, we provide the representation of the resource.
The important methods of HTTP are:
GET: It reads a resource.
PUT: It updates an existing resource.
POST: It creates a new resource.
DELETE: It deletes the resource.

POST /users: It creates a user.

GET /users/{id}: It retrieve the detail of one user.

GET /users: It retrieve the detail of all users.

DELETE /users: It delete all users.

DELETE /users/{id}: It delete a user.

GET /users/{id}/posts/post_id: It retrieve the detail of a specific post.

POST / users/{id}/ posts: It creates a post for a user.

GET /users/{id}/post: Retrieve all posts for a user


HTTP also defines the following standard status code:

404: RESOURCE NOT FOUND
200: SUCCESS
201: CREATED
401: UNAUTHORIZED
500: SERVER ERROR


RESTful Service Constraints :
There must be a service producer and service consumer.
The service is stateless.
The service result must be cacheable.
The interface is uniform and exposing resources.
The service should assume a layered architecture.

Advantages of RESTful web services:
RESTful web services are platform-independent.
It can be written in any programming language and can be executed on any platform.
It provides different data format like JSON, text, HTML, and XML.
It is fast in comparison to SOAP because there is no strict specification like SOAP.
These are reusable.
These are language neutral.



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

There are two popular formats for request and response XML and JSON.

XML Format: XML is the popular form as request and response in web services. Consider the following XML code:

<getDetail>
<id>EmployeeDetail</id>
</getDetail>

The code shows that user has requested to access the EmployeeDetail.



The other data exchange format is JSON. JSON is supported by wide variety of platform.
[ 
    "employee": 
   { 
        "id": 20097420
        "name":       "Kavindra",   
        "salary":      15000,   
   } 
]


To make a web service platform-independent, we make the request and response platform-independent.


Now a question arises, how does the Application know the format of Request and Response?

The answer to this question is "Service Definition." Every web service offers a service definition. Service definition specifies the following:

* Request/ Response format: Defines the request format made by consumer and response format made by web service.
* Request Structure: Defines the structure of the request made by the application.
* Response Structure: Defines the structure of response returned by the web service.
* Endpoint: Defines where the services are available.



Key Terminology of Web Services :
* Request and Response
* Message Exchange Format: XML and JSON
* Service Provider or Server
* Service Consumer or Client
* Service Definition
* Transport: HTTP and MQ


Request and Response: Request is the input to a web service, and the response is the output from a web service.

Message Exchange Format: It is the format of the request and response. There are two popular message exchange formats: XML and JSON.

Service Provider or Server: Service provider is one which hosts the web service.

Service Consumer or Client: Service consumer is one who is using the web service.

Service Definition: Service definition is the contract between the service provider and service consumer. Service definition defines the format of request and response, request structure, response structure, and endpoint.

Transport: Transport defines how a service is called. There is two popular way of calling a service: HTTP and Message Queue (MQ). By tying the URL of service, we can call the service over the internet. MQ communicates over the queue.



Keep Learning ! Cheers Guys!!

Kavindra Sahu


Web Services Components

Web Services Components


There are two components of web services:

* Web Service Description Language (WSDL)
* Universal Description Discovery and Integration (UDDI)

Web Service Description Language (WSDL):
WSDL acronym for Web Service Description Language. WSDL is an XML based interface description language. It is used for describing the functionality offered by a web service. Sometimes it is also known as the WSDL file. The extension of the WSDL file is .wsdl. It provides the machine-readable description of how the service can be called, what parameter it expects, and what data structure it returns.

Service   -- It is a set of system functions.
Port   --    It is an endpoint that defines a combination of binding and network addresses.
Binding   -- It specifies the interface and defines the SOAP binding style. It also defines the operations.
PortType  -- An abstract set of services supported by one or more endpoints.
Operation -- Abstract detail of an action supported by the service. It defines the SOAP actions and the way of encoding the message.
Message   -- An abstract, typed definition of data to communicate. W3C has removed the message in WSDL 2.0, in which XML Schema types for defining bodies of inputs, outputs, and faults are referred directly.
Types   -- It is a container for data type definition. The XML Schema language (XSD) is used for this purpose.




Universal Description, Discovery, and Integration (UDDI):

UDDI acronym for Universal Description, Discovery, and Integration. It is an XML-based registry for businesses word wide to list themselves on the internet.

A service provider registers its business with the UDDI registry.
A service provider registers each service separately with the UDDI registry.
The consumer looks up the business and service in the UDDI registry.
The consumer binds the service with the service provider and uses the service.


The UDDI business registry system has three directories are as follows:
White Pages: The white pages contain basic information such as company name, address, phone number, and other business identifiers such as tax numbers.

Yellow Pages: The yellow pages contain detailed business data organized by relevant business classification. The version of the yellow page classifies business according to the newer NAICS (North American Industry Classification System).

Green Pages: The green pages contain information about the company's crucial business process, such as operating platform, supported programs, and other high-level business protocols.


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...