Maven dependency
<dependency>
<groupId>com.jecklgamis</groupId>
<artifactId>jersey-fastinfoset-provider</artifactId>
<version>1.0</version>
</dependency>
Example Server Configuration (Dropwizard)
Run the file ExampleApp.java with arguments server src/test/resources/config.yml
ExampleApp.java
package com.jecklgamis.fastinfoset;
import com.codahale.metrics.health.HealthCheck;
import io.dropwizard.setup.Environment;
import org.glassfish.jersey.filter.LoggingFilter;
public class ExampleApp extends io.dropwizard.Application<ExampleAppConfig> {
@Override
public void run(ExampleAppConfig config, Environment env) throws Exception {
env.jersey().register(new ExampleResource());
env.healthChecks().register("default", new HealthCheck() {
@Override
protected Result check() throws Exception {
return Result.healthy();
}
});
env.jersey().register(LoggingFilter.class);
env.jersey().register(FastInfosetJaxbElementProvider.class);
env.jersey().register(FastInfosetRootElementProvider.class);
}
public static void main(String[] args) throws Exception {
new ExampleApp().run(args);
}
}
Example Client Configuration (Jersey 2 Client)
Run the ExampleClient.java (ensure ExampleApp is running)
ExampleClient.java
package com.jecklgamis.fastinfoset;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.JerseyClientBuilder;
import org.glassfish.jersey.filter.LoggingFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;
import static java.lang.String.format;
public class ExampleClient {
private static final Logger logger = LoggerFactory.getLogger(ExampleClient.class);
public static void main(String[] args) throws Exception {
Response response = client().target("http://127.0.0.1:5050").request()
.accept("application/fastinfoset").get(Response.class);
User user = response.readEntity(User.class);
logger.info(format("%s %s", user.getUsername(), user.getEmail()));
}
private static Client client() {
ClientConfig config = new ClientConfig();
config.register(LoggingFilter.class);
config.register(FastInfosetJaxbElementProvider.class);
config.register(FastInfosetRootElementProvider.class);
return JerseyClientBuilder.createClient(config);
}
}