This is sort of a follow up post for a previous post of mine – RESTful Web Services Example in Java with Jersey, Spring and MyBatis. It is based on the same example application, which, via a REST API, can execute CRUD operations against a single Podcasts table. If in the first post the focus was on how to build the REST API with Jersey, this time it is on the data persistence layer. I will present how to implement a container-agnostic persistence layer with JPA2/Hibernate, being glued in the application via Spring.

Continue Reading ...

Note: At the time of writing this post I was just starting with REST and Jersey so I  suggest you have a look at  Tutorial – REST API design and implementation in Java with Jersey and Spring instead. My gained REST knowledge will be from now on reflected in this post, which is already an “(r)evolution” regarding REST API design, REST best practices used and backend architecture/implementation supporting the REST API presented in the tutorial.

Looking to REST? In Java? There’s never time for that :), but if you are looking to use an “architectural style consisting of a coordinated set of constraints applied to components, connectors, and data elements, within a distributed hypermedia system” in Java, then you have come to the right place, because in this post I will present a simple RESTful API that maps REST calls to backend services offering CRUD functionality.

Note: I will not focus too much on Representational state transfer (REST) itself, because there are plenty of resources on the topic in the internet, some of which I listed under Resources at the end of the post.

Continue Reading ...

Tools involved

  • JDK 1.6/1.7
  • Eclipse Kepler
  • Maven 3.1.1
  • m2e – Maven Integration for Eclipse plugin
  • Jetty 9
  • Windows 7 / 64 bit
Continue Reading ...

I have just posted my first tweet from Java

and I still can’t believe how easy and fast it was. The actual coding took like 2 minutes, whereby the remaining 8 minutes were needed to setup a Twitter application to be able to post in the first place. Not only that, but it worked from the first try, therefore I had to stop coding and start blogging about it. This was made possible by Twitter4j (thank you very much Yusuke):

“Twitter4J is an unofficial Java library for the Twitter API. With Twitter4J, you can easily integrate your Java application with the Twitter service. Twitter4J is an unofficial library”

Octocat Source code for this post is available on Github - podcastpedia.org is an open source project.

Continue Reading ...

The challenge – java.io.IOException: Server returned HTTP response code: 403 for URL

Remember my post Reading/Parsing RSS and Atom feeds in Java with Rome, remember how I build SyndFeed objects out of a feed’s URL:

public SyndFeed getSyndFeedForUrl(String url) throws MalformedURLException, IOException, IllegalArgumentException, FeedException {

	SyndFeed feed = null;
	InputStream is = null;

	try {

		URLConnection openConnection = new URL(url).openConnection();
		is = new URL(url).openConnection().getInputStream();
		if("gzip".equals(openConnection.getContentEncoding())){
			is = new GZIPInputStream(is);
		}
		InputSource source = new InputSource(is);
		SyndFeedInput input = new SyndFeedInput();
		feed = input.build(source);

	} catch (Exception e){
		LOG.error("Exception occured when building the feed object out of the url", e);
	} finally {
		if( is != null)	is.close();
	}

	return feed;
}
Continue Reading ...