本文整理汇总了Java中org.glassfish.jersey.moxy.json.MoxyJsonFeature类的典型用法代码示例。如果您正苦于以下问题:Java MoxyJsonFeature类的具体用法?Java MoxyJsonFeature怎么用?Java MoxyJsonFeature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MoxyJsonFeature类属于org.glassfish.jersey.moxy.json包,在下文中一共展示了MoxyJsonFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
context.register(MoxyJsonFeature.class);
context.register(MoxyXmlFeature.class);
context.register(MultiPartFeature.class);
// internal features
context.register(CacheFilter.class);
context.register(GenericExceptionMapper.class);
context.register(XmlMessageBodyReader.class);
context.register(XmlMessageBodyWriter.class);
Configuration.instance().getStrings("APP.Jersey.Features").forEach(cn -> {
try {
LOGGER.info("Register Jersey Feature: {}", cn);
context.register(this.getClass().getClassLoader().loadClass(cn));
} catch (ClassNotFoundException e) {
LOGGER.error(e.getMessage(), e);
}
});
return true;
}
示例2: testUpdateStudent
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
/**
* 测试PUT方法
*/
public static void testUpdateStudent(){
Client client = ClientBuilder.newBuilder().register(MoxyJsonFeature.class).register(MyApplication.createMoxyJsonResolver()).build();
Student student = new Student();
student.setSid(1);
student.setName("SCOTT");
ClassRoom classRoom = new ClassRoom();
classRoom.setCid(1);
classRoom.setClassname("三年二班");
student.setClassRoom(classRoom);
Response response = client.target("http://localhost:8080/v1/api/student").request(MediaType.APPLICATION_JSON).put(Entity.entity(student, MediaType.APPLICATION_JSON));
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
}
示例3: testSaveStudent
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
/**
* 测试POST方法
*/
public static void testSaveStudent(){
Client client = ClientBuilder.newBuilder().register(MoxyJsonFeature.class).register(MyApplication.createMoxyJsonResolver()).build();
Student student = new Student();
student.setSid(2);
student.setName("SCOTT");
ClassRoom classRoom = new ClassRoom();
classRoom.setCid(2);
classRoom.setClassname("三年二班");
student.setClassRoom(classRoom);
Response response = client.target("http://localhost:8080/v1/api/student").request(MediaType.APPLICATION_JSON).post(Entity.entity(student, MediaType.APPLICATION_JSON));
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
}
示例4: getClasses
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
// register root resource
classes.add(getResource());
classes.add(MultiPartFeature.class);
classes.add(LensJAXBContextResolver.class);
classes.add(LensJAXBValidationExceptionMapper.class);
classes.add(LensRequestLoggingFilter.class);
classes.add(LoggingFilter.class);
classes.add(LensApplicationListener.class);
classes.add(MoxyJsonConfigurationContextResolver.class);
classes.add(MoxyJsonFeature.class);
classes.add(GenericExceptionMapper.class);
return classes;
}
示例5: buildClient
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
public Client buildClient() {
ClientBuilder cb = ClientBuilder.newBuilder().register(MultiPartFeature.class).register(MoxyJsonFeature.class)
.register(MoxyJsonConfigurationContextResolver.class);
for (Class<?> aClass : params.getRequestFilters()) {
cb.register(aClass);
}
Client client = cb.build();
//Set Timeouts
LensClientConfig config = params.getConf();
client.property(ClientProperties.CONNECT_TIMEOUT, config.getInt(CONNECTION_TIMEOUT_MILLIS,
DEFAULT_CONNECTION_TIMEOUT_MILLIS));
client.property(ClientProperties.READ_TIMEOUT, config.getInt(READ_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS));
return client;
}
示例6: startServer
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
* @return Grizzly HTTP server.
*/
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in com.ccoe.build.service.health package
final ResourceConfig rc = new ResourceConfig().packages("com.ccoe.build.service");
// uncomment the following line if you want to enable
// support for JSON on the service (you also have to uncomment
// dependency on jersey-media-json module in pom.xml)
// --
//rc.addBinder(org.glassfish.jersey.media.json.JsonJaxbBinder);
rc.register(MoxyJsonFeature.class);
rc.register(MultiPartFeature.class);
rc.register(JsonMoxyConfigurationContextResolver.class);
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
示例7: RestConfiguration
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
public RestConfiguration() {
// Resources
packages(new String[]{
HandlingReportService.class.getPackage().getName(),
GraphTraversalService.class.getPackage().getName(),
CargoMonitoringService.class.getPackage().getName()});
// Enable Bean Validation error messages.
property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
// Providers - JSON.
register(new MoxyJsonFeature());
register(new JsonMoxyConfigurationContextResolver()); // TODO See if this can be removed.
}
示例8: bootstrap
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
private static void bootstrap() throws IOException {
Random rnd = new Random();
String port = Optional.ofNullable(System.getenv("PORT")).orElse("808" + String.valueOf(rnd.nextInt(10)));
String host = System.getenv().getOrDefault("HOSTNAME", "localhost");
System.out.println("host " + host);
URI baseUri = UriBuilder.fromUri("http://" + host + "/").port(Integer.parseInt(port)).build();
ResourceConfig config = new ResourceConfig(TweetStateResource.class)
.register(MoxyJsonFeature.class);
HttpServer server = JdkHttpServerFactory.createHttpServer(baseUri, config);
Logger.getLogger(KafkaStreamsAppBootstrap.class.getName()).log(Level.INFO, "Application accessible at {0}", baseUri.toString());
KafkaStreams theStream = new KafkaStreamsTweetAnalysisJob().startPipeline();
//gracefully exit
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
LOGGER.log(Level.INFO, "Exiting......");
try {
theStream.close();
LOGGER.log(Level.INFO, "Kafka Stream services stopped");
server.stop(0);
LOGGER.log(Level.INFO, "Jersey REST services stopped");
} catch (Exception ex) {
//log & continue....
LOGGER.log(Level.SEVERE, ex, ex::getMessage);
}
}
}));
}
示例9: configureClient
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
@Override
protected void configureClient(final ClientConfig config) {
super.configureClient(config);
config.register(MoxyJsonFeature.class)
.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
.register(new MoxyJsonConfig().setFormattedOutput(true)
// Turn off BV otherwise the entities on server would be validated by MOXy as well.
.property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE).resolver());
}
示例10: RestConfiguration
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
public RestConfiguration() {
// Resources
packages(new String[]{
HandlingReportService.class.getPackage().getName(),
CargoMonitoringService.class.getPackage().getName()});
// Enable Bean Validation error messages.
property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
// Providers - JSON.
register(new MoxyJsonFeature());
register(new JsonMoxyConfigurationContextResolver()); // TODO See if this can be removed.
}
示例11: init
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
@PostConstruct
public void init() {
// if we have an explictly configured external JNDI entry use that
if (graphTraversalUrlJNDI != null) {
graphTraversalUrl = graphTraversalUrlJNDI;
}
graphTraversalResource = jaxrsClient.target(graphTraversalUrl);
graphTraversalResource.register(new MoxyJsonFeature()).register(
new JsonMoxyConfigurationContextResolver());
}
示例12: BookingServiceTestRestConfiguration
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
public BookingServiceTestRestConfiguration() {
// Resources
// packages(new String[]{GraphTraversalService.class.getPackage().getName()});
// Providers - JSON.
register(new MoxyJsonFeature());
register(new JsonMoxyConfigurationContextResolver()); // TODO See if this can be removed.
}
示例13: startServer
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
* @return Grizzly HTTP server.
*/
public static HttpServer startServer() {
DataStore.createSampleData();
final ResourceConfig rc = new ResourceConfig().packages("me.ederign.resources" );
rc.register(MoxyJsonFeature.class);
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer( URI.create( BASE_URI ), rc );
return httpServer;
}
示例14: testGetStudentsV1
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
public static void testGetStudentsV1(){
Client client = ClientBuilder.newBuilder().register(MoxyJsonFeature.class).register(MyApplication.createMoxyJsonResolver()).build();
Response response = client.target("http://localhost:8080/v1/api/student").path("v1").request(MediaType.APPLICATION_JSON).get();
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
System.out.println("---------------------------------");
response = client.target("http://localhost:8080/v1/api/student").path("v1").request(MediaType.APPLICATION_XML).get();
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
}
示例15: testGetStudentsV2
import org.glassfish.jersey.moxy.json.MoxyJsonFeature; //导入依赖的package包/类
public static void testGetStudentsV2(){
Client client = ClientBuilder.newBuilder().register(MoxyJsonFeature.class).register(MyApplication.createMoxyJsonResolver()).build();
Response response = client.target("http://localhost:8080/v1/api/student").path("v2").request(MediaType.APPLICATION_JSON).get();
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
System.out.println("---------------------------------");
response = client.target("http://localhost:8080/v1/api/student").path("v2").request(MediaType.APPLICATION_XML).get();
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
}