Wednesday, July 27, 2016

Process flow from Java to SAP with SAP JCO plugin and sample Sales Order example



Java to SAP integration Process flow.

The SAP Java Connector (JCO) is a middleware component that enables Java to access R/3 based systems and vice versa. This means that JCO as well serves as a client to call R/3 Remote Function Calls (BAPIs, Function Modules that can be called from outside) and in addition to that it offers the possibility to work as a Server that receives calls from R/3.

SAP JCo offers the following functions for creating SAP-compliant Java applications:
SAP JCo is based on the JNI (Java Native Interface) which facilitates access to the CPIC library.
It supports SAP (R/3) systems from Release 3.1H upwards, and other mySAP components that have BAPIs or RFMs (Remote Function Modules).
We can execute function calls inbound (Java client calls BAPI or RFM) and outbound (ABAP calls Java Server).
With SAP JCo, you can use synchronous, transactional, queued, and background RFC.
SAP JCo can be used on different platforms

How to install JCO (on Windows) 

1.1. Downloading JCO
JCO can be downloaded from http://service.sap.com/connectors under SAP Java Connector -> Tools & Services
1.2. .DLL files
JCO contains two .DLL files that enable JCO to call RFC based R/3 function modules:
- librfc32.dll -> Provides the base functionality to access RFCs from Windows. It is also used by SAP GUI. Copy that .DLL to your windows/systems32 directory. If there is a newer version already installed, don't overwrite it!
- sapjcorfc.dll -> As far as I know this .DLL wraps the librfc32.dll to enable JCO the access of this .DLL. Also copy this file to your windows/system32 directory.
1.3. .JAR files
In order to use JCO within JAVA, you'll need an API. This API is contained in sapjco.jar. You need to include this .JAR file within your application's classpath.


The SAP JCo Repository

The SAP Java Connector must be able to access the metadata of all Remote Function Modules (RFMs) that are to be used by a Java client. A JCoRepository object is created to do this. The current metadata for the RFMs is retrieved either dynamically from the SAP server at runtime (recommended) or hard-coded.
You must only create the JCoRepository object in the case of hard-coded metadata. This step is automatically executed internally by JCo when retrieving metadata.

Setting up a Repository
Procedure
For the JCo Repository, you need the following interfaces:
o JCoRepository: Contains the runtime metadata of the RFMs.
o JCoFunctionTemplate: Contains the metadata for an RFM.
o JCoFunction: Represents an RFM with all its corresponding parameters.
Make sure that the user ID for the Repository has all the required authorizations for accessing the metadata of the SAP servers.

 Syntax
Creating a JCo Repository
JCoRepository mRepository;
mRepository = destination.getRepository ();

JCO.Repository Contains the runtime metadata for the Remote Function Modules.
IFunctionTemplate Contains the metadata for one single RFM.
JCO.Function Represents an RFM with all its parameters.
JCO.ParameterList Contains the import or export or table parameters of a JCO.Function (that represents an RFM).
JCO.Structure RFMs are able to receive/ pass structures. This class represents such structures.
JCO.Table RFMs are able to receive/ pass table. This class represents such tables.

Creating JCo Function Objects
Procedure
To create a JCo Function object, proceed as follows:
1. Execute the getFunction() method on the JCoRepository interface.
2. Execute the getFunctionTemplate method on the JCoRepository interface.
3. Execute the getFunction() method on the Template.
In addition to containing metadata, a function object also contains the current parameters for executing the RFMs. The relationship between a function template and a function in SAP JCo is similar to that between a class and an object in Java. The code displayed above encapsulates the creation of a function object.

Standalone Java Program for Creating a SAP Server Connection
 We can write a Java program that establishes a server connection to a SAP gateway.
Procedure:
To do this, we need to implement the JCoServerFunctionHandler and the coding to be executed when the call is received.
Create an instance for your JCoServer implementation and start it with start().
Definition of Server Properties

import java.io.File;
import java.io.FileOutputStream;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;

import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.ext.ServerDataProvider;
import com.sap.conn.jco.server.DefaultServerHandlerFactory;
import com.sap.conn.jco.server.JCoServer;
import com.sap.conn.jco.server.JCoServerContext;
import com.sap.conn.jco.server.JCoServerErrorListener;
import com.sap.conn.jco.server.JCoServerExceptionListener;
import com.sap.conn.jco.server.JCoServerFactory;
import com.sap.conn.jco.server.JCoServerFunctionHandler;
import com.sap.conn.jco.server.JCoServerState;
import com.sap.conn.jco.server.JCoServerStateChangedListener;
import com.sap.conn.jco.server.JCoServerTIDHandler;


public class StepByStepServer
{
   static String SERVER_NAME1 = "SERVER";
   static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
   static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
   static
   {
       Properties connectProperties = new Properties();
       connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "ls4065");
       connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "85");
       connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
       connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "farber");
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "laska");
       connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");
       createDataFile(DESTINATION_NAME1, "jcoDestination", connectProperties);

       connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
       connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    "10");
       createDataFile(DESTINATION_NAME2, "jcoDestination", connectProperties);
     
       Properties servertProperties = new Properties();
       servertProperties.setProperty(ServerDataProvider.JCO_GWHOST, "binmain");
       servertProperties.setProperty(ServerDataProvider.JCO_GWSERV, "sapgw53");
       servertProperties.setProperty(ServerDataProvider.JCO_PROGID, "JCO_SERVER");
       servertProperties.setProperty(ServerDataProvider.JCO_REP_DEST, "ABAP_AS_WITH_POOL");
       servertProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, "2");
       createDataFile(SERVER_NAME1, "jcoServer", servertProperties);
   }
 
    static void createDataFile(String name, String suffix, Properties properties)
   {
       File cfg = new File(name+"."+suffix);
       if(!cfg.exists())
       {
           try
           {
               FileOutputStream fos = new FileOutputStream(cfg, false);
               properties.store(fos, "for tests only !");
               fos.close();
           }
            catch (Exception e)
           {
               throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
           }
       }
   }
 

JCo Server


     static class StfcConnectionHandler implements JCoServerFunctionHandler
   {
       public void handleRequest(JCoServerContext serverCtx, JCoFunction function)
       {
           System.out.println("----------------------------------------------------------------");
            System.out.println("call              : " + function.getName());
           System.out.println("ConnectionId      : " + serverCtx.getConnectionID());
           System.out.println("SessionId         : " + serverCtx.getSessionID());
           System.out.println("TID               : " + serverCtx.getTID());
           System.out.println("repository name   : " + serverCtx.getRepository().getName());
            System.out.println("is in transaction : " + serverCtx.isInTransaction());
           System.out.println("is stateful       : " + serverCtx.isStatefulSession());
           System.out.println("----------------------------------------------------------------");
           System.out.println("gwhost: " + serverCtx.getServer().getGatewayHost());
           System.out.println("gwserv: " + serverCtx.getServer().getGatewayService());
           System.out.println("progid: " + serverCtx.getServer().getProgramID());
           System.out.println("----------------------------------------------------------------");
           System.out.println("attributes  : ");
           System.out.println(serverCtx.getConnectionAttributes().toString());
            System.out.println("----------------------------------------------------------------");
           System.out.println("req text: " + function.getImportParameterList().getString("REQUTEXT"));
           function.getExportParameterList().setValue("ECHOTEXT", function.getImportParameterList().getString("REQUTEXT"));
           function.getExportParameterList().setValue("RESPTEXT", "Hello World");
       }
   }
   static void step1SimpleServer()
   {
       JCoServer server;
       try
       {
           server = JCoServerFactory.getServer(SERVER_NAME1);
       }
       catch(JCoException ex)
       {
           throw new RuntimeException("Unable to create the server " + SERVER_NAME1 + ", because of " + ex.getMessage(), ex);
       }
     
       JCoServerFunctionHandler stfcConnectionHandler = new StfcConnectionHandler();
       DefaultServerHandlerFactory.FunctionHandlerFactory factory = new DefaultServerHandlerFactory.FunctionHandlerFactory();
        factory.registerHandler("STFC_CONNECTION", stfcConnectionHandler);
       server.setCallHandlerFactory(factory);
     
        server.start();
       System.out.println("The program can be stopped using +");
   }

Sample Example: Sales Order upload from JAVA to SAP

import java.sql.Timestamp;
import java.util.Calendar;

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;

public class SalesOrder {
   
     static final String SID = "R3";
     static final String errorID = "E";
     IRepository repository;
     //String orderNumber = orderCreation("M-01","3000","0002",3,"ST");
     int counter;

     public SalesOrder()
          {
               try {
                    // Add a connection pool to the specified system
                    JCO.addClientPool(SID,            // Alias for this pool
                                         10,            // Max. number of connections
                                         "800",           // SAP client
                                         "develop",  // userid
                                         "bslabap", // password
                                         "EN",         // language
                                         "172.18.33.20",    // host name
                                         "00");
                    // Create a new repository
                    repository = JCO.createRepository("MYRepository", SID);
               }
               catch (JCO.Exception ex) {
                    System.out.println("Caught an exception: \n" + ex);
               }
          }
     //     Retrieves and sales order Create
     public void createSalesOrder(String PO_NO, String MAT,String RQTY,String CUSTMAT, String SOLD_NAME, String SOLD_STREET,String SOLD_COUNTRY, String SOLD_POST_CODE,String SHIP_NAME, String SHIP_STREET,String SHIP_COUNTRY, String SHIP_POST_CODE)
     {
         
          try {
               
               // Get a function template from the repository
               IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_SALESORDER_CREATEFROMDAT1");
               JCO.MetaData so_metadata = new JCO.MetaData("BAPI_SALESORDER_CREATEFROMDAT1");
               // Create a function from the template
               JCO.Function function = new JCO.Function(ftemplate);
             
               // Get a client from the pool
               JCO.Client client = JCO.getClient(SID);

               // Fill in input parameters
             
               // Header
               JCO.ParameterList input = function.getImportParameterList();
               JCO.ParameterList tables = function.getTableParameterList();
               JCO.Structure input_header = input.getStructure("ORDER_HEADER_IN");
               // Item details
               JCO.Table table_item = tables.getTable("ORDER_ITEMS_IN");
               //JCO.Structure input_item = table_item.getStructure("ORDER_ITEMS_IN");
             
               // Partner details
               JCO.Table table_partner = tables.getTable("ORDER_PARTNERS");
             
               // Populate the header details
               input_header.setValue("ZAD5","DOC_TYPE"); // Document Type
               input_header.setValue("3000","SALES_ORG"); // Sales Organization
               input_header.setValue("10","DISTR_CHAN");  // Distribution Channel
               input_header.setValue("00","DIVISION");  // Distribution Channel
               input_header.setValue("20041212","REQ_DATE_H");// can be changed in yyyymmdd (Requested date)
               input_header.setValue(PO_NO,"PURCH_NO_C");// can be changed ( Customer PO Number )
             
             
               //Populate the item detalis
               table_item.appendRow();
               table_item.setRow(1);
               table_item.setValue("000010","ITM_NUMBER");
               table_item.setValue("AA01","PO_ITM_NO");// can be changed
               table_item.setValue("IAD-SC3000","MATERIAL");
               table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
               table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
               table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
               table_item.appendRow();
               table_item.setRow(2);
               table_item.setValue("000020","ITM_NUMBER");
               table_item.setValue("AA01","PO_ITM_NO");// can be changed
               table_item.setValue("IAD-SC3000","MATERIAL");
               table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
              table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
               table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
               //Populate the Partner details
               // Sold to Party
               table_partner.appendRow();
               table_partner.setRow(1);
               table_partner.setValue("AG","PARTN_ROLE");
               //table_partner.setValue("0000002007","PARTN_NUMB");
               table_partner.setValue("0000100067","PARTN_NUMB");
               table_partner.setValue(SOLD_NAME,"NAME");  // can be changed
               table_partner.setValue(SOLD_STREET,"STREET"); // can be changed
               table_partner.setValue(SOLD_COUNTRY,"COUNTRY");
               table_partner.setValue(SOLD_POST_CODE,"POSTL_CODE"); // can be changed
         
               // Ship to party
              table_partner.appendRow();
               table_partner.setRow(2);
               table_partner.setValue("WE","PARTN_ROLE");
               table_partner.setValue("0000100067","PARTN_NUMB");
               table_partner.setValue(SHIP_NAME,"NAME");// can be changed
               table_partner.setValue(SHIP_STREET,"STREET"); // can be changed
               table_partner.setValue(SHIP_COUNTRY,"COUNTRY");
               table_partner.setValue(SHIP_POST_CODE,"POSTL_CODE");// can be changed
             
               // Call the remote system
               client.execute(function);
             
               // Print return message
               JCO.Structure ret = function.getExportParameterList().getStructure("RETURN");
               System.out.println("BAPI_SALES_ORDER_GETLIST RETURN: " + ret.getString("MESSAGE"));

               // Get table containing the orders
               //JCO.Table sales_orders = function.getTableParameterList().getTable("SALES_ORDERS");
              JCO.Field sales_order = function.getExportParameterList().getField("SALESDOCUMENT");
               // Print results
               String so = sales_order.getString();
               String message = ret.getString("MESSAGE");
               String message_type = ret.getString("TYPE");
               if  (message_type.equalsIgnoreCase("E"))  {
                    System.out.println("Error in Sales Order Creation:" + message);
               }
               else{
                    System.out.println("Sales Order " + so + " Created Succesfully");
                   
               }
                   
                // Release the client into the pool
               JCO.releaseClient(client);
          }
          catch (Exception ex) {
               System.out.println("Caught an exception: \n" + ex);
          }
     }
     //     Retrieves and sales order Create
      public void listSalesOrders()
      {
           try {

                // Get a function template from the repository
                IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_SALESORDER_GETLIST");

                // Create a function from the template
                JCO.Function function = new JCO.Function(ftemplate);

                // Get a client from the pool
                JCO.Client client = JCO.getClient(SID);

                // Fill in input parameters
                JCO.ParameterList input = function.getImportParameterList();

                //input.setValue("0000002007", "CUSTOMER_NUMBER"   );
                input.setValue(      "3000", "SALES_ORGANIZATION");
                //input.setValue(         "0", "TRANSACTION_GROUP" );
                //input.setValue("PO_NUMBER_JAVA01","PURCHASE_ORDER_NUMBER");

                // Call the remote system
                client.execute(function);

                // Print return message
                JCO.Structure ret = function.getExportParameterList().getStructure("RETURN");
                System.out.println("BAPI_SALES_ORDER_GETLIST RETURN: " + ret.getString("MESSAGE"));

                // Get table containing the orders
                JCO.Table sales_orders = function.getTableParameterList().getTable("SALES_ORDERS");

                // Print results
                if (sales_orders.getNumRows() > 0) {

                     // Loop over all rows
                     do {
                         counter++;
                          System.out.println("--
" + counter + "--
");
                   
                          // Loop over all columns in the current row
                          for (JCO.FieldIterator e = sales_orders.fields(); e.hasMoreElements(); ) {
                               JCO.Field field = e.nextField();
                               System.out.println(field.getName() + ":\t" + field.getString());
                          }//for
                     } while(sales_orders.nextRow());

                }
                else {
                     System.out.println("No results found");
                }//if

                // Release the client into the pool
                JCO.releaseClient(client);

           }
           catch (Exception ex) {
                System.out.println("Caught an exception: \n" + ex);
           }
      }

     public static void main(String[] argv) {
          SalesOrder so = new SalesOrder();
          //
          so.createSalesOrder("PO_NUMBER_JAVA02", "","0000000020000","121-223-2332-1231", "SOFTWARE SYSTEME GMBH-WE", "STREET-SH","US", "53125","SOFTWARE SYSTEME GMBH-WE", "STREET-SH","US", "53125");
          //so.listSalesOrders();  
    }
}






Java XML Parsers

What is XML Parsing?
Parsing XML refers to going through XML document to access data or to modify data in one or other way.

What is XML Parser?
XML Parser provides way how to access or modify data present in an XML document. Java provides multiple options to parse XML document. Following are various types of parsers which are commonly used to parse XML documents.
Dom Parser - Parses the document by loading the complete contents of the document and creating its complete hierarchical tree in memory.
When to use?
You should use a DOM parser when:
·         You need to know a lot about the structure of a document
·         You need to move parts of the document around (you might want to sort certain elements, for example)
·         You need to use the information in the document more than once

SAX Parser - Parses the document on event based triggers. Does not load the complete document into the memory.
When to use?
You should use a SAX parser when:
·         You can process the XML document in a linear fashion from the top down
·         The document is not deeply nested
·         You are processing a very large XML document whose DOM tree would consume too much memory.Typical DOM implementations use ten bytes of memory to represent one byte of XML
·         The problem to be solved involves only part of the XML document
·         Data is available as soon as it is seen by the parser, so SAX works well for an XML document that arrives over a stream
Disadvantages of SAX
·         We have no random access to an XML document since it is processed in a forward-only manner
·         If you need to keep track of data the parser has seen or change the order of items, you must write the code and store the data on your own


JDOM Parser - Parses the document in similar fashion to DOM parser but in more easier way.
When to use?
You should use a JDOM parser when:
·         You need to know a lot about the structure of a document
·         You need to move parts of the document around (you might want to sort certain elements, for example)
·         You need to use the information in the document more than once
·         You are a java developer and want to leverage java optimized parsing of XML.

Advantages

JDOM gives java developers flexibility and easy maintainablity of xml parsing code. It is light weight and quick API.

 StAX Parser - Parses the document in similar fashion to SAX parser but in more efficient way.
When to use?
You should use a StAX parser when:
·         You can process the XML document in a linear fashion from the top down.
·         The document is not deeply nested.
·         You are processing a very large XML document whose DOM tree would consume too much memory. Typical DOM implementations use ten bytes of memory to represent one byte of XML.
·         The problem to be solved involves only part of the XML document.
·         Data is available as soon as it is seen by the parser, so StAX works well for an XML document that arrives over a stream.
Disadvantages of SAX
·         We have no random access to an XML document since it is processed in a forward-only manner
·         If you need to keep track of data the parser has seen or change the order of items, you must write the code and store the data on your own

XPath Parser - Parses the XML based on expression and is used extensively in conjunction with XSLT.

DOM4J Parser - A java library to parse XML, XPath and XSLT using Java Collections  Framework, provides support for DOM, SAX and JAXP.
When to use?
You should use a DOM4J parser when:
You need to know a lot about the structure of a document
You need to move parts of the document around (you might want to sort certain elements, for example)
·         You need to use the information in the document more than once
·         You are a java developer and want to leverage java optimized parsing of XML.



Java Web services interview questions

What are web services?
Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). Web services provide a standard means of inter operating between software applications running on a variety of platforms and frameworks.

Main characteristics of the Web Services are:

1. Interoperability 
2. Extensibility
3. Machine process able descriptions.

What is the difference between SOA and a web service?
SOA (Service-Oriented Architecture) is an architectural pattern that makes possible for
services to interact with one another independently. 
Web Services is a realization of SOA concept, that leverages XML, JSON, etc. and common Internet protocols such as HTTP(S), SMTP, etc. 
SOA is a system-level architectural style that tries to expose business. WOA is an interface-level architectural style that focuses on the means by which these service capabilities are exposed to consumers.

What is SOAP?
SOAP (Simple Object Access Protocolis a transport protocol for sending and receiving requests and responses on XML format, which can be used on top of transport protocols such as HTTP, SMTP, UDP, etc. 

What is REST?
REST (REpresentational State Transfer) is an architectural style by which data can be transmitted over transport protocol such as HTTP(S).

What is the difference between a REST web service and a SOAP web service?
Below are the main differences between REST and SOAP web service
1.      REST supports different formats like text, JSON and XML; SOAP only supports XML;
2.      REST works only over HTTP(S) on a transport layer; SOAP can be used different protocols on a transport layer;
3.      REST works with resources, each unique URL is some representation of a resource; SOAP works with operations, which implement some business logic through different interfaces;
4.      SOAP based reads can’t be cached, for SOAP need to provide caching; REST based reads can be cached;
5.      SOAP supports SSL security and WS-security (Web Service-security); REST only supports SSL security;
6.      SOAP supports ACID (AtomicityConsistencyIsolationDurability); REST supports transactions, but it is neither ACID compliant nor can provide two phase commit.
How to decide which one of web service to use REST or SOAP? 
“REST vs SOAP” we can have rephrased to "Simplicity vs Standard". Of course, "Simplicity" with REST at most cases wins, it wins in performance, scalability and support for multiple data formats, but SOAP is favoured where service requires comprehensive support for security (WS-security) and transactional safety (ACID).

  What is WSDL?
WSDL (Web Services Description Language) is an XML format for describing web services and how to access them. 

  What is JAX-WS?
JAX-WS (Java API for XML Web Servicesis a set of APIs for creating web services in XML format.

 What is JAXB?
JAXB (Java Architecture for XML Binding) is a Java standard that defines how Java objects are converted from and to XML. It makes reading and writing of XML via Java relatively easy.

 Can we send soap messages with attachments?
Yes, we can send different formats such as PDF document, image or other binary file with soap messages as an attachment. Messages send using the binary data. SOAP messages is attached with MIME extensions that come in multipart/related.  
An example:
MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml;
        start=" javahungry.com>"
Content-Description: This is the optional message description.
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
..
..
--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: binary
Content-ID:

...binary TIFF image...
--MIME_boundary—

 What is MTOM?
MTOM (Message Transmission Optimization Mechanism) is a mechanism for transmitting large binary attachments with SOAP messages as raw bytes, allowing for smaller messages.

 What is XOP?
XOP (XML-binary Optimized Packaging) is a mechanism defined for the serialization of XML Information Sets that contain binary data, as well as deserialization back into the XML Information Set.

 What is a SOAP envelope element?
SOAP envelop element is the root element of a SOAP message which defines the XML document as a SOAP message.
An example:
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  ...
  Message information
  ...
 What does a SOAP namespace defines?
SOAP namespace defines the Envelope as a SOAP Envelope.
An example:
xmlns:soap=http://www.w3.org/2001/12/soap-envelope

 What is the SOAP encoding?
SOAP encoding is a method for structuring the request which is suggested within the SOAP specification, known as the SOAP serialization.

 What does SOAP encodingStyle attribute defines?
SOAP encodingStyle defines the serialization rules used in a SOAP message. This attribute may appear on any element, and is scoped to that element's contents and all child elements not themselves containing such an attribute. There is no default encoding defined for a SOAP message.
An example: 
SOAP-ENV:encodingStyle="http://www.w3.org/2001/12/soap-encoding"

 What are 2 styles web service’s endpoint by using JAX-WS?
1.      RPC (remote procedure call) style web service in JAX-WS; 
2.      document style web service in JAX-WS. 

 What is encoding rules for header entries? 
1.      a header entry is identified by its fully qualified element name, which consists of the namespace URI and the local name. All immediate child elements of the SOAP Header element must be namespace-qualified. 
2.      the SOAP encodingStyle attribute may be used to indicate the encoding style used for the header entries. 
3.      the SOAP mustUnderstand attribute and SOAP actor attribute may be used to indicate how to process the entry and by whom. 

 What is the wsimport tool? 
The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services: https://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

 What is the wsgen tool?
The wsgen tool is used to parse an existing web service implementation class and generates required files (JAX-WS portable artifacts) for web service deployment: http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsgen.html

 What is the difference between SOAP and other remote access techniques?
1.      SOAP is simple to use and it is non - symmetrical unlike DCOM or CORBA is highly popular and usually have complexity in them.
2.      SOAP provides greater platform independent with the language independence unlike DCOM or CORBA doesn't provide any of these.
3.      SOAP uses HTTP as its transport protocol and the data are being saved in XML format that can be ready by human, whereas DCOM or CORBA have their own binary formats that are used to transport the data in complicated manner.
4.      SOAP identify the object other than URL endpoint. SOAP objects are stateless and it is hard to maintain that. Whereas, it is not hard to maintain in case of other remote access techniques.

 What is a resource in a REST?
      A resource is a unique URL with representation of an object which we can get contents via GET and modify via PUT, POST, DELETE.

 What are HTTP methods supported by REST?
                  GET, POST, PUT, DELETE, OPTIONS, HEAD.

Whether can use GET request instead of POST to create a resource?
It is not possibly, because GET can’t change a resource.

 What is the difference between PUT and POST?
Need to use PUT when can update a resource completely through a specific resource. . If do not know the actual resource location for instance, when add a new article, can use POST. 
PUT is idempotent, while POST is not. It means if use PUT an object twice, it has no effect.

 What is WADL?
WADL (Web Application Description Language) is a XML description of a deployed RESTful web application. 

 What are frameworks available to implement REST web services? 
Jersey, Restlet, EasyRest, etc.

What is the Restlet framework?
Restlet is a lightweight, comprehensive, open source RESTful web API framework for the Java platform.
It has advantages such as
websocket and server-sent events support;
HTTP/2 support;
transparent HTTP PATCH support;
client cache service;
fluent APIs.

Q29 What is the Jersey framework?
Jersey is open source framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation. It has advantages such as 
1. contains support for Web Application Description Language (WADL); 
2. contains Jersey Test Framework which lets run and test Jersey REST services inside JUnit;   
3. supports for the REST MVC pattern, which would allow to return a View from Jersey services rather than just data.

 What is the RESTeasy framework?
RESTeasy is a JBoss project, which implements of the JAX-RS specification. It has benefits such as 
fully certified JAX-RS implementation; supports HTTP 1.1 caching semantics including cache revalidation; 
JAXB marshalling into XML, JSON, Jackson, Fastinfoset, and Atom as well as wrappers for maps, arrays, lists, and sets of JAXB Objects; 
OAuth2 and Distributed SSO with JBoss AS7; 
rich set of providers for: XML, JSON, YAML, Fastinfoset, Multipart, XOP, Atom, etc. 


What is the difference between AJAX and REST?
1.      Ajax, the request are sent to the server by using XMLHttpRequest objects; REST have a URL structure and a request/response pattern the revolve around the use of resources;
2.      Ajax eliminates the interaction between the customer and server asynchronously; REST requires the interaction between the customer and server;
3.      Ajax is a set of technology; REST is a type of software architecture and a method for users to request data or information from servers.

What tool are required to test REST services?
Firefox “poster” plugin for RESTFUL services. https://addons.mozilla.org/en-us/firefox/addon/poster/