Release 6.2.0
Date: Apr 28, 2017
Juneau 6.2.0 is a major update.
org.apache.juneau
-
Revamped the serializer, parser classes to use builders for creation. Serializers and parsers are now unmodifiable objects once they are created. This is a breaking code change that will require adoption.
/* Creating a new serializer or parser */
// Old way
WriterSerializer s = new JsonSerializer().setUseWhitespace(true).pojoSwaps(BSwap.class).lock();
// New way
WriterSerializer s = JsonSerializer.create().ws().pojoSwaps(BSwap.class).build();
/* Cloning an existing serializer or parser */
// Old way
WriterSerializer s = SimpleJsonSerializer.DEFAULT
.clone().setUseWhitespace(true).pojoSwaps(BSwap.class).lock();
// New way
WriterSerializer s = SimpleJsonSerializer.DEFAULT
.builder().ws().pojoSwaps(BSwap.class).build(); -
Also introduced the following builder classes and related architecture changes to make the built objects unmodifiable:
SerializerGroup.BuilderParserGroup.BuilderEncoderGroup.Builder
-
Revamped the config file API to use a builder:
ConfigFileBuilder. -
Removed the
Lockableinterface. -
New
addBeanTypeProperties
setting added to serializers to override theSerializerContext.SERIALIZER_addBeanTypePropertiessetting for individual serializers in a serializer group:HtmlSerializerContext.HTML_addBeanTypePropertiesJsonSerializerContext.JSON_addBeanTypePropertiesMsgPackSerializerContext.MSGPACK_addBeanTypePropertiesUonSerializerContext.UON_addBeanTypePropertiesXmlSerializerContext.XML_addBeanTypePropertiesRdfSerializerContext.RDF_addBeanTypeProperties
-
UON notation serializers and parsers moved into the new
org.apache.juneau.uon
package. -
New XmlFormat.VOID format to identify HTML void elements.
-
Tweaks to HTML5 support.
- Fixed handling of empty non-void elements in HTML serializer.
- Added
style()
override methods to all elements.
-
Improvements to Swagger support.
- New SwaggerBuilder class.
- Fluent-style setters added to the Swagger beans.
- Added Swagger examples
hereand in theswaggerjavadocs.
-
Improvements to VarResolver.
- New IfVar $IF variable for if-else block logic.
- $SWITCH variable for switch block logic.
- Whitespace wasn't being ignored in some cases.
-
HtmlParser can now parse full body contents generated by HtmlDocSerializer.
-
Parse-args supported added to MsgPackParser to allow it to be used in remoteable proxies.
-
Added some convenience classes for constructing collections using a fluent interface:
AListASetAMap
-
New @Bean(typePropertyName) annotation allows you to specify the name of the
"_type"
property at the class level. -
New methods added to HTML5 container beans:
-
New common serializer setting:
SerializerContext.SERIALIZER_abridged. -
Support for defining interface proxies against 3rd-party REST interfaces. New package
remoteablefor all remoteable proxy interface annotations.@Remoteable
annotation has been moved to this package. -
Updated doc: 6 - Remoteable Services
-
New doc: 6.1 - Interface proxies against 3rd-party REST interfaces
-
New URL-encoding serializer setting:
UrlEncodingSerializerContext.URLENC_paramFormat. -
New methods on UrlEncodingSerializer.Builder:
Builder.paramFormat(String)Builder.plainTextParams()
org.apache.juneau.rest
-
@RestResourceannotation can now be applied to any class! You're no longer restricted to subclassing your resources fromRestServlet. This is a major enhancement in the API. Anything you could do by subclassing fromRestServlet
should have an equivalent for non-RestServlet
classes. The only restriction is that the top-level resource must subclass fromRestServlet
. Child resources do not.The majority of code has been split up into two separate classes:
RestConfig- A modifiable configuration of a resource. Subclasses fromjavax.servlet.ServletConfig.- RestContext - A read-only configuration that's the result of a snapshot of the config.
The
RestServletclass now has the following initialization method that allows you to override the config settings define via annotations:RestServlet.init(RestConfig)- A modifiable configuration of a resource.
Non-
RestServlet
classes must have one of the following to allow it to be instantiated:- A
public T(RestConfig)
constructor. - A
public T()
constructor. - The parent resource must have a customized
RestResourceResolverfor instantiating it.
Non-
RestServlet
classes can optionally include the following init methods to gain access to the config and context:- public init(RestConfig)
- public init(RestContext)
-
New annotations added to
@RestResourceto allow non-RestServlet
resources to do the same as subclassing directly fromRestServlet
:RestResource.resourceResolver()- Specify aRestResourceResolverclass for resolving child resources.RestResource.callHandler()- Specify aRestCallHandlerclass for handling the lifecycle of a REST call.RestResource.infoProvider()- Specify aRestInfoProviderclass for customizing title/description/Swagger information on a REST resource.RestResource.logger()- Specify aRestLoggerclass for handling logging.
-
New annotations added to
@RestResourceand@RestMethodto simplify defining page title, text, and links on HTML views:@RestResource(pageTitle)@RestMethod(pageTitle)@RestResource(pageText)@RestMethod(pageText)@RestResource(pageLinks)@RestMethod(pageLinks)
// Old method
@RestResource(
properties={
@Property(name=HTMLDOC_title, value="System properties resource"),
@Property(name=HTMLDOC_description, value="REST interface for performing CRUD operations on system properties."),
@Property(name=HTMLDOC_navlinks, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}")
}
)
// New method
@RestResource(
pageTitle="System properties resource",
pageDescription="REST interface for performing CRUD operations on system properties.",
pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"
)Typically you're going to simply want to use the
title
anddescription
annotations which apply to both the page title/text and the swagger doc:@RestResource(
title="System properties resource",
description="REST interface for performing CRUD operations on system properties.",
pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"
) -
RestResource.stylesheet()can now take in a comma-delimited list of stylesheet paths. -
StreamResourcecan now contain multiple sources from a variety of source types (e.g.byte[]
arrays,InputStreams
,Files
, etc...) and is now immutable. It also includes a newStreamResourceBuilderclass. -
Simplified remoteable proxies using the
@RestMethod(name="PROXY")
annotation on REST methods. Used to expose interface proxies without the need forRemoteableServlet.// Server side
@RestMethod(name="PROXY", path="/myproxy/*")
public IAddressBook getProxy() {
return addressBook;
}
// Client side
RestClient client = RestClient.create().rootUrl(samplesUrl).build();
IAddressBook ab = client.getRemoteableProxy(IAddressBook.class, "/addressBook/myproxy");See
@RestMethod(name)for more information. -
RestRequest.toString() can be called at any time to view the headers and content of the request without affecting functionality. Very useful for debugging.
-
@RestMethod(name)annotation is now optional. Defaults to"GET"
.
org.apache.juneau.rest.client
-
Revamped the client API to use builders.
-
New doc:
1.5 - Debugging -
The
RestClient
classdoX(Object url)
methods now handle HttpClientURIBuilder
instances. -
New methods added/updated to RestClient:
RestClient.getRemoteableProxy(Class,Object)- For interface proxies defined using@RestMethod(name="PROXY")
.RestClient.getRemoteableProxy(Class,Object,Serializer,Parser)- Same as above but overrides the serializer and parser defined on the client.RestClient.doPost(Object)RestClient.doCall(HttpMethod,Object,Object)- Can now pass in instances ofNameValuePairsfor easy form posts. This extends to all methods that take in the input.
-
New methods on
RestCall:RestCall.uri(Object)query(String,Object,boolean,PartSerializer)RestCall.query(String,Object)RestCall.queryIfNE(String,Object)RestCall.query(Map)RestCall.queryIfNE(Map)RestCall.query(String)formData(String,Object,boolean,PartSerializer)RestCall.formData(String,Object)RestCall.formDataIfNE(String,Object)RestCall.formData(Map)RestCall.formDataIfNE(Map)header(String,Object,boolean,PartSerializer)RestCall.header(String,Object)RestCall.headerIfNE(String,Object)RestCall.headers(Map)RestCall.headersIfNE(Map)RestCall.host(String)RestCall.port(int)RestCall.userInfo(String,String)RestCall.userInfo(String)RestCall.scheme(String)
-
New methods added to RestClient.Builder:
- executorService(ExecutorService,boolean)
Builder.paramFormat(String)Builder.plainTextParams()- noTrace() - Adds a
No-Trace: true
header on all requests to prevent the servlet from logging errors. Useful for testing scenarios when you don't want the console to end up showing errors done on purpose. - debug() now adds a
Debug: true
header on all requests.
-
New methods added/updated to
RestCall:-
RestCall.runFuture() -
RestCall.getResponseFuture(Class) -
RestCall.getResponseFuture(Type,Type...) -
RestCall.getResponseAsStringFuture() -
RestCall.serializer(Serializer)- Override the serializer defined on the client for a single call. -
RestCall.parser(Parser)- Override the parser defined on the client for a single call. -
input(Object)- Now accepts instances ofNameValuePairs. -
RestCall.getResponse(Class)- Can now pass in any of the following:- HttpResponse - Returns the raw
HttpResponse
returned by the innerHttpClient
. - Reader - Returns access to the raw reader of the response.
- InputStream - Returns access to the raw input stream of the response.
- HttpResponse - Returns the raw
-
-
New methods added to
NameValuePairs:NameValuePairs.append(String,Object)append(String,Object,PartSerializer)
-
RetryOnis now an abstract class with an additional method: -
RetryOn.onResponse(HttpResponse)
org.apache.juneau.microservice
-
"REST/port"
configuration setting can now be a comma-limited list of port numbers to try. You can also specify one or more0
s to try a random port. -
Methods added to
RestMicroserviceclass:getPort()getURI()- Override methods added from Microservice class for easier method chaining.