Friday, 4 October 2019

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.x.test

When you are setting up a project for the first time with maven, you will end up getting the below error. your maven build may not success.

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test

INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.832s
[INFO] Finished at: Fri Oct 04 14:10:27 CDT 2019
[INFO] Final Memory: 40M/320M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project tm: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test failed: Unable to load the mojo 'test' in the plugin 'org.apache.maven.plugins:maven-surefire-plugin:2.10'. A required class is missing: org.apache.maven.plugin.surefire.SurefirePlugin
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.10
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy


Even if you try mvn clean install -U or force update the maven will not solve the problem . The issue will be mostly with the dependency maven-surefire-plugin, you might be using .

Update you maven dependency for maven-surefire-plugin as below, it will solve your problem .

 <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
        </plugin>

Then build your project, it will solve your problem.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.825s
[INFO] Finished at: Fri Oct 04 14:15:44 CDT 2019
[INFO] Final Memory: 44M/369M
[INFO] ------------------------------------------------------------------------



Hope this solves your problem .


Tuesday, 24 September 2019

MarketplaceDiscoveryStrategy failed with an error - Solved

If you get the error MarketplaceDiscoveryStrategy failed with an error, please follow the below steps to solve this issue.


Navigate to Windows->preferences-General-> Network Connection and select the option Direct and click on Apply and ok . Then try Eclipse market place .



Monday, 9 September 2019

Difference between Statement, prepared Statement and Callable Statement


Statement:  

Statement is used to execute normal SQLs , it won't take any parameters. Generally preferable for DDL statements and normal SQLs without any parameters. 

Statement st=conn.createStatement();
st.execute("create table tableA (columnA int not null, columnB varchar(255) )");

Prepared Statement:

Prepared statement is used to execute dynamic SQLs with parameters, it extends Statement interface.
If you are executing the same query multiple times, its preferable to use to the prepared statement , since it pre-compiles the statements

PreparedStatement prepStmt= conn.prepareStatement("update tableA set column1=? where column2=?");

prepStmt.setString(1, "test");  
prepStmt.setInt(2, 444);


Callable Statement: Execute a call to a database stored procedure. it extends statement interface . It allows the user to send parameters to procedure and retrieve the data from procedure.


CallableStatement cStmt= conn.prepareCall("call procA(?,?,?)")
cStmt.setString(1,"test");
cStmt.setInt(2,444);
cStmt.registerOutParameter(3);
cStmt.execute();

Tuesday, 3 September 2019

OOPS concepts and exmples

Object Oriented programs and concepts 


What is Object oriented program 



Object oriented program is the concept of the principle that works objects are most important of  a program that users are building. An object is set of  variables, methods  and objects. Manipulating the objects to get the result is the aim of object oriented program.

OOPS Concepts 

Class 
Object 
Inheritance 
Abstraction
Encapsulation
Polymorphism 
Association 
Aggregation
Composition 

Class  :

A class is user defined blueprint or prototype  for which the objects are created. It can simply say combination of variables , methods and other objects .


Object:

Object is self contained component which consists of method and variables which makes particular type of data is useful to user. In simple terms Object is the instantiation of a class , which is ready to use for a purpose .

Inheritance:

Inheritance, is the concept of acquiring/getting/using  the properties of another object in one object, basically creating  parent child relationship between classes. 

the keyword extends used to inherit the properties . Class A extends B means , all the properties of B can be used in Class A.

Abstraction:

Inheritance Abstraction is the process by which the data and programs are defined with representation while hiding the implementation details.
In simple terms , Abstraction is  to hide the information which is not relevant to others/other objects.

Encapsulation:

Wrapping data and methods within classes in combination with implementation hiding (through access specifiers/modifiers) is called encapsulation.  Encapsulation essentially has both  information hiding and implementation hiding.

Polymorphism:

Polymorphism is the ability by which, the functions or reference variables which behaves differently in different programmatic context.

two types of polymophisms available:

Compile time polymorphism (static binding or method overloading)
Run-time polymorphism (dynamic binding or method overriding)

Association:

Association is the concept of building relationship between two classes , but the association defined as is a relation or has a relation between classes .

Aggregation:

Aggregation is the concept of having relationship only in one direction .

Composition :

Composition is the type of both directional relationship. Object A to B and B to A , if the Object A is not defied Object B will not exist and Object B is not defined Object A will not exist. 







Monday, 26 August 2019

How to send file with secure web service

We might have called many secure/plain web services with tokens/without tokens. But sending a file to secure web service with token is little tricky,  follow the below simple steps to invoke a secure web service with token and send file .




//Create an object for OkHttpClient , this is available from java1.8
OkHttpClient client = new OkHttpClient();

// Create a file object for the file which you would like to send along with the web service call
File file= new File("D:\\test\\ExampleContacts_Hanuman.csv");

//Create the request body using MultipartBody and provide the files details to request body .
RequestBody formBody = new MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("file", file.getName(),
            RequestBody.create(MediaType.parse("text/plain"), file))
        .addFormDataPart("other_field", "other_field_value")
        .build();

// Bild the compelte request with URL , token and request body
Request request = new Request.Builder()
  .url("https://securewebservicewithFile********.com")
  .post(formBody)
  .addHeader("Content-Type", "multipart-formdata")
  .addHeader("x-api-token", "apitoekn*******")
  .addHeader("cache-control", "no-cache")
  .build();

// Invoke the request
Response response = client.newCall(request).execute();
//Verify the reponse ..
System.out.println(" response"+ response);



Its so simple to send file with OkHttpClient for secure web service.
Hope this will helpful.