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

做网站要用什么语言wordpress搬家更换域名

做网站要用什么语言,wordpress搬家更换域名,网站备案成功然后怎么做,模板建房多少钱一平方1.简介 这篇文章的目的是使用Spring Integration HTTP入站适配器实现HTTP Restful API。 本教程分为两个部分#xff1a; XML配置示例#xff08;同一篇文章#xff09;。 Java DSL示例。 这将在本教程的下一部分中进行说明#xff0c;展示如何使用Spring Integration Ja… 1.简介 这篇文章的目的是使用Spring Integration HTTP入站适配器实现HTTP Restful API。 本教程分为两个部分 XML配置示例同一篇文章。 Java DSL示例。 这将在本教程的下一部分中进行说明展示如何使用Spring Integration Java DSL配置应用程序并提供Java 7和Java 8的示例。 在查看代码之前让我们看一下下图该图显示了应用程序公开的不同服务 GET操作由HTTP入站网关处理而其余操作PUTPOST和DELETE由HTTP入站通道适配器处理因为没有响应主体发送回客户端。 以下各节将说明每个操作 介绍 应用配置 进行操作 放置和发布操作 删除操作 结论 源代码可从Github获得 。 2.应用程序配置 web.xml文件包含分派器Servlet的定义 servletservlet-namespringServlet/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:xpadro/spring/integration/configuration/http-inbound-config.xml/param-value/init-param /servlet servlet-mappingservlet-namespringServlet/servlet-nameurl-pattern/spring/*/url-pattern /servlet-mapping 以下各节将说明http-inbound-config.xml文件。 下面是pom.xml文件的详细信息。 重要的是要注意杰克逊库。 由于我们将使用JSON表示资源因此这些库必须存在于类路径中。 否则框架将不会注册所需的转换器。 propertiesspring-version4.1.3.RELEASE/spring-versionspring-integration-version4.1.0.RELEASE/spring-integration-versionslf4j-version1.7.5/slf4j-versionjunit-version4.9/junit-versionjackson-version2.3.0/jackson-version /propertiesdependencies!-- Spring Framework - Core --dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion${spring-version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion${spring-version}/version/dependency!-- Spring Framework - Integration --dependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-core/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-http/artifactIdversion${spring-integration-version}/version/dependency!-- JSON --dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-core/artifactIdversion${jackson-version}/version/dependencydependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion${jackson-version}/version/dependency!-- Testing --dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion${junit-version}/versionscopetest/scope/dependency!-- Logging --dependencygroupIdorg.slf4j/groupIdartifactIdslf4j-api/artifactIdversion${slf4j-version}/version/dependencydependencygroupIdorg.slf4j/groupIdartifactIdslf4j-log4j12/artifactIdversion${slf4j-version}/version/dependency /dependencies3.进行操作 该流程的配置如下所示 http-inbound-config.xml 网关接收到以下路径的请求/ persons / {personId}。 请求到达后将创建一条消息并将其发送到httpGetChannel通道。 然后网关将等待服务激活器 personEndpoint返回响应 现在需要解释一些要点 支持的方法 此属性指示网关支持哪些方法仅GET请求。 payload-expression 我们在这里所做的是从URI模板中的personId变量获取值并将其放入消息的有效负载中。 例如请求路径“ / persons / 3”将成为一条值为“ 3”的消息作为有效负载。 request-mapping 我们可以包含此元素以指定多个属性并过滤哪些请求将被映射到网关。 在示例中此网关仅处理包含Content-Type头consumes属性和Accept头produces属性的值“ application / json”的请求。 将请求映射到此网关后便会生成一条消息并将其发送到服务激活器。 在示例中我们定义了一个简单的Bean它将从服务中获取所需的信息 Component public class PersonEndpoint {private static final String STATUSCODE_HEADER http_statusCode;Autowiredprivate PersonService service;public Message? get(MessageString msg) {long id Long.valueOf(msg.getPayload());ServerPerson person service.getPerson(id);if (person null) {return MessageBuilder.fromMessage(msg).copyHeadersIfAbsent(msg.getHeaders()).setHeader(STATUSCODE_HEADER, HttpStatus.NOT_FOUND).build(); }return MessageBuilder.withPayload(person).copyHeadersIfAbsent(msg.getHeaders()).setHeader(STATUSCODE_HEADER, HttpStatus.OK).build();}//Other operations } 根据从服务收到的响应我们将返回被请求的人员或指示未找到人员的状态代码。 现在我们将测试一切是否按预期进行。 首先我们定义将响应转换为的ClientPerson类 JsonIgnoreProperties(ignoreUnknown true) public class ClientPerson implements Serializable {private static final long serialVersionUID 1L;JsonProperty(id)private int myId;private String name;public ClientPerson() {}public ClientPerson(int id, String name) {this.myId id;this.name name;}//Getters and setters } 然后我们执行测试。 在buildHeaders方法中我们指定了Accept和Content-Type标头。 请记住我们在这些标头中使用application / json值限制了请求。 RunWith(BlockJUnit4ClassRunner.class) public class GetOperationsTest {private static final String URL http://localhost:8081/int-http-xml/spring/persons/{personId};private final RestTemplate restTemplate new RestTemplate();private HttpHeaders buildHeaders() {HttpHeaders headers new HttpHeaders();headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));headers.setContentType(MediaType.APPLICATION_JSON); return headers;}Testpublic void getResource_responseIsConvertedToPerson() {HttpEntityInteger entity new HttpEntity(buildHeaders());ResponseEntityClientPerson response restTemplate.exchange(URL, HttpMethod.GET, entity, ClientPerson.class, 1);assertEquals(John , response.getBody().getName());assertEquals(HttpStatus.OK, response.getStatusCode());}Testpublic void getResource_responseIsReceivedAsJson() {HttpEntityInteger entity new HttpEntity(buildHeaders());ResponseEntityString response restTemplate.exchange(URL, HttpMethod.GET, entity, String.class, 1);assertEquals({\id\:1,\name\:\John\,\age\:25}, response.getBody());assertEquals(HttpStatus.OK, response.getStatusCode());}Test(expectedHttpClientErrorException.class)public void getResource_sendXml_415errorReturned() {HttpHeaders headers new HttpHeaders();headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));headers.setContentType(MediaType.APPLICATION_XML);HttpEntityInteger entity new HttpEntity(headers);restTemplate.exchange(URL, HttpMethod.GET, entity, ClientPerson.class, 1);}Test(expectedHttpClientErrorException.class)public void getResource_expectXml_receiveJson_406errorReturned() {HttpHeaders headers new HttpHeaders();headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));headers.setContentType(MediaType.APPLICATION_JSON);HttpEntityInteger entity new HttpEntity(headers);restTemplate.exchange(URL, HttpMethod.GET, entity, ClientPerson.class, 1);}Test(expectedHttpClientErrorException.class)public void getResource_resourceNotFound_404errorReturned() {HttpEntityInteger entity new HttpEntity(buildHeaders());restTemplate.exchange(URL, HttpMethod.GET, entity, ClientPerson.class, 8);} } 在Content-Type标头中未指定正确的值将导致415不支持的媒体类型错误因为网关不支持此媒体类型。 另一方面在Accept标头中指定不正确的值将导致406 Not Acceptable错误因为网关返回的内容类型不同于预期。 4.放置和发布操作 对于PUT和POST操作我们使用相同的HTTP入站通道适配器从而可以为它定义多个路径和方法。 一旦请求到达路由器将负责将消息传递到正确的端点。 http-inbound-config.xml int-http:inbound-channel-adapter channelrouteRequest status-code-expressionT(org.springframework.http.HttpStatus).NO_CONTENTsupported-methodsPOST, PUT path/persons, /persons/{personId}request-payload-typexpadro.spring.integration.server.model.ServerPersonint-http:request-mapping consumesapplication/json/ /int-http:inbound-channel-adapterint:router input-channelrouteRequest expressionheaders.http_requestMethodint:mapping valuePUT channelhttpPutChannel/int:mapping valuePOST channelhttpPostChannel/ /int:routerint:service-activator refpersonEndpoint methodput input-channelhttpPutChannel/ int:service-activator refpersonEndpoint methodpost input-channelhttpPostChannel/ 此通道适配器包括两个新属性 status-code-expression 默认情况下通道适配器确认已收到请求并返回200状态码。 如果要覆盖此行为可以在此属性中指定其他状态代码。 在这里我们指定这些操作将返回204 No Content状态代码。 request-payload-type 此属性指定将请求主体转换为哪个类。 如果我们没有定义它它将无法转换为服务激活器期望的类ServerPerson。 收到请求后适配器会将其发送到路由器期望它的routeRequest通道。 该路由器将检查消息头并根据“ http_requestMethod”头的值将其传递到适当的端点。 PUT和POST操作都由同一个bean处理 Component public class PersonEndpoint {Autowiredprivate PersonService service;//Get operationpublic void put(MessageServerPerson msg) {service.updatePerson(msg.getPayload());}public void post(MessageServerPerson msg) {service.insertPerson(msg.getPayload());} } 返回类型为空因为没有期望的响应 入站适配器将处理状态码的返回。 PutOperationsTest验证是否返回了正确的状态码以及资源是否已更新 RunWith(BlockJUnit4ClassRunner.class) public class PutOperationsTest {private static final String URL http://localhost:8081/int-http-xml/spring/persons/{personId};private final RestTemplate restTemplate new RestTemplate();//build headers methodTestpublic void updateResource_noContentStatusCodeReturned() {HttpEntityInteger getEntity new HttpEntity(buildHeaders());ResponseEntityClientPerson response restTemplate.exchange(URL, HttpMethod.GET, getEntity, ClientPerson.class, 4);ClientPerson person response.getBody();person.setName(Sandra);HttpEntityClientPerson putEntity new HttpEntityClientPerson(person, buildHeaders());response restTemplate.exchange(URL, HttpMethod.PUT, putEntity, ClientPerson.class, 4);assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());response restTemplate.exchange(URL, HttpMethod.GET, getEntity, ClientPerson.class, 4);person response.getBody();assertEquals(Sandra, person.getName());} } PostOperationsTest验证是否已添加新资源 RunWith(BlockJUnit4ClassRunner.class) public class PostOperationsTest {private static final String POST_URL http://localhost:8081/int-http-xml/spring/persons;private static final String GET_URL http://localhost:8081/int-http-xml/spring/persons/{personId};private final RestTemplate restTemplate new RestTemplate();//build headers methodTestpublic void addResource_noContentStatusCodeReturned() {ClientPerson person new ClientPerson(9, Jana);HttpEntityClientPerson entity new HttpEntityClientPerson(person, buildHeaders());ResponseEntityClientPerson response restTemplate.exchange(POST_URL, HttpMethod.POST, entity, ClientPerson.class);assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());HttpEntityInteger getEntity new HttpEntity(buildHeaders());response restTemplate.exchange(GET_URL, HttpMethod.GET, getEntity, ClientPerson.class, 9);person response.getBody();assertEquals(Jana, person.getName());} }5.删除操作 我们的RESTful API的最后一个操作是删除操作。 这次我们为此使用一个单通道适配器 int-http:inbound-channel-adapter channelhttpDeleteChannel status-code-expressionT(org.springframework.http.HttpStatus).NO_CONTENTsupported-methodsDELETE path/persons/{personId} payload-expression#pathVariables.personIdint-http:request-mapping consumesapplication/json/ /int-http:inbound-channel-adapterint:service-activator refpersonEndpoint methoddelete input-channelhttpDeleteChannel/ 通道适配器使我们可以定义返回的状态代码并且正在使用有效负载表达式属性将请求的personId映射到消息正文。 该配置与先前操作中的配置略有不同但是这里没有任何未解释的内容。 服务激活者我们的人员端点将请求人员服务删除此资源。 public void delete(MessageString msg) {long id Long.valueOf(msg.getPayload());service.deletePerson(id); } 最后所需的测试 RunWith(BlockJUnit4ClassRunner.class) public class DeleteOperationsTest {private static final String URL http://localhost:8081/int-http-xml/spring/persons/{personId};private final RestTemplate restTemplate new RestTemplate();//build headers methodTestpublic void deleteResource_noContentStatusCodeReturned() {HttpEntityInteger entity new HttpEntity(buildHeaders());ResponseEntityClientPerson response restTemplate.exchange(URL, HttpMethod.DELETE, entity, ClientPerson.class, 3);assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());try {response restTemplate.exchange(URL, HttpMethod.GET, entity, ClientPerson.class, 3);Assert.fail(404 error expected);} catch (HttpClientErrorException e) {assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());}} }六结论 这篇文章是对我们的应用程序的介绍目的是从已知的角度xml配置了解它的结构。 在本教程的下一部分中我们将使用Java DSL来实现相同的应用程序。 该应用程序将配置为可与Java 8一起运行但是当使用lambda时我还将展示如何使用Java 7来完成。 我正在Google Plus和Twitter上发布我的新帖子。 如果您要更新新内容请关注我。 翻译自: https://www.javacodegeeks.com/2014/12/exposing-http-restful-api-with-inbound-adapters-part-1-xml.html
http://www.zqtcl.cn/news/58190/

相关文章:

  • 五道口网站建设html5开发网站
  • 儋州网站设计公司网站娱乐一条龙搭建
  • 遵义市住房和城乡建设厅网站seo专员是什么职业岗位
  • 齐齐哈尔住房和城乡建设局网站苏州模板建站哪家好
  • 接做网站的网站首页设计布局方式
  • 盘锦微信网站建设汕头企业网站建设公司
  • 在哪些软件上建设网站上传网站 php 服务器
  • 四川省省建设厅网站天津网站开发招聘
  • 如何设网站主页做网站空间不给账号密码
  • 梧州网站建设流程网站主要内容
  • 广东网页制作与网站建设广州域名注册
  • 商务网站建设与推广实训意义优秀营销策划方案
  • 免费网站安全检测网站空间流量6g
  • 郫县做网站公司网站经典案例
  • 免费建小程序网站百度广告官网
  • 网站文章不显示企业网站展示生产的处方药介绍处罚案件
  • 做关键词优化需要修改网站标题微信wordpress小程序
  • 网站页面引导怎么做哪里有做网站排名优化
  • 适合医药公司做网站的图片南京做网站费用
  • 广州品牌型网站wordpress加视频
  • 网站建设主要课程wd网址怎么推广
  • 用dw建设网站外贸做的亚马逊网站是哪个好
  • 鄂州网签查询天津百度推广排名优化
  • 设计公司网站推广营销哪个网站做logo好
  • 网站安全措施魅族官方网站挂失手机找到怎么做
  • 网站内链技巧三栏wordpress 主题
  • 网站制作原理中国建设银行天津分行网站
  • 郑州做网站公司有哪些宣传型电子商务网站
  • wordpress是模板建站苏州网站
  • 关于企业网站建设的提案深圳网络推广公司哪家好