当前位置: 首页 > news >正文

如何直到网站是用什么模板做的做网站好多钱

如何直到网站是用什么模板做的,做网站好多钱,南阳网站,网页制作公司moxy json介绍因此#xff0c;这些天我正在为即将推出的Oracle云服务开发新的REST API#xff0c;因此我需要做的事情之一就是能够为模型中的bean自动生成JSON模式。 我正在使用MOXy从POJO生成JSON#xff0c;从EclipseLink 2.5.1版本开始#xff0c;它现在具有从bean模型生… moxy json介绍 因此这些天我正在为即将推出的Oracle云服务开发新的REST API因此我需要做的事情之一就是能够为模型中的bean自动生成JSON模式。 我正在使用MOXy从POJO生成JSON从EclipseLink 2.5.1版本开始它现在具有从bean模型生成JSON模式的能力。 将来会有一个更加正式的解决方案集成到Jersey 2.x 但是如果您想尝试一下此解决方案目前就可以使用。 因此我们需要设置的第一类是模型处理器这是非常内部的Jersey类它允许我们使用额外的方法和资源来修改资源模型。 我们可以向模型中的每个资源添加JsonSchemaHandler 以完成生成新模式的艰苦工作。 由于这是一个简单的POC因此这里没有缓存如果要在生产代码中使用它请注意这一点。 import com.google.common.collect.Lists;import example.Bean;import java.io.IOException; import java.io.StringWriter;import java.text.SimpleDateFormat;import java.util.Date; import java.util.List;import javax.inject.Inject;import javax.ws.rs.HttpMethod; import javax.ws.rs.WebApplicationException; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Configuration; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response;import javax.xml.bind.JAXBException; import javax.xml.bind.SchemaOutputResolver; import javax.xml.transform.Result; import javax.xml.transform.stream.StreamResult;import org.eclipse.persistence.jaxb.JAXBContext;import org.glassfish.jersey.process.Inflector; import org.glassfish.jersey.server.ExtendedUriInfo; import org.glassfish.jersey.server.model.ModelProcessor; import org.glassfish.jersey.server.model.ResourceMethod; import org.glassfish.jersey.server.model.ResourceModel; import org.glassfish.jersey.server.model.RuntimeResource; import org.glassfish.jersey.server.model.internal.ModelProcessorUtil; import org.glassfish.jersey.server.wadl.internal.WadlResource;public class JsonSchemaModelProcessor implements ModelProcessor {private static final MediaType JSON_SCHEMA_TYPE MediaType.valueOf(application/schemajson);private final ListModelProcessorUtil.Method methodList;public JsonSchemaModelProcessor() {methodList Lists.newArrayList();methodList.add(new ModelProcessorUtil.Method($schema, HttpMethod.GET, MediaType.WILDCARD_TYPE, JSON_SCHEMA_TYPE,JsonSchemaHandler.class));}Overridepublic ResourceModel processResourceModel(ResourceModel resourceModel, Configuration configuration) {return ModelProcessorUtil.enhanceResourceModel(resourceModel, true, methodList, true).build();}Overridepublic ResourceModel processSubResource(ResourceModel resourceModel, Configuration configuration) {return ModelProcessorUtil.enhanceResourceModel(resourceModel, true, methodList, true).build();}public static class JsonSchemaHandler implements InflectorContainerRequestContext, Response {private final String lastModified new SimpleDateFormat(WadlResource.HTTPDATEFORMAT).format(new Date());Injectprivate ExtendedUriInfo extendedUriInfo;Overridepublic Response apply(ContainerRequestContext containerRequestContext) {// Find the resource that we are decorating, then work out the// return type on the first GETListRuntimeResource ms extendedUriInfo.getMatchedRuntimeResources();ListResourceMethod rms ms.get(1).getResourceMethods();Class responseType null;found:for (ResourceMethod rm : rms) {if (GET.equals(rm.getHttpMethod())) {responseType (Class) rm.getInvocable().getResponseType();break found;}}if (responseType null) {throw new WebApplicationException(Cannot resolve type for schema generation);}//try {JAXBContext context (JAXBContext) JAXBContext.newInstance(responseType);StringWriter sw new StringWriter();final StreamResult sr new StreamResult(sw);context.generateJsonSchema(new SchemaOutputResolver() {Overridepublic Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {return sr;}}, responseType);return Response.ok().type(JSON_SCHEMA_TYPE).header(Last-modified, lastModified).entity(sw.toString()).build();} catch (JAXBException jaxb) {throw new WebApplicationException(jaxb);}}}} 请注意 JsonSchemaHandler代码中的非常简单的启发式方法假定每个资源都有11映射到单个JSON Schema元素。 当然这可能不适用于您的特定应用程序。 现在我们已经在一个已知的位置生成了架构我们需要将其告知客户我们要做的第一件事是确保当用户在特定资源上调用OPTIONS时有一个合适的链接头 import java.io.IOException;import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.Context; import javax.ws.rs.core.Link; import javax.ws.rs.core.UriInfo;public class JsonSchemaResponseFilter implements ContainerResponseFilter {Contextprivate UriInfo uriInfo;Overridepublic void filter(ContainerRequestContext containerRequestContext,ContainerResponseContext containerResponseContext) throws IOException {String method containerRequestContext.getMethod();if (OPTIONS.equals(method)) {Link schemaUriLink Link.fromUriBuilder(uriInfo.getRequestUriBuilder().path($schema)).rel(describedBy).build();containerResponseContext.getHeaders().add(Link, schemaUriLink);}} } 由于这是JAX-RS 2.x因此我们正在与之合作将所有内容捆绑为一个功能 import javax.ws.rs.core.Feature; import javax.ws.rs.core.FeatureContext;public class JsonSchemaFeature implements Feature {Overridepublic boolean configure(FeatureContext featureContext) {if (!featureContext.getConfiguration().isRegistered(JsonSchemaModelProcessor.class)) {featureContext.register(JsonSchemaModelProcessor.class);featureContext.register(JsonSchemaResponseFilter.class);return true;}return false;} } 我不会展示我的整个POJO类集。 但是很快这就是模式生成代码所需的带有GET方法的Resource类 import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType;Path(/bean) public class BeanResource {GETProduces(MediaType.APPLICATION_JSON)public Bean getBean() {return new Bean();} } 最后如果对资源执行GET将看到以下内容 GET .../resources/bean Content-Type: application/json{message : hello,other : {message : OtherBean},strings : [one,two,three,four] } 和选项 OPTIONS .../resources/bean Content-Type: text/plain Link: http://.../resources/bean/$schema; reldescribedByGET, OPTIONS, HEAD 最后如果您解析模式资源 GET .../resources/bean/$schema Content-Type: application/schemajson{$schema : http://json-schema.org/draft-04/schema#,title : example.Bean,type : object,properties : {message : {type : string},other : {$ref : #/definitions/OtherBean},strings : {type : array,items : {type : string}}},additionalProperties : false,definitions : {OtherBean : {type : object,properties : {message : {type : string}},additionalProperties : false}} } 这里有很多工作要做特别是根据我不久前转发到Jersey 2.xa的声明性链接注释生成超媒体扩展。 但这确实指向解决方案我们可以运用各种解决方案使某些事情现在起作用。 翻译自: https://www.javacodegeeks.com/2014/04/quick-and-a-bit-dirty-json-schema-generation-with-moxy-2-5-1.htmlmoxy json介绍
http://www.huolong8.cn/news/159044/

相关文章:

  • 一流的龙岗网站建设珠海网站建设公司哪家好
  • 国外乡村建设网站中企做的网站太原
  • 广州建网站兴田德润很好wordpress 文章 模板下载
  • 淘宝接单做网站wordpress 获取当前文章的浏览量
  • 手机网站网站开发流程网站备案个人使用
  • 北京网站开发培训兼容模式网站错位
  • 网站定制开发什么意思广告策划方案万能模板
  • 设计素材网站wordpress代码缩进
  • 上海建筑工程网站wap静态模板
  • 古风自己做头像的网站给公司做网页收多少钱
  • 响应式网站开发视频教程用外国人的照片做网站
  • 深圳专门网站制作怎么制作公司宣传图片
  • 51CTO学院个人网站开发视频wordpress 按别名
  • 顺义电大网上作业在那个网站做专业网站优化方案
  • 建设一个企业网站一般多少钱龙港哪里有做阿里巴巴网站
  • 建设一个门户网站 费用网站建设基本范例
  • 个人做理财网站好wordpress图片购买下载
  • 长沙设计网站建设工商局网上注册公司
  • 检察院门户网站建设自查报告青岛做网站那家好
  • c 做的网站怎么上传家居设计网站推荐
  • 广西建设厅网站行业网电子商务网站开发开发背景
  • 医疗网站建设好么产品50个关键词
  • 营销型网站制作费用网站多个页面要加引导
  • 临安网站设计淡水做网站
  • 网站能看出建设时间吗装修公司网站设计
  • 电子商务网站建设与维护期末考试百度联盟官网
  • 东莞淘宝网站建设沧州网络推广公司
  • 白色网站源码网络运营商自动选择
  • 关于美食网站的问卷调查怎么做网站模板选择
  • 长春市城建网站wordpress 照片博客