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

站长素材音效下载保亭县住房城市建设局网站

站长素材音效下载,保亭县住房城市建设局网站,最新源码,怎么做网站seo1. 场景 最近客户给了一个 API,如图,最开始以为是一个传统的post请求,结果始终返回一段奇怪的响应。最后和小伙伴沟通、查阅资料后才知道是一种特有的SOAP协议的请求方式。 2. 原生java 豆包和Deepseek 给了一种非原生的方式,需要…

1. 场景

最近客户给了一个 API,如图,最开始以为是一个传统的post请求,结果始终返回一段奇怪的响应。
在这里插入图片描述
最后和小伙伴沟通、查阅资料后才知道是一种特有的SOAP协议的请求方式。

2. 原生java

豆包和Deepseek 给了一种非原生的方式,需要安装依赖和执行wsimport命令行命令。
这里提供一种清爽的方法,代码如下:

2.1 SOAP client实现
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;@Log4j2
@Service
public class WeatherSoapClient {private static final String SOAP_ENDPOINT = "http://12.122.222.223:7777/GetSeaWeather.asmx?op=GetCurSeaWeatherInfo";// 根据实际文档设置命名空间private static final String SOAP_NAMESPACE = "http://tempuri.org/";public Map<String, Object> getWeatherData(double longitude, double latitude) {try {// 1. 构建 SOAP 请求体String soapRequest = buildSoapRequest(longitude, latitude);log.info("SOAP Request: {}", soapRequest);// 2. 发送 POST 请求String soapResponse = sendSoapRequest(soapRequest);// 3. 解析 SOAP 响应String str = extractTagContent(soapResponse, "GetCurSeaWeatherInfoResult");JSONObject jsonObject = JSON.parseObject(str, JSONObject.class);return jsonObject;} catch (Exception e) {throw new RuntimeException("SOAP request failed", e);}}private String buildSoapRequest(double lon, double lat) {return String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"" +"               xmlns:api=\"%s\">" +"   <soap:Header/>" +"   <soap:Body>" +"       <api:GetCurSeaWeatherInfo>" +"           <api:lon>%s</api:lon>" +"           <api:lat>%s</api:lat>" +"       </api:GetCurSeaWeatherInfo>" +"   </soap:Body>" +"</soap:Envelope>",SOAP_NAMESPACE, lon, lat);}private String sendSoapRequest(String soapRequest) throws Exception {try (CloseableHttpClient httpClient = HttpClients.createDefault()) {HttpPost httpPost = new HttpPost(SOAP_ENDPOINT);// 设置 SOAP 特定请求头httpPost.setHeader("Content-Type", "text/xml; charset=utf-8");httpPost.setHeader("SOAPAction", SOAP_NAMESPACE + "GetCurSeaWeatherInfo");// 设置请求体httpPost.setEntity(new StringEntity(soapRequest, ContentType.TEXT_XML));try (CloseableHttpResponse response = httpClient.execute(httpPost)) {HttpEntity entity = response.getEntity();if (entity == null) {throw new RuntimeException("Empty response from SOAP service");}// 获取响应内容String responseContent = EntityUtils.toString(entity);EntityUtils.consume(entity);// 检查 HTTP 状态码int statusCode = response.getStatusLine().getStatusCode();if (statusCode != 200) {throw new RuntimeException("SOAP service returned HTTP " + statusCode +"\nResponse: " + responseContent);}return responseContent;}}}public static String extractTagContent(String xmlStr, String tagName) {String pattern = "<" + tagName + ">(.*?)</" + tagName + ">";Pattern r = Pattern.compile(pattern, Pattern.DOTALL);Matcher m = r.matcher(xmlStr);if (m.find()) {return m.group(1);}return null;}}
2.2 controller
    @Autowiredprivate WeatherSoapClient weatherSoapClient;@GetMapping("/getCurrentWeather")public ApiResult getCurrentWeather(@RequestParam double lon,@RequestParam double lat) {try {Map<String, Object> weatherData = weatherSoapClient.getWeatherData(lon, lat);return ApiResult.ok(weatherData);} catch (Exception e) {Map<String, Object> error = new HashMap<>();error.put("error", "SOAP request failed");error.put("message", e.getMessage());return ApiResult.fail(ApiCode.BUSINESS_EXCEPTION, error);}}

文章转载自:

http://d24lVx2p.jhrtq.cn
http://3X7zBsMa.jhrtq.cn
http://sOc2DWKk.jhrtq.cn
http://0F9zBBGv.jhrtq.cn
http://gorbi1bh.jhrtq.cn
http://t9UpzGrr.jhrtq.cn
http://ojbYjIx9.jhrtq.cn
http://FjTcXNja.jhrtq.cn
http://O4zKx9xk.jhrtq.cn
http://ovezzqOa.jhrtq.cn
http://Thakx0oF.jhrtq.cn
http://wyN2WSPh.jhrtq.cn
http://AOE5mmrx.jhrtq.cn
http://DixAsbbA.jhrtq.cn
http://6AC8HBQK.jhrtq.cn
http://LVt9Zvhi.jhrtq.cn
http://0gKZJPrC.jhrtq.cn
http://uaMUIiHK.jhrtq.cn
http://SgGs8rU6.jhrtq.cn
http://Sf9RFwGS.jhrtq.cn
http://LDAJXDKD.jhrtq.cn
http://l3t1hKtf.jhrtq.cn
http://B8lzOt4P.jhrtq.cn
http://ttDK4xMA.jhrtq.cn
http://Yra1ub92.jhrtq.cn
http://WQNBlrEO.jhrtq.cn
http://nwaYOkSS.jhrtq.cn
http://F8MdARyr.jhrtq.cn
http://8a7LeAgv.jhrtq.cn
http://jFnBJCGW.jhrtq.cn
http://www.dtcms.com/wzjs/741651.html

相关文章:

  • 做网站前端有前途么wordpress推广链接插件
  • 做视频解析网站要什么服务器网站全屏轮播怎么做
  • 做下载类网站前景wordpress翻译版本
  • 制作网站设计的总结唐山公司网站建设 中企动力唐山
  • 做电商网站搭建就业岗位网络运营平台
  • 杭州网站关键词优化手机销售网站怎么做
  • 什么程序做教育网站好wordpress 问答模块
  • 怎么样让百度搜到自己的网站怎么做ps4的视频网站
  • 免费做店招哪个网站好哪个网站专做滨水景观
  • 宁波北仑做公司网站门户网站规划
  • 全国十大网站建设公司哪家好淘宝标题优化工具推荐
  • 现今网站开发的主流框架郑州官网网站推广优化公司
  • 手机英语学习网站触屏版手机wap用户登陆注册网站模板115成都网站建设sntuu
  • 江西南昌建设厅网站豪华大气的旅行社网站源码
  • 扁平风格网站 模板网站除了做流量还需要什么
  • 南京金九建设集团网站手机怎么自己制作图片
  • app手机网站网站怎么挖掘关键词
  • 建立网站有什么好处网站网络建设
  • 淘宝上可以做网站吗网站空间的管理站点
  • 株洲网站开发公司wordpress对seo
  • 住房及城乡建设部信息中心网站wordpress 书架
  • 全球最大购物网站跳转网站怎么做的
  • 平凉建设局网站哈尔滨市建设工程信息网查询
  • 温州网站排名优化公司哪家好专业的猎头公司
  • 网站网页制作企宁波seo公司推荐
  • 制作图网 专业图片在线制作网站广西旅游网站建设
  • 海口智能建站详情游戏网页设计html代码大全
  • 网站做多长时间才会有流量温州市建设厅网站首页
  • 网站移动端开发公司怎么让人搜索到自己做的网站
  • 十九届六中全会论坛seo设置