Skip to main content

Posts

Showing posts from 2012

60 days at expedia India

About to complete 60 days at Expedia, Gurgaon and till now the ride has been a rollercoaster. I joined Expedia hoping for challenging work, participating in building a good team and workplace full of amazing people. To be frank, everything is as close to reality as I imagined. The experience is amazing, people are awesome, the new office is great, the parties are crazy, but the most important thing is the freedom to express yourself and asking questions. And people around you listen (even leaders) and have enough patience to make you feel comfortable. Work-wise finishing user-stories (part of the onboarding process), building a team by interviewing the brightest mind in the industry and ideating about the new ideas to make it a better workplace and best technology platform. It's a great learning opportunity to contribute to one of the fastest-growing company's in the technology and travel industry. I hope this answers some of your initial questions about joining Expedia. Looki...

Java references in nutshell

Java developers struggle to use java references and i don't blame them. The topic seldom covered by text books and even code reviews rarely give emphasis on usage of references. Why the topic is important at all? and if everybody (atleast people i have come across) is coding without it why the hell you need it? Since you are reading this, either you are already aware of them or for the interview. Anyways, knowing references helps you manage memory better because you are able to define the behavior of the object when GC (garbage collector)  is run. Type of references: 1. Strong R eference : The normal reference in the java code is strong reference and the object referenced by strong reference is eligible for GC as soon as scope ends or reference started pointing to null in the code. E.g.  Person p = new Person();                 p = null; // will make object initialized...

CXF-RS adding custom response code

Following snippet show how to return the custom Response code as http response code while returning the response: import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; @Path("/") @Consumes("application/xml") @Produces("application/xml") public class Test  { public  Test () { } @POST public Response test() { Response response = Response.status( 4xx ).entity("Testing").build(); return response; } }

CXF-RS Hiding JAXRS Service Endpoints Listing

You may come across a scenario where you want to stop listing of the exposed service from given endpoint. This can be achieved by setting the property " org.apache.cxf.endpoint.private "   to true as shown in following snippet: < jaxrs:server id = "serivceId" address = "/test" > . . . < jaxrs:properties > < entry key = "org.apache.cxf.endpoint.private" value = "true" /> </ jaxrs:properties > </ jaxrs:server > This will stop the listing of the service when url http://server:port/ test is typed in the browser.

Eclipse Tips: Escape string while pasting in the editor

Escape string while pasting in the editor Go to Window > Preferences, type escape in the search field. Go to Java > Editor > Typing preference page. In last group label "String literals" select the "Escape text when pasting into a string literal".

CXF JSON Generation remove @ prefix

Working with CXF-RS if you want to generate the json response along with xml than it becomes pain in cases where your xml is a mixture of attributes and elements. Problem comes because of default jettison json provider which is configured in cxf-rs. The jettison appends the '@' prefix  with the attributes. However, I needed json free from any prefixes. To achieve this i had configure jackson as json provider like this:                <jaxrs:providers>             <ref bean="jaxbProvider" />             <ref class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>         </jaxrs:providers>                         That's it and you should be free from prefixes.

CXF-RS: Java Code Generation from xml/xsd

Cleaner approach is to use xjc like this: Continue to dirty approach below if u need to: When working with CXF-RS services often we start with XML message that will be served. After that we go through endless iteration of generating the right Java POJO's for the XML. The library like apache XMLBeans generate the Java code but the code generated is not what a developer would write and generally tedious to modify and understand. I have come across a work around for generating Java classes from XSD (xml) which is very close to what a developer with decent experience will write.  Follow the steps given below to explore the solution: 1. Generate the wsdl from from xsd as given in at this link  ( http://cxf.apache.org/docs/xsd-to-wsdl.html ). 2. The Java classes can be generated from wsdl from maven plugin entry below find complete details here   http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html org.apache.cxf cxf-codegen-plugin ...