REST Web Services

REST Web Services:

Java Web Services

Java web administrations instructional exercise gives ideas and cases of two primary java web administrations programming interface. REST of JAX-WS and REST of JAX-RS. The java web benefit application can be gotten to by other programming dialects, for example, .Net and PHP.JAX-WS instructional exercise is gives ideas and cases of JAX-WS API. This JAX-WS instructional exercise is intended for amateurs and experts.

Java web benefit application performs correspondence through WSDL (Web Services Description Language). There are two essential for java web benefit source code: SOAP and RESTful.

Java Web Services API

There are two essential API’s portrayed by Java for making web advantage applications since JavaEE6.

1) JAX-WS: for SOAP web organizations. The two ways to deal with form JAX-WS application code: by RPC style and Document style.

2) JAX-RS: for RESTful web organizations. There are generally 2 utilizations at this moment being utilized for making JAX-RS application: Jersey and REST simple.

JAX-WS is provides concepts and examples of JAX-WS API. This JAX-WS tutorial is designed for beginners and professionals.

RPC style:

  • RPC style web services use method name and parameters to generate XML structure.
  • The generated WSDL is difficult to be validated against schema.
  • In RPC style, SOAP message is sent as many elements.
  • RPC style message is tightly coupled.
  • In RPC style, SOAP message keeps the operation name.
  • In RPC style, parameters are sent as discrete values.

WSDL file:

In WSDL file, it doesn’t specify the type details.

JAX-WS Example RPC Style:

Making JAX-WS illustration is a simple errand since it requires no additional design settings.JAX-WS API is inbuilt in JDK, so you don’t have to stack any additional jug petition for it.

There are made 4 records for hi world JAX-WS illustration

HelloWorld.java

HelloWorldImpl.java

Publisher.java

HelloWorldClient.java

The initial 3 documents are made for server side and 1 application for customer side.

JAX-WS Server Code
File: HelloWorld.java:

 package com.javaspot;

import javax.jws.WebMethod;

import javax.jws.WebService;

import javax.jws.soap.SOAPBinding;

import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface

@WebService

@SOAPBinding(style = Style.RPC)

public interface HelloWorld{

@WebMethod String getHelloWorldAsString(String name);

}

File: HelloWorldImpl.java:

 package com.javaspot;

import javax.jws.WebService;

//Service Implementation

@WebService(endpointInterface = “com.javatpoint.HelloWorld”)

public class HelloWorldImpl implements HelloWorld{

@Override

public String getHelloWorldAsString(String name) {

return “Hello World JAX-WS ” + name;

}

}

File: Publisher.java:

 package com.javaspot;

import javax.xml.ws.Endpoint;

//Endpoint publisher

public class HelloWorldPublisher{

public static void main(String[] args) {

Endpoint.publish(“http://localhost:7779/ws/hello”, new HelloWorldImpl());

}

}

How to view generated WSDL

After running the publisher code, you can see the generated WSDL file by visiting the URL

http://localhost:7779/ws/hello?wsdl

JAX-WS Client Code

 File: HelloWorldClient.java

 package com.javaspot;

import java.net.URL;

import javax.xml.namespace.QName;

import javax.xml.ws.Service;

public class HelloWorldClient{

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

URL url = new URL(“http://localhost:7779/ws/hello?wsdl”);

QName qname = new QName(“http://javaspot.com/”, “HelloWorldImplService”);

Service service = Service.create(url, qname);

HelloWorld hello = service.getPort(HelloWorld.class);

System.out.println(hello.getHelloWorldAsString(“javaspot rpc”));

}

}

 JAX-WS Example Document Style:

Like RPC style, we can make JAX-WS case in report style. To do as such, you have to change just a single line in benefit interface.

You have to utilize Style.DOCUMENT for @SOAPBinding comment set up of Style.RPC.

Document: HelloWorld.java

@SOAPBinding(style = Style.DOCUMENT)//It is changed from RPC to DOCUMENT

Presently Let’s see the full case of JAX-WS in record style.

There are made 4 records for hi world JAX-WS archive style case.

HelloWorld.java

HelloWorldImpl.java

Publisher.java

HelloWorldClient.java

The initial 3 records are made for server side and 1 application for customer side.

JAX-WS Server Code

 File: HelloWorld.java:

 package com.javaspot;

import javax.jws.WebMethod;

import javax.jws.WebService;

import javax.jws.soap.SOAPBinding;

import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface

@WebService

@SOAPBinding(style = Style.DOCUMENT)

public interface HelloWorld{

@WebMethod String getHelloWorldAsString(String name);

}

File: HelloWorldImpl.java:

 package com.javaspot;

import javax.jws.WebService;

//Service Implementation

@WebService(endpointInterface = “com.javaspot.HelloWorld”)

public class HelloWorldImpl implements HelloWorld{

@Override

public String getHelloWorldAsString(String name) {

return “Hello World JAX-WS ” + name;

}

}

File: Publisher.java:

 package com.javaspot;

import javax.xml.ws.Endpoint;

//Endpoint publisher

public class HelloWorldPublisher{

public static void main(String[] args) {

Endpoint.publish(“http://localhost:7779/ws/hello”, new HelloWorldImpl());

}

}

Now, it will generator 2 files:

  • SayHello
  • SayHelloResponse

Paste these files in com.javaspot directory and then run the publisher class.

JAX-WS Client Code
File: HelloWorldClient.java:
package com.javaspot;

import java.net.URL;

import javax.xml.namespace.QName;

import javax.xml.ws.Service;

public class HelloWorldClient{

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

URL url = new URL(“http://localhost:7779/ws/hello?wsdl”);

QName qname = new QName(“http://javaspot.com/”, “HelloWorldImplService”);

Service service = Service.create(url, qname);

HelloWorld hello = service.getPort(HelloWorld.class);

system.out.println(hello.getHelloWorldAsString(“javaspot document”));

}

}

Drop Us A Query

Trending Courses
  • Python and Django Online Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

  • Tableau Online Training
  • Tableau is a Software company that caters interactive data visualization products that provide Business Intelligence services. The company’s Head Quarters is in Seattle, USA.

  • MicroStrategy Online Training
  • Micro Strategy is one of the few independent and publicly trading Business Intelligence software provider in the market. The firm is operational in 27 Countries around the globe.

  • PEGA (PRPC) 7.2 Certification Online Training
  • Pega Systems Inc. is a Cambridge, Massachusetts based Software Company. It is known for developing software for Customer Relationship Management (CRM) and Business process Management (BPM).

  • Workday Online Training
  • Workday specialises in providing Human Capital Management, Financial Management and payroll in online domain.It is a major web based ERP software vendor.

  • Power BI Online Training
  • Power BI is business analytics service by Microsoft. With Power BI, end users can develop reports and dashboards without depending on IT staff or Database Administrator.


100% Secure Payments. All major credit & debit cards accepted.