Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Missing }, minor spelling/stylistic changes.

...

Code Block
http://my.company.com/myapp/orders/1
http://my.company.com/myapp/orders/1.xml
http://my.company.com/myapp/orders/1.xhtml
http://my.company.com/myapp/orders/1.json

and the framework handles the serialization and deserialization automaticallyThe REST plugin automatically handles serialization to, and deserialization from, each format.

Features

  • Fully implements Ruby -On-on Rails RestREST-style URLs
  • Supports XML-free development, without requiring annotations
  • Built-in serialization and deserialization support for XML and JSON
  • Automatic error handling of errors
  • Type-safe configuration of the HTTP response
  • Automatic conditional GET support

...

Code Block
langxml
  <!-- ... -->
   <init-param>
     <param-name>struts.devMode</param-name>
     <param-value>true</param-value>
   </init-param>
</filter>

Next, create Java objects ending in "Controller" in the configured package. The "Controller" suffix is used to distinguish Rest REST action resources from regular Struts 2 actions, although it is completely optional and they are functionally the same. Now, add in methods to handle the various requests. For example, the following resource action will support /orders/34 GET and PUT requests:

...

You may wonder why the show() method returns a HttpHeaders object and the update() method returns the expected result code String. Well, the Rest The REST Plugin adds in support for action methods that return HttpHeaders objects as a way for the action to have more control over the response. In this example, we wanted to ensure the response included the ETag header and a last modified date so that the information will be cached properly by the client. The HttpHeaders object is a convenient way to control the response in a type-safe way.

...

Setting

Description

Default

Possible Values

struts.rest.handlerOverride.EXTENSION

The alias for the ContentTypeHandler implementation that handles the EXTENSION value

N/A

Any declared alias for a ContentTypeHandler implementation

{{struts.rest.defaultExtension}

The default extension to use when none is explicitly specified in the request

xml

Any extension

struts.configuration.rest.disableControllerScanning

Whether to disable the scanning of the classpath for controllers or not

false

true or false

...

This plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib directory. It does depend The REST plugin is dependent on the Codebehind Plugin, so if aren't using a build system that supports transitive dependencies like Maven 2, you will need to add that plugin as well.

...

...