Web Development
Articles, notes, and tutorials filed under Web Development.
Latest articles
Showing 1-8 of 22Getting Started with JUnit 5: Test your Spring MVC Application with it
In this post, we describe how to use JUnit 5 to test your Spring MVC application with Maven. Before diving into the pom.xml, it helps to know that JUnit 5 is not a single library but three sub-projects: the Platform (the foundation that discovers and launches tests), Jupiter (the new programming and extension model you actually write tests against), and Vintage (a backward-compatible engine that still runs your old JUnit 3/4 tests). This split is what makes the Maven coordinates below, and the SpringExtension we plug in later, much less mysterious.
Making Requests Non-blocking in Tornado
Tornado is one of the most popular web frameworks for Python, which is based on a single thread IO loop (aka event loop). You can handle high concurrency with optimal performance. However, Tornado is single-threaded (in its common usage, although it supports multiple threads in advanced configurations), therefore any “blocking” task will block the whole server. This means that a blocking task will not allow the framework to pick the next task waiting to be processed.
Single Sign-On with Apereo CAS
This tutorial walks a newcomer through standing up an Apereo CAS server for single sign-on and wiring a Java web application to it as a client. The complete CAS 7.1 server is available as a companion WAR overlay on GitLab. Note: This post has been rewritten for Apereo CAS 7.x. It was originally written for CAS 4.x, which you set up by copying the server source and hand-editing a pile of XML files (deployerConfigContext.xml, ticketGrantingTicketCookieGenerator.xml, …). CAS has changed completely since: the org.jasig.cas packages became org.apereo.cas, and the server is now built as a Spring Boot WAR overlay configured through a single cas.properties file.
Create a Desktop App with Angular 2 and Electron
Last week, I took part in the Google Developer Day held in Beijing. The Angular team introduced their new Angular 2. Angular is a development platform for building mobile and desktop web applications. This tutorial shows how to configure and use Angular 2 web components with the Electron framework for creating native cross-platform applications with web technologies. As recommended by the Angular team, TypeScript will be used throughout this tutorial. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open-source.
Use Server-Sent Events in Spring MVC
Server-Sent Events (SSE) let a server push a continuous stream of updates to the browser over a single long-lived HTTP connection. Spring has supported them since version 4.2 through the SseEmitter class, and the API has been stable ever since. This post is a practical how-to: we start with a bare SseEmitter, then build the setup I actually use in production, streaming events from a message queue to the browser.
Use WebSockets with Spring, SockJS and Stomp
This guide walks you through building a “hello world” application that sends messages back and forth between a browser and the server. WebSocket is a very thin, lightweight layer on top of TCP, which makes it a natural place to run a subprotocol that gives the raw bytes some structure. Here we use STOMP messaging with Spring to create an interactive web application. Note: This post has been updated for Spring 6/7. The WebSocket setup now uses @EnableWebSocketMessageBroker Java configuration and the modern @stomp/stompjs client. The original 2015 version targeted Spring 4.1 with XML <websocket:message-broker> config and the legacy Stomp.over() API; both are obsolete and have been replaced throughout.
Spring MVC MyBatis Integration Tutorial
A while back I built a project on Spring MVC and Hibernate, then wanted to see how MyBatis compares. This article shows how to wire MyBatis into Spring MVC, and how to let Spring manage MyBatis transactions for you. A database transaction is an all-or-nothing unit of work: either every statement in it takes effect, or none of them does. We lean on that property at the very end, where a single bad row makes an entire batch insert roll back.
Use CDN Service in Spring MVC
When I deployed TestZilla on Aliyun Elastic Compute Service, growing traffic made it worth offloading static files (images, CSS, and JavaScript) to a CDN. At the time there was little guidance on wiring a CDN into Spring MVC, so I asked on Stack Overflow and ended up with the setup below. The idea is simple: keep the CDN host in a single property and inject it wherever your JSP views reference static assets.