Skip to main content

Posts

Showing posts with the label cxf

JAXRS client on Android

Context Not a while ago I realized that for many people on this planet including my parents, smart-phone application is the only way they understand to interact with Internet. Therefore with zero client side software development experience, I started learning Android app programming. Only after several days of learning I found myself blocked for there doesn't seem to be a clear answer for a problem that is so essential -- how to create JAXRS client on Android application. After days of trying a working solution finally presented to me. This document talks about the solution that I found as well as, more importantly, the solutions that do not work. It's really important to known what we are looking for before start coding. I found many discussions on internet where people provide irrelevant because they have no idea what they are looking for. A solution must satisfy all following criteria: A Java library that calls HTTP RESTful service, preferably support HTTPS, wth/wi...

RESTful service with JAX-RS is so easy, a caveman could do it

A recent project requires me to build a RESTful service that supports supports stream input, output and JAXB binding. After a quick research, I was amazed when I found how easy it is to build RESTful service using JAX-WS(JSR-311) and Apache CXF . Cut the chase, let the code talk. import javax.xml.ws.rs.*; @Path( "/hello" ) public interface Greeter { @GET @Path( "/{user}") @Produces( "text/plain" ) public String sayHelloTo( @PathParam( "user" )String userName ); } It seems the annotations in the interface above provides everything client needs to know, and that's exactly right. Following CXF class returns an implementation of Greeter that knows to send HTTP request to http://helloworld.com/hello/jiaqi and return the HTML response as a String. There's zero coding work involved to create fully functional client. import org.apache.cxf.jaxrs.client.JAXRSClientFactory; ... Greeter greeter = JAXRSClientFactory.create( "http://hel...