uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

17.1.2 Entity parameters

From among the parameters of a resource method, a parameter that is not annotated by an annotation is called an entity parameter. The value of the entity parameter is an entity body.

The following example describes an entity parameter used in the resource method.

@POST
public String getRequestParameters(@MatrixParam("matrix") String matrix,
    String entity) {
  return "Matrix is:" + matrix + "\mEntity Body is: " + entity;
}

In this example, the resource method getRequestParameters() contains the parameter matrix annotated by the MatrixParam annotation and the un-annotated parameter entity (entity parameter). When an HTTP request with the entity body content of Entity Content is received, the value of the entity parameter entity is Entity Content.

Organization of this subsection
(1) Combination of Java types and MIME media types available for entity parameters
(2) Notes on entity parameters

(1) Combination of Java types and MIME media types available for entity parameters

The following table describes the combinations of the Java types and the MIME media types that can be used as entity parameters. Do not use the annotations of the JAXB specifications for a POJO. If you use the annotations, the actual operations might differ from the described operations.

Table 17-5 Combinations of Java types and MIME media types that can be used as entity parameters

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#2 Y Any (*/*)
6 javax.activation.DataSource Y Any (*/*)
7 javax.xml.transform.Source#3 N text/xml,
application/xml,
application/*+xml
8 javax.xml.bind.JAXBElement<String>#4 N text/xml,
application/xml,
application/*+xml
9 The JAXB class annotated by the XmlRootElement annotation and/or the XmlType annotation#4 N text/xml,
application/xml,
application/*+xml
10 javax.ws.rs.core.MultivaluedMap<String,String> Y application/x-www-form-urlencoded
11 org.w3c.dom.Document N text/xml,
application/xml,
application/*+xml
12 java.util.List<T>#5 N text/xml,
application/xml,
application/*+xml
13 java.awt.image.RenderedImage N application/octet-stream, image/jpeg
14 com.cosminexus.jersey.core.provider.EntityHolder<T>#6 D The same MIME media type as the type specified in T.
15 POJO#7 Y application/json

Legend:
Any (*/*): Indicates that all MIME media types are supported

#1
Indicates whether the content of the charset parameter included in the HTTP Content-Type header is considered when the parameter is injected into an entity parameter.
Y: Considered. UTF-8 is considered as the charset if the charset parameter is not included in the HTTP Content-Type header.
D: Depends on the type specified in T
N: Not considered
Note that the charset parameter is ignored, if included in the value of the Consumes annotation.

#2
The JAX-RS engine creates a temp directory in the J2EE server environment to save a temporary file. Use the cjsetup command to configure the J2EE server environment. For details on the cjsetup command, see cjsetup (Set up and unset up of a J2EE server) in the Cosminexus Application Server Command Reference Guide.

#3
You can use the following implementation classes:
- javax.xml.transform.stream.StreamSource
- javax.xml.transform.sax.SAXSource
- javax.xml.transform.dom.DOMSource

#4
When the MIME media type is application/fastinfoset or application/json , the operation completes successfully without occurrence of an error.

#5
With T, you can specify the JAXB class annotated by the XmlRootElement annotation and XmlType annotation.

#6
You can specify the types from No. 2 through No.13, and No. 15 of this table in T.

#7
Enable the JSON POJO mapping. The operation when the JSON POJO mapping is disabled is the same as the operation when an unsupported Java type is specified in an entity parameter. For details on how to enable the JSON POJO mapping, see 18. Mapping JSON and POJO.

(2) Notes on entity parameters

Further notes on the entity parameters are as follows:

Operation if an exception is thrown when converting to an entity parameter
If an exception is thrown when converting to an entity parameter, an error occurs. For details on how to handle the exceptions, see 17.1.8 Exception handling.

Operation when a Java type does not support an entity parameter type or when the entity body of an HTTP request cannot use the MIME media type
The (KDJJ10024-E) error occurs when the following Java type entity parameters contain a MIME media type that cannot be used by the entity body of an HTTP request, and the system, throws javax.ws.rs.WebApplicationException, which can be handled by the exception mapping provider and has 415 as the HTTP status code.
  1. javax.xml.bind.JAXBElement<String>
  2. The JAXB class annotated by the XmlRootElement annotation and/or the XmlType annotation
  3. javax.ws.rs.core.MultivaluedMap<String,String>
  4. java.util.List<T>
  5. POJO
The operation, however, ends successfully without any errors when the MIME media type of the entity body of an HTTP request is application/fastinfoset or application/json in the step No.1 or No.2 mentioned above.
In the entity parameter of java.awt.image.RenderedImage, if the MIME media type of the entity body of an HTTP request is image/*, the system throws java.io.IOException, which can be handled by the exception mapping provider.
  • If the HTTP request contains an entity body in the entity parameter of com.cosminexus.jersey.core.provider.EntityHolder<T>, in either of the following cases, the error (KDJJ10003-E) occurs and the system throws javax.ws.rs.WebApplicationException, which can be handled by the exception mapping provider and has 500 as the HTTP status code.
    - If the type does not support T (No. 1 and No. 14 of the table)
    - If the type supports T (From No. 2 to No. 13 of the table) but the MIME media type does not support the entity body of the HTTP request
  • If you use a Java type that does not support the entity parameter type (excluding the cases where the MIME media types of the entity body of the HTTP request is application/xml, text/xml, or application/*+xml and java.lang.Object is being used), the (KDJJ10024-E) error occurs and the system throws an exception javax.ws.rs.WebApplicationException, which can be handled by the exception mapping provider and has one of the following values as the HTTP status code.
    400: When the entity parameter type is java.lang.Object and the MIME media type of the entity body of the HTTP request is application/xml, text/xml or application/*+xml
    415: When the entity parameter type is other than java.lang.Object, or when the entity parameter type is java.lang.Object and the MIME media type of the entity body of an HTTP request is other than application/xml, text/xml, or application/*+xml
    The process, however, completes successfully without occurrence of an error when the entity parameter type is javax.mail.internet.MimeMultipart and the MIME media type of the entity body of the HTTP request is multipart/*.

The number of entity parameters available for a resource method
You can use only one entity parameter in a resource method. If a resource method contains multiple entity parameters, the warning message (KDJJ20012-W) is output to the log. The entity body of the HTTP request is injected only into the initial entity parameter and the state of the second parameter and that of those thereafter is not guaranteed.

Resource methods that contain a GET request method identifier
When a resource method with a GET request method designator contains an entity parameter, 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).
Note
The Encoded annotation or the DefaultValue annotation is ignored, if annotated in the entity parameter.

Messages that are output when the type parameters of the entity parameters cannot be resolved
When the type parameter of an entity parameter cannot be resolved, a warning message or an error message (KDJJ10006-E or KDJJ20003-W) 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).

Notes when a specific type is specified in an entity parameter
When the entity parameter type is javax.ws.rs.core.MultivaluedMap<String,String> or com.cosminexus.jersey.core.provider.EntityHolder<javax.ws.rs.core.MultivaluedMap<String,String>>, note the following points:
  • If an entity body is accessed by a component other than a servlet or a servlet filter of the JAX-RS functionality, a warning message (KDJJ20007) is output to the log.
    Here, the entity parameters are in an undetermined state when being accessed. Reference the form parameters included in the entity body from the parameters annotated by the FormParam annotation.
  • An entity body can contain a maximum of 10,000 form parameters by default.
    If the number of parameters of a request exceed the specified number, an error (KDJJ10042-E) occurs and the system throws the javax.ws.rs.WebApplicationException exception, for which 413 is set in the HTTP status code and which can be processed by the exception mapping provider. Change the webserver.connector.limit.max_parameter_count property of the user property file (usrconf.properties) for the J2EE server, as and when required.
    For details on the user property file for the J2EE server, see 2.4 usrconf.properties (User property file for the J2EE server in the uCosminexus Application Server Definition Reference Guide.
When the entity parameter type is a POJO, note the following points:
  • If the JSON POJO mapping is disabled, an error (KDJJ10024-E) occurs and the system throws the javax.ws.rs.WebApplicationException exception, for which 415 is set as the status code and which can be processed by the exception mapping provider. For details on how to enable the JSON POJO mapping, see 18. Mapping JSON and POJO.