uCosminexus Application Server, Web Service Development Guide
The following table describes the combinations of the Java types and MIME media types, which can be used in the return value of a resource method. The return value is converted to the entity body of an HTTP response. Do not use the annotations in the JAXB specifications for POJO. If you use the annotation, the actual operations might differ from the described operations.
Table 17-6 Combinations of Java types and MIME media types, which can be used in the return value of a resource method
| No | Java type | Charset#1 | MIME media type |
|---|---|---|---|
| 1 | byte[] | N | Any (*/*) |
| 2 | java.lang.String | Y | Any (*/*) |
| 3 | java.io.InputStream | N | Any (*/*) |
| 4 | java.io.Reader | Y | Any (*/*) |
| 5 | java.io.File | N | Any (*/*) |
| 6 | javax.activation.DataSource | N | Any (*/*) |
| 7 | javax.xml.transform.Source#2 | N | text/xml, application/xml, application/*+xml |
| 8 | javax.xml.bind.JAXBElement<String>#3 | Y | text/xml, application/xml, application/*+xml |
| 9 | The JAXB class annotated by the XmlRootElement annotation#3 | Y | text/xml, application/xml, application/*+xml |
| 10 | javax.ws.rs.core.MultivaluedMap<String, String> | Y | application/x-www-form-urlencoded |
| 11 | javax.ws.rs.core.StreamingOutput | N | Any (*/*) |
| 12 | org.w3c.dom.Document | N | text/xml, application/xml, application/*+xml |
| 13 | java.util.List<T>#4 | Y | text/xml, application/xml, application/*+xml |
| 14 | java.awt.image.RenderedImage | N | image/jpeg |
| 15 | Void | -- | Any(*/*) |
| 16 | javax.ws.rs.core.Response | Y | Any (*/*) |
| 17 | javax.ws.rs.core.GenericEntity<T>#5 | D | Same MIME media type as specified in T. |
| 18 | POJO#6 | N#7 | application/json |
Legend:
--: Indicates a non-applicable item
Any (*/*): Indicates that all MIME media types are supported
#1
When a charset parameter is to be included in the Produces annotation or return value, indicate whether that information will be reflected in the charset parameter of the Content-type HTTP header for converting to an HTTP response.
Y: Reflected. UTF-8 is considered as the charset if the charset parameter is not included in the Produces annotation and the return value
D: Depends on the Java type specified in T
N: Not reflected
#2
The following implementation classes can be used:
- javax.xml.transform.stream.StreamSource
- javax.xml.transform.sax.SAXSource
- javax.xml.transform.dom.DOMSource
#3
When the MIME media type is application/fastinfoset or application/json, the operation completes successfully without occurrence of an error.
#4
You can specify the JAXB class annotated by the XmlRootElement annotation in T.
#5
You can specify all the types except No.17 of the table in T.
#6
Enable the JSON POJO mapping. The operations when the JSON POJO mapping is disabled are the same as the operations when you specify an unsupported Java type in an entity parameter. For details on how to enable the JSON POJO mapping, see 18. Mapping JSON and POJO.
#7
Do not add the charset parameter in the HTTP Content-Type header.
The following table describes the mapping of the return value and the HTTP response.
Table 17-7 Mapping of return value and HTTP response
| No. | Return value | HTTP response | ||
|---|---|---|---|---|
| Type | Value | HTTP status code | Entity body | |
| 1 | void | -- | 204 | Void entity body |
| 2 | Response | A non-null instance | 200 | Response entity properties |
| 3 | Null | 204 | Void entity body | |
| 4 | String | A non-null instance | 200 | String value |
| 5 | Null | 204 | Void entity body | |
| 6 | Supported Java types except void, Response, String | A non-null instance | 200 | A converted entity body based on the return value class |
| 7 | Null | 204 | Void entity body | |
Legend:
--: Indicates that the return value is unavailable
For the Java types where the return value types are not supported, the error (KDJJ10026-E) occurs, and consequently the system throws the exception javax.ws.rs.WebApplicationException, which can be handled by the exception mapping provider and has 500 as the HTTP status code. The process, however, successfully completes without occurrence of an error when the return value type is javax.mail.internet.MimeMultipart and the MIME media type is multipart/*.
If an exception is thrown when converting to entity body of an HTTP response, an error occurs. For details on how to handle the exceptions, see 17.1.8 Exception handling.
If the type of a return value is in the following Java type and the MIME media type that cannot be used by the entity body of the HTTP response, an error (KDJJ10026-E) occurs, and consequently the system throws javax.ws.rs.WebApplicationException, which can be handled by the exception mapping provider and has 500 as the HTTP status code.
The operation, however, successfully completes without occurrence of an error when the MIME media type of the entity body of the HTTP request is application/fastinfoset or application/json in No.1 or No.2.
For the following return values, a warning message or an error message (KDJJ20003-W or KDJJ10006-E) is output to the log. For details on KDJJ20003-W and KDJJ10006-E, see 13.7.1 Checking the syntax when initializing a Web resource (KDJJ20003-W and KDJJ10006-E).
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.