import net.sf.json.JSONObject;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
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.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.encoding.XMLType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@Component
public class DemoUtil {
/**
* cxf调用示例
*/
@RequestMapping("/cxfService")
public void testWeb(){
String url = "http://11.23.0.28:8456/ws/author";
String method = "getAuthorByName";
Object parameters = "张三";
System.out.println(invokeRemoteMethod(url, method, parameters)[0]);
}
public static void main(String[] args) {
//广电的webservice地址
String gdUrl = "";
//广电请求json
String requestInfo = "{\"commonTradeInfo\":{\"sn\":\"a1\",\"verificationCode\":\"147451561a800880b5bedae8a16cf32f\",\"source\":\"sdjcy\",\"areaCode\":\"LY\"},\"identificationType\":\"1\",\"identificationNo\":\"13120214874\"}";
//调用的方法名 findCustomers查询开户的方法 findCustomerOrders查询受理记录的方法
String method = "findCustomers";
//调用广电webservice
System.out.println(invokeRemoteMethod(gdUrl, method, requestInfo)[0]);
}
/**
* cxf调用示例
* @param url
* @param operation
* @param parameters object数组
* @return
*/
public static Object[] invokeRemoteMethod(String url, String operation, Object[] parameters) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
if (!url.endsWith("wsdl")) {
url += "?wsdl";
}
org.apache.cxf.endpoint.Client client = dcf.createClient(url);
//处理webService接口和实现类namespace不同的情况,CXF动态客户端在处理此问题时,会报No operation was found with the name的异常
Endpoint endpoint = client.getEndpoint();
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), operation);
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
if (bindingInfo.getOperation(opName) == null) {
for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
if (operation.equals(operationInfo.getName().getLocalPart())) {
opName = operationInfo.getName();
break;
}
}
}
Object[] res = null;
try {
res = client.invoke(opName, parameters);
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
/**
* cxf调用示例
* @param url
* @param operation
* @param parameters object对象
* @return
*/
public static Object[] invokeRemoteMethod(String url, String operation, Object parameters) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
if (!url.endsWith("wsdl")) {
url += "?wsdl";
}
org.apache.cxf.endpoint.Client client = dcf.createClient(url);
//处理webService接口和实现类namespace不同的情况,CXF动态客户端在处理此问题时,会报No operation was found with the name的异常
Endpoint endpoint = client.getEndpoint();
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), operation);
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
if (bindingInfo.getOperation(opName) == null) {
for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
if (operation.equals(operationInfo.getName().getLocalPart())) {
opName = operationInfo.getName();
break;
}
}
}
Object[] res = null;
try {
res = client.invoke(opName, parameters);
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
/**
* axis 调用webservice接口示例
* @param inputXml
* @param methodName
* @return
* @throws Exception
*/
public String callinvoke(String inputXml, String methodName) throws Exception {
String webServiceURL = "httpy/*******V***V****";
String targetNamespace = "********";
QName servicename = new QName(webServiceURL, targetNamespace);
javax.xml.rpc.Service service = ServiceFactory.newInstance().createService(servicename);
javax.xml.rpc.Call call = service.createCall();
call.setTargetEndpointAddress(webServiceURL);
QName operationname = new QName(targetNamespace, methodName);
call.setOperationName(operationname);
call.addParameter("inputXml",XMLType.XSD_STRING, ParameterMode.IN);
QName returnname = new QName(targetNamespace, "string");
call.setReturnType(returnname, String.class);
String result = call.invoke(new Object[]{inputXml}).toString();
return result;
}
//http get
public static String getURLContent(String httpUrl) {
CloseableHttpClient httpCilent = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(httpUrl);
Map<String, Object> resultMap = new HashMap<>();
try {
CloseableHttpResponse response = httpCilent.execute(httpGet);
if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
resultMap.put("flag", HttpStatus.SC_OK);
resultMap.put("result", EntityUtils.toString(response.getEntity()));
//处理返回结果
String result = (String) resultMap.get("result");
return result;
} else {
resultMap.put("flag", response.getStatusLine().getStatusCode());
}
} catch (IOException e) {
resultMap.put("flag", 0);
e.printStackTrace();
}
return null;
}
//http post方式
public static String getURLContent(String httpUrl,Map<String,String> params) {
CloseableHttpClient httpCilent = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
JSONObject jsonObject=JSONObject.fromObject(params);
String json = jsonObject.toString();
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(httpUrl);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpCilent.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
return resultString;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}
相关推荐
电赛备赛笔记:用STM32驱动AD9959信号发生器模块,从接线到出波保姆级教程
本文详细介绍了如何使用STM32驱动AD9959信号发生器模块,从硬件接线到软件调试的全流程。AD9959作为高性能DDS芯片,适用于电子设计竞赛中的信号生成需求。文章包含硬件连接指南、寄存器配置解析、多通道控制技巧以及常见问题解决方案,帮助参赛者快速掌握AD9959的应用。
HttpSampler进行模拟webservice接口
webservice接口,使用HttpSampler进行模拟,注意点说明: 1、 2、 3、 4、 如果没有头信息,soap1.0的版本会返回错误body,如下, PS:soap1.2存在细微差别 转载于:https://www.cnblogs.com/Miss-Elsa/p/10044218.html...
科研党必看!Zotero+Claude3插件实战:如何用AI高效阅读文献(附详细配置步骤)
本文详细介绍了如何通过Zotero与Claude3插件的深度整合,实现科研文献的高效阅读与管理。从环境配置到核心功能实战,包括智能摘要生成、精准学术翻译和论文写作辅助等,帮助科研人员大幅提升工作效率。特别适合需要处理大量文献的研究者使用。
Spring Boot 集成 WebServiceTemplate使用
增加maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> WebServiceTemplate使用 //服务端WSDL String uri="?wsdl"; StringBuffer source = new S
EPICS电机支持(asynMotor)
EPICS电机支持(asynMotor)
【Flow3D实战】从零构建水利冲淤模型:关键步骤与参数详解
本文详细介绍了使用Flow3D构建水利冲淤模型的关键步骤与参数设置技巧。从基础认知到前处理、计算设置和后处理,全面解析如何高效模拟水流与泥沙的相互作用,特别适用于桥墩冲刷、水库泄洪等工程场景。通过实战案例分享,帮助读者掌握Flow3D在水利工程中的精准应用,提升模型精度与计算效率。
基于soapui的webservice模拟方法
客户端和服务端进行测试,如下图,请求界面,路径设置与服务端路径一致,点击请求按钮,服务端返回响应参数,如下图。创建成功,如下图,左侧展示提供的所有接口,客户端模拟成功。编辑完服务名称,点击确定,新建一个服务端成功,如下图,左侧新增一个。弹出服务名称编辑界面,如下图,默认已填入服务端名称,可自行修改。如下图,左侧新增一个对应的服务,点击运行服务,模拟服务端成功。如下图,左侧加载响应的接口服务,运行服务,接口服务端模拟成功。如下图,弹出服务名称设置界面,设置服务名,点击确定。如下图,设置对应的响应参数,点击。
告别双系统!用Ventoy把Ubuntu 22.04装进U盘,打造你的随身开发环境(附保姆级避坑指南)
本文详细介绍了如何使用Ventoy将Ubuntu 22.04安装到U盘,打造便携式开发环境。通过即插即用的特性,开发者可以在任何x86电脑上快速启动完整的Ubuntu系统,无需配置双系统或虚拟机。文章提供了从硬件准备到系统优化的全流程指南,帮助用户高效创建随身开发环境。
webservice的post请求中请求参数在postman中应用
点击 “Body” 选项卡,然后选择 “x-www-form-urlencoded”(如果需要将参数以表单形式传递)或 “raw”(如果需要自定义参数格式)。根据你的实际情况,选择合适的参数传递方式,如表单形式(“x-www-form-urlencoded”)或自定义格式(“raw”)。需要注意的是,不同的库可能有不同的用法和配置方式,但基本原理是相同的。时,请求体中的参数会按照键值对的形式进行编码,并且使用等号(=)将键和值连接起来,使用 “&” 符号分隔不同的键值对。
LLM Wiki 的完整输入体系:LLM Wiki极简实战
LLM Wiki 的输入分为**四大类**,覆盖从"原始知识注入"到"系统行为控制"的全流程,所有输入都遵循"**原始资料不可变,规则可迭代,人类反馈闭环**"的核心原则。
2024年上半年试题二:论性能测试方法及其应用
2025年1月,我以系统分析师的身份参与了公司OA系统的开发与建设。该系统包含的功能有打卡签到、公文流转、工资查询等。我们吸取了之前由于系统使用人数激增暴露出的短时间卡顿等问题,所以在本次开发中,我们非常重视系统的性能测试。通过自动化的测试工具模拟多种正常、峰值及异常负载条件对系统的各项性能指标进行测试。性能测试在软件的质量保证中起着重要的作用,它包括的测试内容丰富多样,常见的负载测试和压力测试都属于性能测试。
java模拟http和webservice请求并获取参数示例
主要是使用java进行模拟请求,不多说,直接上干货。 1、依赖 (1)httpclient: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> ...
PCL ICP算法实现点云精配准【2026最新版】
PCL1.14.1 及之前版本所实现的迭代最近点ICP算法。博客长期更新,本文最新更新时间为:2026年4月17日。
webservice(三)用http请求模拟请求webservice接口
封装的一个工具方法 /** * 请求webService返回xml字符串 * @param restTemplate {org.springframework.web.client.RestTemplate} * spring中用于http请求的RestTemplate,需要引入spring的依赖 * @p...
TMS_WebGMaps_1.9.8.0_Full_Source
TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
使用postman模拟http请求webservice服务
在webservice服务测试过程中简化使用后台代码发送请求,可以使用postman进行模拟http请求。
Data-Structures-and-Algorithm-Analysis-in-Java.pdf
作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...
JMeter之WebService(soap)请求
JMeter之WebService(soap)请求
蓝牙模块HM-10手册
蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。
java模拟浏览器发送http请求案例
最近做的webservice中有个单点登录的东西,单点登录时别人写的,我们只负责调用,但是他们把返回单点登录的信息写在了过滤器的doFilter方法中,于是我想着先发出一个http请求去请问我这边webservice服务端的过滤器,在请求过程中把doFilter方法中拿到的值写在项目的properties文件中,然后在webservice的服务端去读取今儿实现了在webservice中拿...
用java http post模拟soapUI调用webservice
工作中需要用java调用peoplesoft提供的webservice接口,但peoplesoft的实施方没有提供java调用的案例代码,soapUI可以调用,但java代码一直写不出来,自行学习并调通了用java http post模拟的方法,感谢天涯的zhouyun0243和谷歌! import java.io.BufferedReader; import java.io.File;
模拟http请求webService的body参数封装方法(SOAP请求)
/** * body 拼接 * * @param method 请求方法名 * @param params 参数 * @return */ public static String createWebServiceRequestBody(String method, Map<String, Object> params) { StringBuffer body = new StringBuffer("<?xml version=\"1.0\" encodin
java soapui xml_用java http post模拟soapUI调用webservice
工作中需要用java调用peoplesoft提供的webservice接口,但peoplesoft的实施方没有提供java调用的案例代码,soapUI可以调用,但java代码一直写不出来,自行学习并调通了用java http post模拟的方法,感谢天涯的zhouyun0243和谷歌!import java.io.BufferedReader;import java.io.File;import ...
使用Fiddler调用WebService接口,模拟发HTTP请求
1、百度一个免费WebService接口 如:天气预报http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 其下有一个方法 2、打开Fiddler,打开Composer,将从WebService界面上获取的相应信息填入以下相应区域后,点击Execute。 双击发出的请求,右下方可以看到WebService接口返回结果,如下。 ...
webService、webSocket、socket、http之间的区别
HTTP HTTP 是基于请求响应式的,即通信只能由客户端发起,服务端做出响应,无状态,无连接。 无状态:每次连接只处理一个请求,请求结束后断开连接。 无连接:对于事务处理没有记忆能力,服务器不知道客户端是什么状态。 以往实现即时通讯的手段: 轮询:客户端定时向服务器发送 Ajax 请求,服务器接到请求后马上返回响应信息并关...
java 调用soapui_用java http post模拟soapUI调用webservice
工作中需要用java调用peoplesoft提供的webservice接口,但peoplesoft的实施方没有提供java调用的案例代码,soapUI可以调用,但java代码一直写不出来,自行学习并调通了用java http post模拟的方法,感谢天涯的zhouyun0243和谷歌!import java.io.BufferedReader;import java.io.File;import ...
curl 请求wsdl php,curl 请求 webservice
在项目对接中需要从对方服务器获取数据,对方提供的是标准的webservice接口。通过fiddler抓包发现,webservice其实是post请求加上data.xml数据,所以使用curl post请求模拟webservicecurl -request POST --header "SOAPAction: ''" --data @data.xml http://ip:8080/project/s...
WebService服务模拟HttpPost、HttpGet调用
web.asmx页面写webService服务的方法 /// <summary> /// 插入 /// </summary> /// <param name="list"></param> [WebMethod] public void InsertDealerCh...
366



被折叠的 条评论
为什么被折叠?



