In my previous tip, I looked at setting up RESTful Controllers. Now in the post we will look at the verbs available for RESTful services. . Although this is nice for writing RESTless controllers, it is not ideal for writing RESTful controllers. The reason is that controllers made in this way are action oriented and not resource oriented. This can be easily surmised by the names used for the different requests which are focused on the particular use cases but not on the resources. ...
Updated 11-30-2011 at 01:39 PM by Spring Framework
In my previous tip, I presented to you an overview of how to handle RESTful URLs. In this tip, I will followup will look at RESTful Controllers. From my previous posts, I believe you have surmised that Spring MVC’s model is a very flexible framework for for writing controller classes. Almost any method with almost any signature can be annotated to handle a web request. Although this is nice for writing RESTless controllers, it is not ideal for writing RESTful controllers. The reason is that controllers ...
In my previous tip, I presented to you an overview of Spring support of REST. In this tip, I will followup with a tip for look at RESTful URLs. If you want to create a RESTful controller, you will need to handle URLs in a RESTful way. That’s because everything that’s done in REST is done through a URL. The URL’s RESTful nature is even implied by it’s name, uniform resource locator. Given that name, it seems that a URL is intended to locate a resource. Above and beyond this, URLs ...
Updated 11-30-2011 at 01:37 PM by Spring Framework
In Spring 3.0, the Spring team added support for Representational State Transfer (REST). It has emerged as a popular information-centric alternative to traditional SOAP-based web services. Spring developers have taken advantage of the REST architectural model to pack the Spring MVC with first-class support for working with REST. In this tip, we will look at the fundamentals of REST. In order to understand what REST is all about, it helps to break down the acronym into its constituent ...
I have been exploring JAX-WS services in Spring. In this tip, I will look into proxying JAX-WS services on the client side. Consuming web services with Spring involves client-side proxies in a way similar to how Spring based clients consume other remoting technologies. Using JaxWsPortProxyFactoryBean is used to wire the Car web service in Spring similar to any other Spring bean. The JaxWsPortProxyFactoryBean is a factory bean that produces a proxy that knows how to talk to a SOAP ...
Updated 11-30-2011 at 01:36 PM by Spring Framework
In my previous tip, I showed you how to autowire a JAX-WS endpoint. Although this is very useful, but recognize that the objects whose properties are being injected doesn’t have its lifecycle managed by Spring. There are circumstances though, where it’s possible to export a Spring-managed bean as a JAX-WS endpoint. In this tip, I will show you how. Spring’s SimpleJaxWsServiceExporter works by publishing Spring-managed beans as service endpoints in a JAX-WS runtime. SimpleJaxWsServiceExporter ...
Updated 11-30-2011 at 01:35 PM by Spring Framework
One of the most important changes in IT in the last 10 years has been the advent of Service Oriented Architecture (SOA). At the core SOA is the idea of building system via a common set of core services rather than the traditional monolithic method. Java and web services have been intimately intwined. There are a number of options are available for working with web services in Java. Spring facilitates the integration of many of these options. In fact, Spring provides support for publishing and consuming ...
Sometimes you might need to have a more sophisticated method of defining security constraints. Fortunately as of version 3.0, Spring Security also supports SpEL as a means for declaring access requirements. I will give you show you how to use it in this tip. First thing you will need to do is to enable it. To do this, you must set the use-expressions attribute of <http> to true: Java Code: <http auto-config="true" use-expressions="true"> ...
<http auto-config="true" use-expressions="true">
Updated 11-30-2011 at 01:34 PM by Spring Framework
This is the last of a series of tips on Spring Security. From my previous tips, you should be able to configure Spring Security as well as setup login and logout. In the last tip, I will show you how to intercept requests. The <intercept-url> element is the key in the request-level security. Its pattern attribute is provide with a URL pattern that will be matched against incoming requests. If any requests match the pattern, then the <intercept-url>’s security rules will be applied. So ...
In my previous tips, I showed you how to configure and setup Spring Security as well as the login form autogenerated when auto-config is set to true. In this tip, I will show you how to setup the logout for your application. Basically the <logout> element will setup a Spring Security filter that will invalidate a user session. If it is used as is, the filter set up by <logout> is mapped to /j_spring_security_ logout. In order to ensure that there is no collision with the DispatcherServlet, ...
In my previous tips I showed how to add in the necessary servlet filters in your Spring application file and then to configure minimal security in your Spring application. In this tip, we will look at setting up a form for logging into an application. As I mention in the last tip, by setting auto-config to true, the autoconfiguration give our a free login page, support for HTTP Basic authentication and logging out, and Spring Security will automatically generate a login page page. ...
In a previous tip, I showed how to add in the necessary servlet filters in your Spring application file. We added both the Delegating FilterProxy along with the another filter, FilterChainProxy. In general, Spring security will automatically create these beans for you when you configure the <http> element. Java Code: <http> <form-login /> <http-basic /> <logout /> <intercept-url pattern="/**" access="ROLE_USER" ...
<http> <form-login /> <http-basic /> <logout /> <intercept-url pattern="/**" access="ROLE_USER"
Continuing our investigation of Spring Security, in this tip I will look at making secure web requests. All activities that starts in a java web application is initiated via an HttpServletRequests. As such, this is where the security of your application will start. This security takes the form of request-level security. This involves declaring one or more URL patterns as requiring some level of granted authority and restricting access to those without authority from accessing the content of those ...
In the last tip, I introduced Spring Security and outlined the modules that are available. In this tip, we will look at configuring namespaces. Using Spring, the nice thing about Spring Security is that all the security elements are configured as beans in the application context. It is not uncommon to have a Acegi configuration containing dozens of bean declarations that span multiple pages. Another nice feature is that Spring Security has its own security-specific namespace to simplify ...
Spring Security is a security framework that started out as Acegi Security and then became an official part of Spring in version 2.0. It provides declarative security for all Spring-based applications. Spring Security handles all aspects of security from authentication to authorization at both the web request level and at the method invocation level. Like many Spring Framework modules, it takes full advantage of dependency injection (DI) and aspect-oriented techniques. Irrespective ...
Following on from my previous tip, I will now define the page view from our previous tip. Using Tiles properly, the home page is composed of several distinct pieces. The main_template.jsp file describes the common layout for all pages in the Springexample application, while home.jsp displays the main content for the home page. Plus, carForm.jsp and login.jsp provide additional common elements. The home.jsp is where the home page request finishes its journey. It picks up the list of Cars ...
In earlier tips, I talked about using Spring MVC and the use of different view technologies. In this tip, I will look at Tiles as a view technology for Spring MVC. Tiles was initially built to be used with the Struts Framework. But as it is a powerful view technology it has been reused by other web frameworks. To use Tiles with Spring MVC you need to register the Tiles’ view resolver as a bean with the application’s xml file, springexamples.xml. Java Code: <bean class= "org.springframework.web.servlet.view.tiles2.TilesViewResolver"/> ...
<bean class= "org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>
In the previous tip, I showed you how you could use XML to define a transaction. In this tip we will look at doing the same using annotations. It is blindly simple to use annotations for transactions. The tx namespace provides the <tx:annotation-driven> element. It appears like this : Java Code: <tx:annotation-driven transaction-manager="txManager" /> With this you can now define transaction rules very easily. This tag tells Spring to examine all beans in ...
<tx:annotation-driven transaction-manager="txManager" />
Continuing from my previous post, I will demonstrate how you can declare transactions in XML using Spring. Continuing from the previous tips on transaction attributes, let’s dive straight in. Spring has a tx configuration namespace to simply declaring transactions in Spring. It is recommended that you include the aop namespace as well since some of the declarative transaction configuration elements use AOP configuration elements. The following shows how <tx:advice> is used for the Car service. ...
Updated 11-27-2011 at 10:36 PM by Spring Framework
In the previous tip, we looked at the key properties that are required for handling any transaction. In Spring, when you want to have your application are using. Spring transaction concepts are taken from the JEE specification specifically the EJB 3.0 specification. Another key aspect of managing transactions is the ability to control the propagation of transactions in your application. Spring has the org.springframework.transaction.TransactionStatus interface that allows an application to check ...
Transactions are defined as doing a business unit of work. It is a key functionality that enable you to control concurrent access of data by multiple business operations. This is done in order to safeguard integrity and ensure that data remains in a consistent state. If for any reason the unit of work could not be completed as an indivisible unit of work, all the changes are unwound and the system is returned to its previous state. The key properties for the design of any application is to ensure ...
Updated 11-30-2011 at 01:06 PM by Spring Framework
In my previous post, I showed you how to create a HomeController for our home page in your application. You might have noted that there was little code that linked your HomeController with Spring that was included. It is simply a plain old java object (POJO). In this tip, we will look at unit testing your controller. Unit testing your controller will be very easy since a POJO doesn’t need you to mock any Spring or other specific objects. I will create a test object using standard naming conventions, ...
When you work with Spring MVC, after configuring the Dispatcher Servlet in order to build an application you need to do the following: Define controllers that invoke business logic and create a ModelAndView object. Visualization component like JSP, Velocity or FreeMarker. Annotation configuration or XML to wire the components together The first thing that you will most likely do is to define a home page controller. Spring provides a number of controllers to use ...
In an earlier post, I showed you how to integrate Hibernate with Spring using the annotation oriented persistence. For those still interested in the standard way I outline how you can accomplish that below. The key to the standard way is to use a Hibernate org.hibernate.SessionFactory for all access to the database through the domain objects. The Java configuration for the SessionFactory is shown below. Java Code: package com.acme.springexamples.car.dao.config; import org.springframework.beans.factory.annotation.Value; ...
package com.acme.springexamples.car.dao.config; import org.springframework.beans.factory.annotation.Value;
If you are concern you that DispatcherServlet will be handling static content requests, Spring has features that can help you to deal with this. Spring’s mvc namespace includes a <mvc:resources> element that handles requests for static content for you. In the following example, I show you how you can create an xml file that the DispatcherServlet can use to create an application context. Java Code: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ...
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
Updated 11-30-2011 at 12:59 PM by Spring Framework
Spring MVC’s key component is the DispatcherServlet. This servlet that functions as Spring MVC’s front controller. Like any servlet, DispatcherServlet must be configured in the web application’s web.xml file. If you need to setup the Dispatcher Servlet it is relatively straightforward. Below is what needs to be added to the web.xml file. Java Code: <servlet> <servlet-name>springexamples</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet ...
<servlet> <servlet-name>springexamples</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet
There are a number of DataSource connection pool implementations provided by different vendors as well as projects like C3PO and Apache Commons DBCP providing popular open-source options. It is easy to switch between different data source implementations, because of the common DataSource interface. Spring provides a convenient data source implementations as well but it is not considered as powerful as the vendor or open source implementations. The simplest one is org.springframework.jdbc.datasource.DriverManagerD ataSource, ...
Custom XML namespaces were introduced in Spring 2.0. Similar to Java packages, custom namespaces make it possible to define components without concern of colliding with other named components. Spring has already some predefined namespaces such as jee, aop, util, as well as others. Custom namespaces are handled using the NamespaceHandlerSupport class that generates metadata to be consumed by the Spring framework. This metadata is processed by parser classes that are also supplied by a component developer. ...
In Spring AOP, you can use what is called an introduction (a special type of advice) that enables your objects to implement an interface dynamically, by providing the implementation class for that interface. This behavior can be multiplied to give the impression of multiple inheritance to your beans. To define an introduction, use the @DeclareParents annotation, which gives matching types a new parent. Java Code: package com.acme.springexamples.derivautos; import org.aspectj.lang.annotation.Aspect; ...
package com.acme.springexamples.derivautos; import org.aspectj.lang.annotation.Aspect;
Spring offers a number of options for configuring a data sources via data source beans. These sources include the following: Data sources that use JNDIData sources that use JDBC driversData sources that pool connections There is significant differences in the features available depending on what you are trying to do. In this tip, I will outline how to configure different data sources and what they are best used for. If you are looking to do really robust ...
License4J 4.0
Yesterday, 12:23 AM in Java Software