Weblogs and Java Dave Johnson Roller Weblogger project Prepared for the Triangle Java User’s Group February 16 th, 2004
0 - Today’s talk What’s a weblog and why have weblogs become such an important part of the Java community? How you can use weblogs in software development projects. And about the XDoclet-driven architecture of the Roller Weblogger.
What is a weblog? “A blog is a web page made up of usually short, frequently updated posts that are arranged chronologically—like a what's new page or a journal. The content and purposes of blogs varies greatly—from links and commentary about other web sites, to news about a company/person/idea, to diaries, photos, poetry, mini- essays, project updates, even fiction.” - The Blogger.com site “Weblogs are often-updated sites that point to articles elsewhere on the web, often with comments, and to on-site articles.” – Dave Winer
History of weblogging One could consider the “what’s new” pages at CERN, NCSA, and Netscape in the early 1990’s to be the first weblogs. The term weblog originated in late 1997, there were only a couple dozen such sites then. Radio, Blogger, LiveJournal services sprang up during the dot-com boom brings war-blogs, mainstream media blogs, mo-blogging, and political campaign blogs.
1 - The Java weblog community 2002: a couple Java blogs and FreeRoller 2003: explosion of Java blogs Thousands of JRoller Java blogs Hundreds of independently hosted Java blogs Javablogs.com community aggregator Sun’s Java.NET weblogs JBoss blogs, Codehaus blogs, etc.
JRoller.com Free Java-oriented weblogging service Started as FreeRoller by Anthony Eden in Javalobby took over in October 2003, re- branded, and now hosts more than 2000 blogs.
Javablogs.com Hub of the Java weblogging community. Started by Atlassian, makers of JIRA issue tracking software. Anybody can register a weblog here, but non-Java blogs are discouraged.
Sun’s Java.NET community site Launched just before JavaONE in July 2003 Weblogs and Wiki are prominently featured Java gurus invited to populate weblogs
Java news you can use… Fresh Java links everyday from Erik Thauvin, featured in JDJ Struts, XHTML, CSS, JavaScript tips, and Java webapp tips from Matt Raible JSP and J2EE webapp tips from WROX author Simon Brown Mobile app. dev. trends from Russell Beattie Ted Neward published a rough draft of Effective Enterprise Java on his blog S/W dev. discussion from Cedric Buest, Senior S/W Engineer, BEA S/W dev. discussion from Cameron Purdy, CEO Tangosol S/W dev. discussion from Charles Miller of Atlassian. And of course:
2 – Weblog software features We already discussed the basics. A weblog is: An online journal, news site, diary A personal publishing system Entries in reverse chronological order Let’s discuss how weblog software makes it easy to write online.
Easy to update your site Easy to add a new weblog entry, even if you have no knowledge of HTML. Easy to categorize posts. Easy to edit old posts. Use a WYSIWYG editor, HTML, or use Wiki syntax.
Common features Permalinks: every post gets it’s own unique and permanent URL. Comments: Some weblogs allow comments on each post, some do not – it’s up to the author. RSS Newsfeeds: so that “subscribers” may read your weblog in a Newsreader. Page Templates: so you can customize the look, feel, and layout of your weblog. Referrer Tracking and Trackback: so you know who is writing about or linking to your weblog entries. Blog-rolling: displaying a list of favorite weblogs and websites.
Anatomy of a weblog
3 - Weblog infrastructure Weblogging is supported by an extensive infrastructure that is built around: Data formats: RSS, Atom, OPML Web service APIs: Blogger API, Atom And good old HTTP Let’s talk about that infrastructure and the applications that build upon it to support weblogging…
Newsfeed syndication A newsfeed is simply an XML representation of titles and entries from a website, made available at a URL. A weblog page: A weblog RSS feed: Most newsfeeds are RSS or RDF. Serious weblog readers use newreaders: on JRoller over 70% of requests come from newsreader software.
Example RSS newsfeed
XML-RPC interface XML-RPC based Blogger API allows posting and editing of weblog entries from weblog client software. MetaWeblog API adds support for titles. XML-RPC was invented to serve this purpose. History of weblog APIs:
Clients Blog clients allow you to: Post to your own weblog Post comments to other weblogs Newsreader clients, allow you to: Subscribe to and read RSS newsfeeds Import/export subscription lists as OPML
SharpReader – desktop newsreader
Bloglines.com – web newsreader
w:bloggar – blogging client
4 – Weblogs & communities “the web grows communities, almost without trying, because the web is the only media that allows it’s users to communicate with each other directly, publicly, and immediately” - Derek Powazek, Design for Communities Communities are important to technology development and adoption. Weblogs are not the only technology that enable online community, communication, and collaboration. What’s so special about weblogs in community building?
Weblogs vs. A mailing-list is also a great place for community discussion, but flames and noise can be a problem. Spam is making less and less valuable. can complement weblogs Blogging via Mailing-list to weblog gateways Comment notification via publishes to a select group, the content is free-form, haphazard, and unrestricted. The problem is that has little "memory" (you cant refer to a previous ) and no permanence (an doesn't park itself on your intranet, to be seen, shared, repurposed, etc.. for later use). -Jordan Frank, Traction Software
Weblogs vs. newsgroups Threaded newsgroups and web forums are a great place for community discussions, but flames and noise can drive people away. You can opt-out with a kill file. Weblogs provide an opt-in model – you only read, subscribe, and link to blogs you like. This also provides filtering. Forums can complement weblogs – a threaded forum could be used for weblog comments.
Weblogs vs. web pages Project and group web pages always seem to grow stale. Generally speaking, web pages are static and difficult to update. This is true even in a web savvy group with great web design/editing tools. Weblogs are easy to keep up to date and require no special publishing tools. Weblogs replace “homepages” The vanity page is dead; long live the Blog. The vanity Web page has lost momentum. People who posted one have already done so, and the growth has slowed. Most are uninteresting and uninspired. Cat pictures dominate too many of them. – John Dvorak
Weblogs vs. Wikis Wikis provide: A collaborative space for a community Anybody can edit or add any page via web interface Super simple syntax means, no need for HTML Wikis can function as weblogs and can produce RSS feeds Wikis & weblogs are easily integrated
Weblog as community “it’s this multitude [of separate sites] that gives the weblog community model it’s strength. Because a person has control over his own piece of community landscape, he feels a powerful ownership of his space that’s lacking in traditional community sites.” Design For Community, Derek Powazek
Weblog Community Aggregators Javablogs.com is not the only one… “A Community Aggregator is a portal-like web application that displays weblog posts from a group of closely related but separately hosted weblogs and provides synthetic newsfeeds so that readers may subscribe to the group as a whole.” Enabled by RSS syndication Provide aggregated RSS feeds Subscription lists in OPML format
Planet Apache Community aggregator for Apache developer weblogs. Similar sites for: Dot Net blogs Python blogs GNOME blogs Mono blogs Fedora blogs Debian blogs Lisp blogs Etc. …
Question #1 Why have weblogs have become such an important part of the Java community? Ease of publishing empowers developers to share This resulted in lots of great developer weblogs Weblogs are great for community building
5 – Weblogs at work More and more people are discovering weblogs and wikis are useful on the job and behind the firewall. Let’s talk about some specific uses for weblogs in the workplace.
K-logging K-logs: weblogs for knowledge management, a term originated by Jon Robb former CEO of UserLand. Every employee blogs on a daily basis Goals and progress Opinions and links to outside news and analysis Managers subscribe to employee weblogs, directors subscribe to their manager, and so on up the chain. Weblog archives act as knowledge base that may be commented upon and linked to.
It all sounds so good, but… Will it work? Local blogger Mark Pilgrim points out that: “most people are not good writers” “most companies don’t see the value of having people document anything” “most people are not passionate about their work” “people only have so much writing in them everyday”
Enterprise blogging use-cases Enterprise Weblogging vendor Traction software suggests a number of use cases for weblogs behind the firewall: Personal notebook Corporate communications Program management Product management Operations log Internal news Communities of interest
Enterprise Blogging
In my experience… Weblogs are useful for timely news and status Announce new builds and new documents News of big changes to code-base Weekly or daily status reports Wikis are useful as collaborative space Serves as software project homepage Record rough specs and feature ideas Consultants can document progress and issues Testers can document ever changing test setups
6 – Roller demo Making a post with Roller Making a post with w:bloggar Using Roller’s Wiki integration features Managing categories Managing bookmarks
7 – Roller Architecture Roller is an open source J2EE weblogging system that manages weblog data in a relational database. Editor UI – Struts and JSP Page and RSS rendering – Velocity Database access – Hibernate (or Castor)
Layered architecture
7.1 Roller Persistence Layer
Persistence Layer in context
Example code: a query // Find all entries in a website since a given date QueryFactory factory = mStrategy.getQueryFactory(); Query query = factory.createQuery(WeblogEntryData.class.getName()); Condition specifiedWebsite = factory.createCondition("website", Query.EQ, website); Condition specifiedDate = factory.createCondition( “pubTime", Query.GT, date); List conditions = new LinkedList(); conditions.add(specifiedWebsite); conditions.add(specifiedDate); query.setWhere(factory.createCondition(Query.AND, conditions)); List entries = query.execute();
7.2 Roller Business Layer Defined by set of manager interfaces. And a set of persistent domain objects.
Business Layer in context
Roller Data Model
Example POJO: XDoclet markup /** name="website" table="website" id="id" * key-generator="UUID" auto-complete="true" table="website" include-all="true" */ public class WebsiteData extends org.roller.persistence.PersistentObject implements java.io.Serializable { /** set-method="setDescription" name="description" * dirty="check" sql-dirty="check" column="description" * non-null=“false" unique="false" */ public java.lang.String getDescription() { return this.description; } public void setDescription(java.lang.String description) { this.description = description; }
XDoclet code generation, part I XDoclet makes it easy to keep O/R mapping files in sync with Java source code.
7.3 Roller Presentation Layer Editor UI implemented with Struts and JSP, using Struts form beans generated by XDoclet. JSP pages use: Struts HTML form tags JSTL core and I18N tags Custom Roller JSP tags Roller pages and RSS feeds are implemented using Velocity templates.
Presentation Layer in context
Example Action: XDoclet markup /** path="/BookmarkSave" name="bookmarkFormEx" * validate="true" input="/BookmarkEdit.do“ * name="Bookmarks" * path="/Bookmarks.do?method=selectFolder" */ public class BookmarkSave extends Action { public ActionForward execute( ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {...
XDoclet code generation, part II XDoclet makes it easy to keep deployment descriptors in sync with Java source code.
7.4 Roller Page Rendering Weblog users want almost complete control over page layout and design For a variety of reasons, we can’t allow them to edit JSP files Instead, pages are defined by Velocity templates PageServlet renders user-defined pages FlavorServlet renders predefined formats
Example: a weblog page template #showWebsiteTitle() #includePage("_css") #showRSSAutodiscoveryLink() #showWebsiteTitle() #showWebsiteDescription() #showWeblogCategoryChooser() #showWeblogEntries("_day" 15) Calendar #showWeblogCalendar() RSS Feeds #showRSSBadge() #showRSSLinks() Links #showBookmarks("Blogroll" true false) #showBookmarks("News" true false) Navigation #showBasicNavBar(true) #showEditorNavBar(true) Referers #showReferers(30 20)
Example: a day page template #showDayPermalink( $day ) #showEntryDate( $day ) #foreach( $entry in $entries ) $entry.title #showEntryText($entry) ($entry.pubTime) #showEntryPermalink( $entry ) #showCommentsPageLink( $entry ) #end #showLinkbacks( $day )
Example: the RSS template $utilities.textToHTML($website.name,true) $websiteURL $utilities.textToHTML($website.description,true) en-us Copyright #formatDate("yyyy" $now) $ Address #set( $entries = $pageModel.getRecentWeblogEntriesArray($entryCount) ) #foreach( $entry in $entries ) $utilities.textToHTML($entry.title,true) $absBaseURL$entry.permaLink $entry.getRss09xDescription( $entryLength ) #end
Roller Page Velocity Servlets Page Servlet mapped to /page/ Flavor Servlet mapped to /flavor/ and to /rss/
7.7 Roller: Lessons Learned Initially, FreeRoller suffered from severe performance and load-related stability problems. Now, JRoller runs smoothly and puts minimal load on the Java Lobby server. Most important performance improvements Caching, Caching, and more Caching Proper use of connections - Open Session in View Database Indexes
Caching, Caching, Caching Server-side Page and RSS feed caching via OSCache Enable client-side caching by supporting HTTP IF- MODIFIED-SINCE header. Cache last update time for each weblog so checking IF- MODIFIED-SINCE needs no database query. Caching keeps database hits to absolute minimum.
Example: RSS feed caching
Open Session in View Cannot give each HTTP session it’s own database connection – that won’t scale. Pattern documented by Hibernate folks, a “persistence session” corresponds to a database connection. Each incoming request gets a connection from the connection pool and uses it for all processing. When response is complete, request’s connection is returned to the pool.
Open Session in View - sequence
Database indexes Biggest single performance improvement. Watch for queries that examine lots of rows, make sure key fields are indexed.
8 – Conclusion Go sign up for your new blog at JRoller.com Thanks for listening! Any questions?