Sunday, 21 February 2021

1.4 Java Web Services


 

JAX-RS Annotation

@Path

The @Path annotation is used to specify the URI through which a resource and an API can be accessed. Resource in this case is the REST Web service itself. @Path("/").


@Path("/message")

public class MessageReceiveService {


@Path("/birthday")

    public Response printBdayMessage(){


@GET - If service method is returning data based on client request.

@POST - If you want to store the data

@PUT -If you want to modify the data

@DELETE - If you want to delete 


@QueryParam

public String hello(@QueryParam("name1") String name, @QueryParam("age1") int age){

return "Hello ..."+name+" age="+age;

}

http://wwww.localhost:8080/appname/skeleton/helloService/hello?name1=bikesh&age1=32


@PathParam

 @Path("/helloService")

 public class HelloService{

@Path("sayHello/{name1}/{age}")

public String sayHello(@Pathparam("name1") String name, @QueryParam("age1") int age){

return "Hello ..."+name+" age="+age;

}

 }

 http://localhost:8080/webAppname/rest/helloService/sayHello/venkat/32


@MatrixParam

 It is similar to QueryParam but in URL variables will be seperated by semicoloun.

 

@FormParam

    @POST

    @Path("/add")

    public Response addUser(

        @FormParam("name") String name,

        @FormParam("age") int age) {


        return Response.status(200)

            .entity("addUser is called, name : " + name + ", age : " + age)

            .build();


    }

@Consumes annotation specifies the list of media types consumed by a particular API or class

Examples:

@Consumes("application/json")

@Consumes("application/xml")


@Produces annotation specifies the list of the media types produced by a particular API or class

Examples:

@Produces("application/json")

@Produces("application/xml")

Read More »

Wednesday, 17 February 2021

1.3 Web Services - JAX-WS


 

JAX-WS - It is a specification (API - contain set of interfaces)

It is having some Annotations

NOTE : Recommended approach is create interface and then implementation service class

In interfaces and implementation all three annotations are mandatory

1. @WebService

    This is mandatory annotation in I+C

    Example








Three optional properties are there

serviceName - default value will be - ServiceClassName (It should be unique)

targetNamespace - default value will be - package name in reverse order (It should be unique)

endpointInterface - default value will be - Fully qualified name of interface

2. @WebMethod (Optional)

If you want to give different name for method in wsdl then you can use it otherwise original method name will appear in wsdl file.

3. @WebParam (Optional)

If you want to give different nave for variables in wsdl then you can use it otherwise original variable name will appear in wsdl file.




 CLIENT APPLICATION FOR APACHE CFX



Read More »

Tuesday, 16 February 2021

1.2 Web Services - JAX RPC API - AXIS1 Implementation


NOTE : It doesn't support collection type methods
 

STEPS TO CREATE WEB SERVICE IN ECLIPSE





STEPS TO CREATE CLIENT



Read More »

Monday, 15 February 2021

1.1 WEB SEVICES - SUMMARY


 

What is Web Services - Sharing information between two application on internet is know as web services.

There are other options to share information

1. Socket Programming (Both App should be in java)

2. RMI - Remote Method Invocation (Both App should be in java)

3. EJB - Session beans and entity beans (Both App should be in java)

4. RPC - Remote Procedure Call (Both App should be in CPP)

5. CORBA - Common Object Request Broker Architecture (Multi language app supported)

6. DCOM  - Distributed communication  (Both App should be in .NET)


NOTE : CORBA is the 1st Specification which supported different language app com. support.

But Every implementation provider given their own specification because of which in some cases they fail to share information.


In technical terms Web Services are nothing but specification(Set of interfaces) i.e set of rules.

WSDL - Web Service Definition language

It contains 

1. Service Name

2. Operations

3. Parameters

4. Data Type

5. End point URL

NOTE : If you want to make your web service public you can register it to UDDI

UDDI stands for Universal Description, Discovery, and Integration.


WEB SERVICE ARCHITECTURE


1. WSDL generation tool will generate WSDL document from java service class

2. WSDL registration to UDDI registry to make it available publicly

3. WSDL document received by client

4. Stub class generation tool will create stub classes in respective programming language

5. Client will use stub classes to pass the parameters into request

6. XML request will form using stub classes

7. HTTP protocol will take SOAP request to service API

8. Soap request will be read by skeleton classes 

9. Service operation will get perform 

10. Soap response will sent back to client.

11. Stub classes will read the response from soap response

12. Reading soap response

13. response read

14. response will be given to client


synchronous response returns to the client in the same HTTP connection as the request. With asynchronous responses, a client can send multiple requests and receive the responses in subsequent connections.
















Read More »