ES6 Spread Operator


The spread operator, written with three consecutive dots ( … ), is new in ES6 and gives you the ability to expand, or spread, iterable objects into multiple elements.

Example 1: Array Elements Spread

const books = [“Mallik”, “Talks”, “Java”, “.com”];
console.log(…books);

output:

Mallik Talks Java .com

Example 2: Set Elements Spread

const primes = new Set([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]);
console.log(…primes);

Output:

2 3 5 7 11 13 17 19 23 29

If you look at the output from the examples, notice that both the array and set have been expanded into their individual elements. Sets are a new built-in object in javascript in ES6.

Tagged with: , , , , ,
Posted in ES6, JavaScript

ES6 for…of Example Program – Replace first letter of String with Uppercase


Below example iterates days array using for…of operation in ES6 and replaces the first character of the day with upper case.

/*
* Programming Quiz: Writing a For…of Loop (1-4)
*/

const days = [‘sunday’, ‘monday’, ‘tuesday’, ‘wednesday’, ‘thursday’, ‘friday’, ‘saturday’];

for (const day of days ){
console.log(day.charAt(0).toUpperCase() + day.slice(1));
}

Below is the Output of the Program:

Sunday

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday

Tagged with: , , , , ,
Posted in ES6, JavaScript

NgModule Properties in Angular 2


NgModule is a decorator function that takes a single metadata object whose properties describe the module. The most important properties are:

declarations – the view classes that belong to this module. Angular has three kinds of view classes: components, directives, and pipes.
exports – the subset of declarations that should be visible and usable in the component templates of other modules.
imports – other modules whose exported classes are needed by component templates declared in this module.
providers – creators of services that this module contributes to the global collection of services; they become accessible in all parts of the app.
bootstrap – the main application view, called the root component, that hosts all other app views. Only the root module should set this bootstrap property.

Source: https://angular.io/

Tagged with: , , , , ,
Posted in Angular

Components of Angular 2


Below are the major  components of Angular 2

Modules − This is used to break up the application into logical pieces of code. Each piece of code or module is designed to perform a single task.

Component − This can be used to bring the modules together.

Templates − This is used to define the views of an Angular JS application.

Metadata − This can be used to add more data to an Angular JS class.

Service − This is used to create components which can be shared across the entire application.

 

Tagged with: ,
Posted in Angular

Angular 2 Features


Angular 2 is a opensource javascript framework developed by developers at google. This framework is used to build the single page applications. Angular 2 has been built by considering the difficulties faced in Angular 1 and Angular 2 removes the obstucles in building single page applications.

Blow are the special features of Angular 2:

Components − Angular 2 is a componenent based framework where as Angular 1 is Controller based framework. Components help to build the applications into many modules. This helps in better maintaining the application over a period of time.

TypeScript − Angular 2 is based on TypeScript(a language for application scale JavaScript development). This is a superset of JavaScript that compiles to clean JavaScript output.

Services − Services are a set of code that can be shared by different components of an application. So for example if you had a data component that picked data from a database, you could have it as a shared service that could be used across multiple applications.

Tagged with: , , , , ,
Posted in Angular

Create Web service using wsgen in command line


Generally bottom up approach, where the service implementation is done first and wsdl will be generated next, is not a suggested way of implementing a web service. In some cases where the service implementation class is already exists in the application and wants to expose it as web service then it is acceptable to go with bottom up approach.

In this post, I would like to show how the web service can be developed in bottom up approach using the wsgen command.

The wsgen tool reads an existing web service implementation class and generates the required JAX–WS portable artifacts for web service development and deployment. The wsgen tool can be used for bottoms-up approach, where you are starting from a service endpoint implementation rather than a wsdl. The generated JAX-WS artifacts can be used by both service and client implementations.

Below is the sample service class created – HellowWorldService.java

package in.malliktalksjava.service;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(name=”HellowWorldService”,
targetNamespace=”http://malliktalksjava.in”,
wsdlLocation=”http://localhost:8085/HellowWorldService?wsdl”)
public class HellowWorldService{

@WebMethod
public void printHelloMessage(){
System.out.println(“Printing hello message”);
};

@WebMethod
public String getThankyouMessage(){
System.out.println(“Printing thank you message”);

return null;
};

}

Compile the java classes using below command:

javac -d . in/malliktalksjava/service/*.java

Once the compilation is successful, use the below wsgen command to generate the artifacts:

wsgen -verbose -keep -cp . in.malliktalksjava.service.HellowWorldService

Once click on the enter button, below are the artifacts generated in jaxws folder:

in\malliktalksjava\service\jaxws\GetThankyouMessage.java
in\malliktalksjava\service\jaxws\GetThankyouMessageResponse.java
in\malliktalksjava\service\jaxws\PrintHelloMessage.java
in\malliktalksjava\service\jaxws\PrintHelloMessageResponse.java

If it is required to generate the wsdl file along with the artifacts, we need to use the below command:

wsgen -verbose -keep -cp . -wsdl in.malliktalksjava.service.HellowWorldService

Below are the list of options available in wsgen command:

wsgenoptions

 

Tagged with: , , ,
Posted in JAVA

Differences between wsimport and wsgen


wsimport:
The wsimport tool reads a WSDL and generates all the required artifacts for web service development, deployment, and invocation. The wsimport tool supports the top-down approach to developing JAX-WS Web services, where you are starting from a wsdl.
The wsimport tool generated JAX-WS portable artifacts include Service Endpoint Interface (SEI), Service, Exception class mapped from wsdl:fault (if any), JAXB generated value types (mapped java classes from schema types) etc. These artifacts can be packaged in a WAR file with the WSDL and schema documents along with the endpoint implementation to be deployed.

Ex Command : wsimport http://localhost:8090/MyJaxWSService?wsdl

wsgen:
The wsgen tool reads an existing web service implementation class and generates the required JAX–WS portable artifacts for web service development and deployment. The wsgen tool can be used for bottoms-up approach, where you are starting from a service endpoint implementation rather than a wsdl.

Ex Command : wsgen -verbose -keep -cp . in.malliktalksjava.service.HellowWorldService

 

wsgen and wsimport generate request and response wrapper bean classes and the JAXB classes. However, wsgen generates the JAXB classes and put them in a jaxws folder. But wsimport does not put those classes in any folder instead in the current directory.

The JAX-WS artifacts generated can be used by both service implementation and client implementation.

Using wsgen you can also generate the wsdl using based on webservice implementation class.

Tagged with: , , , , , , ,
Posted in JAVA, Web Services

Create web service in Bottom Up approach using command line


Create Service Interface MyJaxWSSEI.java

package in.malliktalksjava.ws;

import in.malliktalksjava.ws.pojo.*;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

@WebService(name = “MyJaxWSHello”,
targetNamespace = “http://malliktalksjava.in”,
wsdlLocation = “http://malliktalksjava.in/MyJaxWS?wsdl”)
@SOAPBinding(style=Style.RPC, use=Use.LITERAL)
public interface MyJaxWSSEI {

@WebMethod(operationName=”getJXWsRes”)
@RequestWrapper(targetNamespace=”http://malliktalksjava.in/ws/types”,
className=”java.lang.String”)
@ResponseWrapper(targetNamespace=”http://malliktalksjava.in/ws/types”,
className=”in.malliktalksjava.ws.JXRes”)
@WebResult(targetNamespace=”http://malliktalksjava.in/ws/types”,
name=”JXWsRes”)
public JXRes getJXWsRes(
@WebParam(targetNamespace=”http://malliktalksjava.in/ws/types”,
name=”name”,
mode=Mode.IN)
String name
);

}

 

Create Implementation class for the above interface – MyJaxWSSEIImpl.java

package in.malliktalksjava.ws;

import in.malliktalksjava.ws.pojo.*;
import javax.jws.WebService;

@WebService(endpointInterface=”in.malliktalksjava.ws.MyJaxWSSEI”,
targetNamespace=”http://malliktalksjava.in”,
portName=”MyJaxWSSEIPort”,
serviceName=”MyJaxWSHelloService”)
public class MyJaxWSSEIImpl implements MyJaxWSSEI {

/**
* Default Constructor
*/
public MyJaxWSSEIImpl() {

}

/* (non-Javadoc)
* @see in.malliktalksjava.ws.MyJaxWSSEI#getJXWsRes(java.lang.String)
*/
@Override
public JXRes getJXWsRes(String name) {
JXRes jxRes = new JXRes();
jxRes.setMessage(“Hello”);
jxRes.setName(name);
return jxRes;
}

}

Create Required Model object JXRes.java

package in.malliktalksjava.ws.pojo;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class JXRes {
protected String message;
protected String name;
/**
*
*/
public JXRes() {
super();
}
/**
* @return the id
*/
public String getMessage() {
return message;
}
/**
* @param id the id to set
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

}

Create Main Class JXResTest.java

package in.malliktalksjava.ws.main;

import javax.xml.ws.Endpoint;
import in.malliktalksjava.ws.*;

public class JXResTest {
public static void main(String[] args ){
Endpoint.publish(“http://localhost:8080/MyJaxWSService”, new MyJaxWSSEIImpl());
}
}

 

Compile Java Classes in command prompt:

compileclass

Run the class

runmainclass

Verify the service : http://localhost:8080/MyJaxWSService?wsdl

wsdl

 

Tagged with: , , ,
Posted in JAVA, Web Services

Spring Security Namespace Designs


The namespace is designed to capture the most common uses of the framework and provide a simplified and concise syntax for enabling them within an application. The design is based around the large-scale dependencies within the framework, and can be divided up into the following areas:

  • Web/HTTP Security – the most complex part. Sets up the filters and related service beans used to apply the framework authentication mechanisms, to secure URLs, render login and error pages and much more.
  • Business Object (Method) Security – options for securing the service layer.
  • AuthenticationManager – handles authentication requests from other parts of the framework.
  • AccessDecisionManager – provides access decisions for web and method security. A default one will be registered, but you can also choose to use a custom one, declared using normal Spring bean syntax.
  • AuthenticationProviders – mechanisms against which the authentication manager authenticates users. The namespace provides supports for several standard options and also a means of adding custom beans declared using a traditional syntax.
  • UserDetailsService – closely related to authentication providers, but often also required by other beans.
Tagged with: , , , , , ,
Posted in Spring, Spring Security

SOAP Vs REST Web Services


SOAP REST
1) SOAP is a protocol. REST is an architectural style.
2) SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer.
3) SOAP can’t use REST because it is a protocol. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.
4) SOAP uses services interfaces to expose the business logic. REST uses URI to expose business logic.
5) JAX-WS is the java API for SOAP web services. JAX-RS is the java API for RESTful web services.
6) SOAP defines standards to be strictly followed. REST does not define too much standards like SOAP.
7) SOAP requires more bandwidth and resource than REST. REST requires less bandwidth and resource than SOAP.
8) SOAP defines its own security. RESTful web services inherits security measures from the underlying transport.
9) SOAP permits XML data format only. REST permits different data format such as Plain text, HTML, XML, JSON etc.
10) SOAP heavy weight operation. REST is light weight and suggested to use in lower band with scenarios such as accessing applications using mobile devices.
11) SOAP is less preferred than REST. REST more preferred than SOAP.
Tagged with: , , , , ,
Posted in Web Services

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 679 other followers

Calendar
January 2020
M T W T F S S
« Nov    
 12345
6789101112
13141516171819
20212223242526
2728293031  
Mallikarjun Gunda

This is Mallikarjun Gunda, I am working as a software professional. Blogging is my Passion. This blog contains the posts on Java related technologies and programming languages. I am happy to share my knowledge through the blogs.

Blog Stats
  • 323,826 hits
IndiBlogger
malliktalksjava.wordpress.c...
70/100