Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
java
java
public class JAXRSUserModelServlet extends CXFNonSpringJaxrsServlet  {

    @Override
    public void loadBus(ServletConfig servletConfig) throws ServletException {
        super.loadBus(servletConfig);

        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        String address = servletConfig.getInitParameter(SERVICE_ADDRESS_PARAM); //jaxrs.address
        if (address == null) {
            address = "/";
        }
        sf.setAddress(address);

        // modelRef needs to start from 'classpath:', ex 'classpath:/WEB-INF/models/model1.xml
        String modelRef = servletConfig.getInitParameter("user.model");
        sf.setModelRef(modelRef);
        sf.create();
    }
} 

Query String Customization

CXF provides advanced capabilities with respect to query string parsing and expansion.

Collection/List

The typical way to manage collection/list query parameters is described in RFC-6570: URI Template (https://tools.ietf.org/html/rfc6570) and basically assumes the repetition of the name/value pairs, for example: http://localhost:8080/MovieDB/GetJson?name=Actor1&name=Actor2&name=Actor3&startDate=20120101&endDate=2012050

Since 3.1.8+, this behavior could be tweaked using server-side "parse.query.value.as.collection" property,  which adds support for collection/list parameters passed as comma-separated values, , for example: http://localhost:8080/MovieDB/GetJson?name=Actor1,Actor2,Actor3&startDate=20120101&endDate=2012050

The client support was lacking and was added in 3.3.4+ / 3.2.11+ / 3.4.0+ for all types of the clients (WebClient, JAX-RS Client Proxy and Microprofile Client). The matching property name is "expand.query.value.as.collection" and could be specified during the client instance creation, for example:

Code Block
java
java
MyClient client = JAXRSClientFactory
    .create("http://localhost:8080", MyClient.class,
        Collections.singletonMap("expand.query.value.as.collection", "true"));


Code Block
java
java
WebClient client = WebClient.create("http://localhost:8080", 
    Collections.singletonMap("expand.query.value.as.collection", "true"));


Code Block
java
java
MyClient client = RestClientBuilder
    .newBuilder()
    .property("expand.query.value.as.collection", "true")
    .baseUri(new URI("http://localhost:8080"))
    .build(MyClient.class);


Code Block
java
java
WebTarget target = ClientBuilder
    .newClient()
    .property("expand.query.value.as.collection", "true")
    .target("http://localhost:8080");