分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

WebService 笔记

发布时间:2023-09-06 01:31责任编辑:胡小海关键词:Web
WebService服务端框架:jersey

WebService调用方式:jersey、http、spring RestTemplate


Server:

@Configurationpublic class ApplicationConfig {@Namedstatic class JerseyConfig extends ResourceConfig {public JerseyConfig() {this.packages("com.lenovo.li.content.controllers");}}@Beanpublic ObjectMapper objectMapper() {ObjectMapper objectMapper = new ObjectMapper();return objectMapper;}}

Pom

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jersey</artifactId></dependency>

Controller

@Named@Path("/Test")public class RestController {@POST@Path("/get/{url}")@Produces(MediaType.APPLICATION_JSON)public Test getTestContent(@PathParam("url") final String url, @RequestBody Context context)throws JsonParseException, JsonMappingException, IOException {}@PUT@Path("/update/{url}")@Produces(MediaType.APPLICATION_JSON)public Test updateTestContent(@PathParam("url") final String url, @RequestBody Page page)throws JsonParseException, JsonMappingException, IOException {}}

Client

public class TestClient{@AutowiredRestTemplate restTemplate;public String getTestContent(String name, Context context) {ResponseEntity<String> response = restTemplate.postForEntity(url, context,String.class);return response.getBody();}}

ClientXml

<bean id="drHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"/><bean id="restTemplate" class="org.springframework.web.client.RestTemplate" p:requestFactory-ref="drHttpRequestFactory" >        <property name="messageConverters">            <list>                <bean class="org.springframework.http.converter.StringHttpMessageConverter">                    <property name="supportedMediaTypes">                        <list>                            <value>text/plain;charset=UTF-8</value>                        <value>text/html;charset=UTF-8</value>                          <value>application/json; charset=UTF-8</value>                          </list>                    </property>                </bean>                <ref bean="mappingJackson2HttpMessageConverter"/>                                <bean class="org.springframework.http.converter.FormHttpMessageConverter"/>            </list>        </property></bean>


WebService 笔记

原文地址:http://blog.51cto.com/xinzhilian/2052807

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved