Friday, July 21, 2017

Getting XML including the xml TAG

Sometime we need to extract some inner xml from the bigger xml, while parsing it.
One simple approach is to use the some String util (such as Apache commons etc.) and call stringBetween finction, but then it does not give you the parent tag and then you add the prefix and suffix the start and end tag respectively.

Alternatively you can use a mix of XQuery(to search the exact xml node) and then apply LS Serializer to get the inner xml or the sub xml as String.

In the below example of note xml, lets say we have to extract <attachments> xml. So, we will first try to get the node and then use LS Serailzer to get attachments.

The first piece of code, is the input, the second is the output we are looking for. And, the third one is the actual code.

So, that's it. Happy chopping the xmls! :) ;)




Saturday, June 24, 2017

Getting Http Header Param in Jersey (JAX-RS) Rest


How to read header parameter in Jersey REST - directly into a variable.



//contentType is the String variable which can be used later inside the method.
@GET
public Response getFirstUser(@HeaderParam("Content-Type") String contentType){

 ..
 ...
 System.out.println("content type:" + contentType)
  
 ..
  
}


There is one more way, by reading using @Context  HttpHeader (you can also use this in case you need to get multiple/all header parameters):

//All headers can be read by iterating over headers object.
@GET
public Response getFirstUser(@Context HttpHeaders headers){

  String contentType = headers.getRequestHeader("Content-Type");
  String userAgent= headers.getRequestHeader("user-agent").get(0);
  
  ...
  ... 
  
}





Thursday, June 8, 2017

View Unpushed Git Commits


Working from git command line, you want to check the commited but unpsuhed files. You can use below command:


git log origin/<branch_name>..HEAD

Replace <branch_name> with you feature branch name or the current branch name you are working with.

To create a alias inside you unix shell, you can put this alias inside your .profile or .bashrc file:

alias git-unpushed = !GIT_CURRENT_BRANCH=$(git name-rev --name-only HEAD); git log origin/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline

And, use git-unpushed from your git client command prompt.

Even better, if you want git client (on your machine) to remember an alias of your liking (that can be used as command later)

$ git config --global alias.unpushed'!GIT_CURRENT_BRANCH=$(git name-rev --name-only HEAD); git log origin/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline'

Then use git unpsuhed from your git client command prompt.

Saturday, April 1, 2017

Executor Service Example, for invoking multiple calls Parallelly

You may need to run a particular task (that can run independently) in parallel fashion in order to improve performance, or lets say, simulate a method call in multi-threaded environment:

Here is a example code snippet to do so:


Opinion on documentation

When to do documentation:

  • Nuggets of information, need to be referred by more people or more frequently - for example, Test Data, Deep links in different environment etc. 
  • It can speed up a new joiner's on-boarding. For example, some basic knowledge using which a developer can jump-start into building new feature and deploy stuff.
  • Something you feel you are likely to forget for example, an assumptions you were forced to made for whatever reason. 

When it comes to an API is used by different sets of users/clients, it needs to be documented properly. Otherwise, your consumers will either assume things, or, they will keep coming back to you with trivial questions, and that can result in low productivity on both provider's and consumer's end.

Look out for overdoing of documentations - its not good - rather, sometime its a waste of time and energy.


Monday, March 27, 2017

What you need to do to thrive in an Agile Software Development Team :)

1. The art of getting things done:
Building Software is a lot about how to get things done. Small wins are very important in initial days. Try to have targets in mind, small problems to solve, small features that can go into production.
2. Situational Awareness:
People (who is who), technology stack, way of working and cultural aspects of the team.
3. To do list:
You can follow this for time as ritual, or "deliberate practice".
Make a to do list twice, one for the present day and one for the next. Let your to do's become the engine of your initial days of growth.  
4.  Adaptability and self leadership:
You should always look for aligning your day to day tasks or activities to customer's goal or agenda.
Self leadership efforts to know your environment, to understand the way operation runs etc., comes handy when you are actually asked to deal with situations ranging from solving a technical problem to negating with customers or stakeholders.
5. Learning and early failures - Don't let silly mistake ruin your days after 6 months or an year. The early you make mistakes, the early you will have an opportunity to learn from your mistakes. Be courageous (doesn't mean act foolish, without knowing the context),
keep an open mind and learn little something everyday, until you are not comfortable enough.

Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...