Posts

MSSQL server audit

MSSQL Server Auditing on AWS RDS Enable MSSQL Server Auditing on AWS RDS To enable MSSQL server auditing on AWS RDS, please follow these steps: Login to AWS console and go to RDS. Create an option group under RDS > Option groups Give name as 'SqlServerAudit' Provide description as 'Option group for SQL Server audit' Choose the engine as same as the one used while creating the database in RDS. Choose the latest engine version. Save. Go to RDS > Option groups and select the radio button on the option group you just created Click on Add Option. Select SQLSERVER_AUDIT under “Option name” Choose the S3 bucket name where you want to keep the audit files once they grow more than the specified limit. Choose the appropriate IAM role with write access to the S3 bucket. Scheduling > Immediately and then click on “Add Option“.

Circuit breaker implementation in spring boot2

Image
What is it Circuit breaker is a design pattern used in modern software development. It is used to detect failures and encapsulates the logic of preventing a failure from constantly recurring, during maintenance, temporary external system failure or unexpected system difficulties. The Circuit breaker pattern helps to prevent such a catastrophic cascading failure across multiple systems. The circuit breaker pattern allows you to build a fault tolerant and resilient system that can survive gracefully when  key services are either unavailable or have high latency. White box libraries There are many libraries which claim that they have successfully implemented the Circuit Breaker Design Pattern. Few of them are: Hystrix : Opensource Library designed by Netflix. This is the best library available as of today but it  is no longer in active development, and is currently in maintenance mode. Because of this reason we have kept it out from our scope. Sentinel : Opensource Library designe

Writing custom transformers in Mule

Image
Hello Coder, As soon as we start writing Mule flows we need to do the conversion of data from one form to another and that is how a message (request-response) flow in any application works. For example if we are writing endpoints for a mobile application, our server receives a request in some specified format say XML and it need to give response in other format say JSON. So what we will do in this case is to first parse the request XML to a String and then to a Java object or will use some 3rd party library which will do this transformation for us. Same applies to the response also. The work seems reasonable if the endpoints are less but what if we need to provide 1000 endpoints to a mobile application ? Are we going to do this repeated process of transformation ? NO. That's where Mule wins the race because it provides inbuilt transformers which will do the conversion. In this tutorial we will focus on Mule Custom Transformers. First we will understand what are transformers in Mule

Log the SOAP request xml in Mule flow

Hello Reader, Recently I came across in a situation where I wanted to see the actual SOAP request xml which was sent to Mule endpoint. I tried adding a Logger component as advised on mulesoft blog but the request was not getting logged. So I did some hit and trials in the Mule flow mentioned here to finally make the SOAP request xml print in the logs. Below is what I did to success : 1. In Anypoint studio, searched for logger component from right pane and dropped it just before the SOAP component. 2. In the "Mule Properties View" of this component, put #[payload] against "message" textbox. This text box is to log whatever you want to log using this component. Since we want whole xml to be logged hence we will use #[payload] 3. Save and run the Mule application. 4. Call the Mule SOAP endpoint using your favorite tool like SOAPUI. 5. You will see below logging in the logs INFO 2015-04-01 17:11:19,307 [[soap-ws-mule].Connector_Config.worker.01] org.mule.api.proces

Writing junit test case to test Mule flow

Image
Hello Coder, In my last post we learned to create a SOAP server in Mule. We created a Mule flow and ran it inside Anypoint studio. As the flow grows there is more need of unit as well as integration testing. Testing of a service/dao or any other component is fairly simple, in complex scenarios where services are injected using Spring there we can mock the services and inject them while running a JUnit test case. But how can we test a mule-flow xml and ensure that everything works as expected ? In this post we will learn to write a JUnit test case to test your Mule flow. We will use mule's testing framework to create test classes. In order to proceed you need to have basic knowledge about JUnit test cases and you should know how mule flow works. We will write the test case for the flow mentioned in our previous post mentioned here .

Unmarshall SOAP Message (XML) to Java Object using JAXB

Hello Visitor, In this blog post I will guide you to Unmarshall the SOAP message using JAXB to your Java Object. You might have already tried it and some of you have got the below exception when unmarshalling a soap message, then this post will help you recovering the unmarshall error. javax.xml.bind.UnmarshalException: unexpected element  (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{}Envelope> Here is the SOAP message which we want to unmarshall to Java object:    <soap:envelope xmlns:ns1="http://mynamespace.com/ns1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <ns1:updatemydetails> <ns1:items> <ns1:id>1</ns1:id> <ns1:name>crazy coders</ns1:name> <ns1:email>crazycoders4u@gmail.com</ns1:email>

Mule - Bypass all requests through proxy like Charles

Hello, Many times during development of a Mule application we need to see the request and response which Mule receives/sends to another flow/endpoint. Its very easy in Mule to bypass all the calls through any Proxy server. You just need to add 1 connector in your mule flow xml file and then Mule will send all the requests to Proxy server. Below is the connector <http:connector name="localproxy" proxyHostname="127.0.0.1" proxyPort="8888" doc:name="charlesproxy"></http:connector> This example is of using a local proxy server like Charles which runs on port 8888 on localhost. You can also use remote proxy by providing remote proxy host name in proxyHostname tag and port of that server. Make sure you remove this proxy connector for production version of your Mule application. Thanks.

Contract first SOAP CXF webservice in Mule

Image
Hello Coder, Ever wondered how to create and publish a SOAP service using an ESB like Mule ? In this tutorial we will learn to create and publish a SOAP service in Mule ESB using a WSDL which is also referred as Contract-First webservice. Before we proceed ahead there are some assumptions made for the reader of this tutorial: 1) You have basic knowledge about SOAP webservices. 2) You have basic knowledge about Mule ESB and what is a flow in Mule. 3) Installed Anypoint studio. I had used Anypoint version 5.0.0 used in this tutorial. 4) Have a WSDL for SOAP webservice which we are going to create and publish. Lets proceed to a step by step procedure for writing a SOAP webservice in Mule.

Delete rows from multiple tables in one query

Hello Reader, In this blog post we will learn how to cascade the delete operation to child table. In a parent-child relationship there are situations when we don't want to leave the Child orphan. Meaning if the parent row is getting deleted we want to delete the associated childs also. The classic way to achieve this situation is to delete all the child rows first and then delete the parent row. The drawback of this approach is that we need to fire 2 queries and both of them should be in a same transaction else it would leave stale data in DB. For eg. if children were deleted successfully but parent was not deleted successfully, now in DB we still have this parent but no children. If we want to delete this relation in a single query then there are then there are two ways to achieve it: 1) FOREIGN KEYS with ON DELETE CASCADE 2) Using JOIN in DELETE query Below example is for mysql: 1) FOREIGN KEYS with ON DELETE CASCADE: This options allows creating FOREIGN KEYS in such a way

Hibernate inserts duplicate child on cascade

At times we all use hibernate's cascade feature to cascade the child entries into database for OneToMany and ManyToMany relationships. If it is a first entry in DB then everything works fine but when we want to update the number/quantity of child of an existing parent, hibernate adds duplicate children. Assume the parent already exists with few children. Below is the relationship: Parent Mapping for OneToMany with Child: @OneToMany(targetEntity = ChildrenImpl.class, mappedBy = "parent", orphanRemoval = true, fetch = FetchType.LAZY) @Cascade(value = CascadeType.ALL) private List<Children> children = new ArrayList<Children>(); Child Mapping with parent ManyToOne @ManyToOne(targetEntity = ParentImpl.class, fetch = FetchType.LAZY) @JoinColumn(name = "PARENT_ID") private Parent parent; Below is the code which leads to duplicate children. Children newChild = new ChildrenImpl(); newChild.setName("I am a new child"); /* More setters here *

Java Collection Interview Questions and Detailed Answers Part II

More questions on Java Collection API, continued from our previous post linked here Q 1. Explain the impacts of variable and fixed hashcodes for objects stored in hash based data structures ? A. Fixed HashCode: If the hashcode of all the key objects are fixed and all of them return a same number then all the key-value pairs will go in same bucket. In this case the performance of hash based data structure will go down and time complexity for searching will be O(n). Reason is because all the key value pairs goes in same bucket hence jvm will need to traverse all the entries in the bucket to find the suitable key-value pair for the equals() method call. Variable HashCode: If the hashcode of the key object is random then the location of key-value pair for this key in the bucket will be different everytime, as a result the same key will be stored multiple times in the HashMap with different bucket locations. During retrieval of a key-value pair it is also possible that the value associat

Java Collections Interview Questions with Detailed Answers

Image
None of the interviews for Java based position can be completed without questions about Java Collections Framework. The Java Collection Framework is one of the core framework of Java language which each Java developer should know. The Java Collection Framework itself is very wide and its difficult to cover all the areas but still in this blog we will try to cover those questions and answers in detail which a candidate should know. Hierarchy of collection framework: Java collections hierarchy