Sabtu, 25 Februari 2017

What is WSDL and difference between abstract and concrete WSDL

An official W3C standard, the Web Services Description Language (WSDL) is an XML language for describing web services. WSDL 1.1 (which is still in wide use) has five major elements--types, message, portType, binding, and service.  All these major elements may be defined 0 or more times in a WSDL document, except for <types>, which may be 0 or 1 time. Here's a short description of each:

types: This is where XML types to be used in the WSDL document are defined. Traditionally, this has meant using XML Schema, but newer versions of WSDL also support Relax NG.

message: This is the section where the input or output parts of an operation are defined, i.e. the "parameters" or "return types". It may have multiple child <part> elements, though WS-I forbids the use of more than one part per message in a document literal style service. The <part> itself may have an element (referring to a qualified XML element) or a type (referring to an XML Schema type) attribute.

portType: Here is where the operations that a web service offers are defined in terms of messages (input and output, with faults). Faults (referring to SOAP faults here) are the web service equivalent of the exception in languages like C++ or Java; most SOAP toolkits will translate SOAP faults into exceptions at runtime.

binding: This is the "how" of a service, specifying the binding of the operations defined in the portType(s) to specific protocols, such as SOAP.

service: This is the "where" of the service, specifying the address where a bound operation may be found.

Example of WSDL document:

 <?xml version="1.0" encoding="UTF-8" ?>
<definitions targetNamespace="urn:Emp" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:Emp"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:weo="http://www.example.org">
<types>
<xsd:schema targetNamespace="urn:Emp/types" elementFormDefault="qualified"/>
<xsd:schema>
<xsd:import schemaLocation="../Schema/Emp.xsd" namespace="http://www.example.org"/>
</xsd:schema>
</types>
<portType name="EmpDetailsPort">
<operation name="EmpRequestOperation">
<input message="tns:EmpDetailsPort_EmpRequest"/>
<output message="tns:EmpDetailsPort_EmpResponse"/>
</operation>
</portType>
<message name="EmpDetailsPort_EmpRequest">
<part name="part" element="weo:EmpRequest"/>
</message>
<message name="EmpDetailsPort_EmpResponse">
<part name="part" element="weo:EmpResponse"/>
</message>
<binding name="EmpDetailsPortSOAP11Binding" type="tns:EmpDetailsPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="EmpRequestOperation">
<soap:operation style="document" soapAction="urn:Emp/EmpRequestOperation"/>
<input>
<soap:body use="literal" parts="part"/>
</input>
<output>
<soap:body use="literal" parts="part"/>
</output>
</operation>
</binding>
<service name="EmpDetailsPort">
<port name="EmpDetailsPortPort" binding="tns:EmpDetailsPortSOAP11Binding">
<soap:address location="http://www.example.com"/>
</port>
</service>
</definitions>


Abstract and Concrete WSDLs


A WSDL document can be divided into "abstract" and "concrete" portions that by convention often are defined in two or more files (where the concrete file imports the abstract one). The abstract elements are <types>, <message>, and <portType> (or <interface> in 2.0); the concrete ones are <binding> and <service>. Separating these two sections allows for maximal reuse and flexibility in defining services.


How to increase heap size of the integrated server in JDeveloper 12c

Sometimes there may be a need to increase the heap size of the integrated weblogic server within JDeveloper. Obviously one can modify the setDomainEnv file in the domain’s bin directory.

Check the blog if you want to increase the heap size using setDomainEnv file.

You can also change it within JDeveloper, you can do this with the help of below steps:

Note: Before applying these setting, all the application should be closed in the jdevloper.

1) Open the application servers using Window -> Application Servers menu


2) Right click on Integrated Weblogic Server -> Properties.

3) A popup will get open. Go the the Launch Settings tab, Click on More Launch Settings -> Environment Variable and click New

Enter the USER_MEM_ARGS in name and -Xms4096 -Xmx4096m -XX:MaxPermSize=4096m  in value field. You can enter the max and min size as per you requirement. Click OK -> Ok -> Ok


4) Now start the server and see the heap size got changed.


Increasing the Java Heap size for a Admin Server & managed server in Weblogic

For better performance, we may need to increase the heap size for each Managed Server in our environment.

As per performance tuning guidelines it is good practice to start Admin server with lower JVM heap size than your other managed servers because the Admin server doesn't required much resources.
By doing this you can utilize the free memory with others where it is needed (This makes sense when you are running Admin and Managed servers on same host)

The size is set in the setDomainEnv.sh file for Linux or setDomainEnv.cmd for Windows, which is in the $DOMAIN_HOME/bin directory.

Steps to set the heap size for Admin and managed server:

1. Shutdown Admin and Managed servers

2. Take backup of setDomainEnv.sh or setDomainEnv.cmd file in case something goes wrong, you can revert the changes. It is best practice to take backup before you made changes in the servers.

3. Open  setDomainEnv file that is under the  $DOMAIN_HOME/bin directory.

4. Copy and paste the below lines in the setDomainEnv file. Make sure you paste the below line at suitable location.

 
#In case of Admin Server

if [ "${SERVER_NAME}" == "AdminServer" ] ; then
USER_MEM_ARGS="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m"
export USER_MEM_ARGS
fi

#In case of osb_server1 Server

if [ "${SERVER_NAME}" == "osb_server1" ] ; then
USER_MEM_ARGS="-Xms512m -Xmx4096m -XX:MaxPermSize=4096m"
export USER_MEM_ARGS
fi


 Xms: The initial heapsize
 Xmx: The max heapsize

5. Start the Admin server and Managed server.

6. Verify the changes via weblogic console or in logs.


Prototype Design Pattern

In the prototype pattern, a new object is created by cloning an existing object. The prototype pattern can be a useful way of creating copies of objects.

One example of how this can be useful is, if an original object is created with a resource such as a data stream that may not be available at the time that a clone of the object is needed.  Another example is if the original object creation involves a significant time commitment, such as reading data from a database or over a network.


Advantages of Prototype Design Pattern


  • It reduces the need of sub-classing.
  • It hides complexities of creating objects.
  • The clients can get new objects without knowing which type of object it will be.
  • It lets you add or remove objects at runtime.

Usage of Prototype Pattern


  • When the classes are instantiated at runtime.
  • When the cost of creating an object is expensive or complicated.
  • When you want to keep the number of classes in an application minimum.
  • When the client application needs to be unaware of object creation and representation.

Let's see with the help of an example how to implement prototype desing pattern. To do so, we'll create a Prototype interface that features a cloning() method.

       
package com.rd;

public interface Prototype {

Prototype cloning();
}

       
package com.rd;

public class WeatherInfo implements Prototype {

private double temprature;
private String state;


public WeatherInfo(double temprature, String state) {
super();
this.temprature = temprature;
this.state = state;
}

public void showWeatherInfo(){
System.out.println(state+" temprature is "+temprature);
}


@Override
public Prototype cloning() {
return new WeatherInfo(temprature,state);
}

}

       
package com.rd;

public class PrototypeDemo {

public static void main(String[] args) {

WeatherInfo weatherInfo = new WeatherInfo(17, "Delhi");
weatherInfo.showWeatherInfo();

WeatherInfo cloneObject = (WeatherInfo)weatherInfo.cloning();
cloneObject.showWeatherInfo();
}

}


Factory Method Pattern

A Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. In other words, subclasses are responsible to create the instance of the class.

Advantage of Factory Design Pattern

  • Factory Method Pattern allows the sub-classes to choose the type of objects to create.
  • It promotes the loose-coupling by eliminating the need to bind application-specific classes into the code. 


Use of Factory Design Pattern

  • When a class doesn't know what sub-classes will be required to create
  • When a class wants that its sub-classes specify the objects to be created.
Let's see with the help of an example. Let's create a MobileFactory class that will return an instance of MobileType(Android, IOS, Windows) object.

package com.rn;

public abstract class MobileType {

public abstract String mobileType();
}
package com.rn;

public enum Mobile {
ANDROID, IOS,WINDOWS;
}
package com.rn;

public class Android extends MobileType {

@Override
public String mobileType() {
return "Gretting from Android, Mobile request taken and in process..";

}

}
    
package com.rn;

public class IOS extends MobileType {

@Override
public String mobileType() {
return "Gretting from IOS, Mobile request taken and in process..";
}

}

       
package com.rn;

public class Windows extends MobileType {

@Override
public String mobileType() {
return "Gretting from Windows, Mobile request taken and in process..";
}

}
       
package com.rn;

public class MobileFactory {

public MobileType prepareMobile(String mobile){
if(mobile.equals(Mobile.ANDROID.toString())){
return new Android();
}else if(mobile.equals(Mobile.IOS.toString())){
return new IOS();
}else if(mobile.equals(Mobile.WINDOWS.toString())){
return new Windows();
}
return null;
}
}
       
package com.rn;

public class ManufactureMobile {

public static void main(String args[]){

MobileFactory mobileFactory = new MobileFactory();
MobileType mobile = mobileFactory.prepareMobile(Mobile.ANDROID.toString());
System.out.println(mobile.mobileType());

mobile = mobileFactory.prepareMobile(Mobile.IOS.toString());
System.out.println(mobile.mobileType());

mobile = mobileFactory.prepareMobile(Mobile.WINDOWS.toString());
System.out.println(mobile.mobileType());
}
}

Run the ManufactureMobile.java and see the output:




Download the project from here

Singleton design pattern in java

Singleton Pattern says that just"define a class that has only one instance and provides a global point of access to it".

In other words, a class must ensure that only single instance should be created and single object can be used by all other classes.

Advantages of Singleton design pattern


Memory saving: Saves memory as object is created only once for all request. Single instance is used again and again.

Usage of Singleton design pattern


It's used in
  • Mutlti threaded application
  • Database application

It is used in logging, caching, thread pools, configuration settings etc.

How to create Singleton design pattern ?


To create the singleton class, we need to have static member of class, private constructor and static factory method.
  • Static member: It gets memory only once because of static, it contains the instance of the Singleton class.
  • Private constructor: It will prevent to instantiate the Singleton class from outside the class.
  • Static factory method: This provides the global point of access to the Singleton object and returns the instance to the caller.


Types of  singleton design pattern


There are two types of singleton design pattern:
  • Early Instantiation: Creation of instance at load time.
  • Lazy Instantiation: Creation of instance when required.

Early Instantiation Example:
package com.rd;

public class SingletonPattern {

private static SingletonPattern object= new SingletonPattern(); //at load time
private SingletonPattern(){

}
public static SingletonPattern getInstance(){
return object;
}

public void sayHi(String name){
System.out.println("Hi "+name);
}
}
package com.rd;

public class TestSingleton {

public static void main(String[] args) {
SingletonPattern object = SingletonPattern.getInstance();
object.sayHi("Ankur");

}

}

Lazy Instantiation Example:

package com.rd;

public class SingletonPattern {

private static SingletonPattern object= null;
private SingletonPattern(){

}
public static SingletonPattern getInstance(){
if(object==null){
object = new SingletonPattern(); // at request time
}
return object;
}

public void sayHi(String name){
System.out.println("Hi "+name);
}
}

package com.rd;

public class TestSingleton {

public static void main(String[] args) {
SingletonPattern object = SingletonPattern.getInstance();
object.sayHi("Ankur");

}

}



Design Patterns in java

Design Patterns are very popular among software developers. A design pattern is a well described solution to a common software problem.

Sensible use of design patterns results in increased code maintainability, since in addition to being a good solution to a common problem, design patterns can be recognized by other developers, thus reducing the learning curve when dealing with a particular piece of code.
Some of the benefits of using design patterns are:

  • Design Patterns are already defined and provides industry standard approach to solve a recurring problem, so it saves time if we sensibly use the design pattern. There are many java design patterns that we can use in our java based projects.
  • Using design patterns promotes reusability that leads to more robust and highly maintainable code. It helps in reducing total cost of ownership (TCO) of the software product.
  • Since design patterns are already defined, it makes our code easy to understand and debug. It leads to faster development and new members of team understand it easily.

Types of design patterns include creational, structural, and behavioral design patterns.

Creation Design Pattern

Creational design patterns provide solution to instantiate a object in the best possible way for specific situations. These includes:
  • Singleton Pattern
  • Factory Pattern
  • Abstract Factory Pattern
  • Builder Pattern
  • Prototype Pattern

Structural Design Pattern

Structural patterns provide different ways to create a class structure, for example using inheritance and composition to create a large object from small objects. These includes:
  • Adapter Pattern
  • Composite Pattern
  • Proxy Pattern
  • Flyweight Pattern
  • Facade Pattern
  • Bridge Pattern
  • Decorator Pattern

Behavioral Design Pattern

Behavioral patterns provide solution for the better interaction between objects and how to provide lose coupling and flexibility to extend easily. These includes:
  • Template Method Pattern
  • Mediator Pattern
  • Chain of Responsibility Pattern
  • Observer Pattern
  • Strategy Pattern
  • Command Pattern
  • State Pattern
  • Visitor Pattern
  • Interpreter Pattern
  • Iterator Pattern
  • Memento Pattern


Follow the blogs for the example:


Singleton design pattern


Factory Method Pattern


Prototype Design Pattern