golang – input args

Input Args

Code to read the input args

Points :

  • This code reads input args and prints the sum of numbers in input args.
  • To read the input arguments, “os” package of golang is used.
  • All the arguments read are of type String. golang provides a conversion function Atoi to convert the string to integer. The Atoi function is in strconv package .

golang – array sum

Array Sum

Code to sum the integer elements in an array in golang



Spring SOAP Webservice – WSDL first

SOAP Webservice using Spring – WSDL first

Hello Readers ,

In this article we showed how to implement a simple web service using Spring framework. The article started with schema, schema generated classes, spring configuration and then java classes.

Often in real word applications, we get a wsdl and need to come up with a webservice implementation. One example is when we migrate an application from one technology to another.

This article shows how to implement a SOAP webservice with Spring framework and starting with wsdl.

  • Use Case  : Our sample web service takes 2 number as input and gives the sum as result.
  • Maven project : Create a maven project with standard directory layout
  • Define WSDL

  • Define pom.xml:

The maven defined the dependencies and jaxws-maven-plugin that converts the wsdl to java classes.

  • web.xml

  • spring-ws-servlet.xml

Note the use of static-wsdl element. This element defines the id and location of MathSercvice.wsdl

  • MathServiceEndPoint.java

The handle the incoming request , and endpoint classes has to be defined. This class defines various methods annotated with spring annotations which tells the framework what request will be handled by which method. Here is the code for MathServiceEndPoint:

The class is annotated by @Endpoint . The method is annotated by @SoapAction. The value defined with this annotation is same as defined for soap operation in wsdl.

Finally, the request and response parameters are annotated by @RequestPayload  and @ResponsePayload

Compile and deploy the generated war to tomcat server and the use any soap client like soap-ui to use the webservice .

If you have a github account, you can access the source code here : springws-two


mongoDB – basic commands

mongodb : basic commands

Note : This article assumes that mongodb has been installed. If it is not, please refer Install Mongodb

  • Running mongodb server:

To start the mongodb server, execute the command :

This will start the mongodb server on default port 27017 and create data directory on default locations based on OS used. On windows it is C:\data\db.

To specify a different data directory use –dbpath option with the mongod command.

The dbpath argument specifies the path where the data fie will be created.

For example , the following command

will start the mongodb server on default port 27017 and create data directory at location /home/codereq/mongodb/data

  • Running mongodb client

Execute the command  :

On executing the above command from the client,  you will see a log on server telling that a client has connected.

So , with the above 2 commands our basic setup is complete. Now we will see how to create a database.

  • Creating a database

mongodb comes with a default database called test

To create database , execute command

use <<database_name>>

For example executing command

will create database testdb01

Once the database is created, the current database is change to newly created one.

  1. To know which is the current database, execute the db command
  2. Note : Just after creating the database, show databases will not yet show the database. The database is shown only if there is any collection in the database.
  3. To drop the database use the following command

In the subsequent articles, we will show how to create collection, create documents some query commands.

Slice in golang


  • A Go Slice is a variable length, fixed capacity sequence of data of same type.
  • A Slice represents a view of an underlying array
  • It is more flexible and powerful than arrays.
  • It is passed as a reference to a function and is thus more efficient than array to pass to a function.

Slice Syntax:

  • make([]Type, length, capacity)
  • make([]Type, length)
  • []Type{}
  • []Type{value1, value2, …, valueN}

A Slice capacity is the length of underlying array and length is an amount upto capacity.

Here are some examples of how the slice is created :

Assume mainArray = […]{2,4,6,8,10,12,14,16,18,20}

  • sA := mainArray[2:5]; // sA returns [6,8,10]
  • sB := mainArray[3:]; //sB returns [8, 10,12,14,16,18,20]
  • sC := mainArray[:7]; //sC returns [2,4,6,8,10,12,14]
  • sD := make([]int, 3, 12); // This creates a sD of length 3 and elements initialized to 0.

Another important feature of slice is that though the it has data of a specific type, in practice it is not the case . This is because the type  could be an interface and any item implementing an interface can be stored in slice.

Declaring arrays in golang

golang arrays

Arrays are declared in following ways in golang :

Note that in the last example variable is preceded by var keyword and a4 is followed by =. This pattern is assignment operator.

:= is called short variable declaration which is initializer expression with no type.

Complete program for arrays :


CXF SOAP Webservice Implementation

CXF SOAP Webservice

This article on CXF SOAP Webservice explains how to implement a basic SOAP web service using CXF framework with minimal configuration. In this article we will use WSDL approach first, that means we would start with WSDL and then configure the various files .

To focus on basic configuration for cxf soap webservice, we will use a very simple PersonService wsdl which exposes createPerson service.

  • WSDL :


    This is the web.xml configuration for cxf soap webservice. In this, all URL patterns /* are mapped to a servlet named cxf which in turn is handled by CXFServlet

  • web.xml


This is the spring configuration file for cxf soap webservice and named after the servlet name <<servet-name>>-servlet.com. This configuration file configures jaxws:endpoint which defines address of the service to be exposed and class implementing the webservice interface. When the java classes are generated, it creates an interface PersonService. The PersonServiceImpl implements this interface.

  • cxf-servlet.com


To implement cxf soap webservice , we will use maven as our build tool and generate the java classes from wsdl using maven plugin. The plugin cxf-codegen-plugin is used for this purpose.

  • pom.xml : cxf plugin


This is how a cxf soap webservice can be implemented.

wsimport – wsdl source generator


Hello Readers,

As a part of implementing a webservice, wsdl source generator are used to convert a wsdl to Java Classes . These java classes can then be used in the application. The wsdl source generator are also used at the client side to generate the Java classes to consume the webservice.

This article shows how to use and configure the wsimport through maven build. Here is the pom configuration.

Important configuration for wsimport in this pom.xml

  • The build configuration uses jaxws-maven-plugin .
  • The wsimport is used in goal configuration
  • <sourceDestDir> : This is used to configure the source directory when the generated files will be placed.
  • <wsdlDirectory> : This is the directory location which tells where the wsdl is located
  • <wsdlLocation> : Name of the wsdl
  • <packageName> :  The name of package for the generated files
  • <keep> : This is a very important configuration which tells wsimport to keep the source files in the respective location.

More configuration parameters for wsimport can be found here : here

Here is the UserService.wsdl that is used for the above configuration :



Basic Scala Arrays

Scala Arrays

Hello Readers ,

Basic Scala Arrays show some usage of basic arrays in Scala. The article shows 3 different usages of Arrays on 3 different data types. This in no way is comprehensive data type scenarios but show how the arrays are used in Scala.

  • The first function, showNumberArrays, shows the usage of Scala arrays with number.
  • The second function, showStringArrays, shows how array of String is used.

In both the function, different ways to iterate over the arrays are used.

  • The third function shows how array of custom object is used.

In the coming articles, some more usage of array APIs will be shown

golang – reading file

Dear Readers ,

The golang – reading file shows how a file can be read in golang . The file, quotes.txt, is located at the same location where the code file is located. The golang – reading file code snippet here uses the os package to open the file and then file operations to read the file. The code also handles error condition if the file does not exist or if the contents of the file does not exists.