public class Test2 {
public String getCurrentData(string aCode,string bCode){
String url = "http://bdlj/Servicfirst?wsdl";
Client client = new Client(new URL(url));
Object[] retunObjs = null;
retunObjs = client.invoke("getCurrentData", new Object[] {"HRD_a","HRD_b"});//a编号150102283,b编号150200042
System.out.println(retunObjs[0].toString());
}
}
}
public String getCurrentData(string aCode,string bCode){
String url = "http://bdlj/Servicfirst?wsdl";
Client client = new Client(new URL(url));
Object[] retunObjs = null;
retunObjs = client.invoke("getCurrentData", new Object[] {"HRD_a","HRD_b"});//a编号150102283,b编号150200042
System.out.println(retunObjs[0].toString());
}
}
}
//通过wsdl服务描述文件创建客户端工厂。
Client client = factory.createClient("http://172.18.48.150:8080/WebServicePro/service/HelloWorldService?wsdl");
//invoke(
//String operationName:要调用的方法名
//Object... params):方法的入参。可以是多个。
Document document = DocumentHelper.createDocument();
Element root = document.addElement("root");
Element child = root.addElement("child");
child.setText("我是兒子!");
String xmlString = document.asXML();
Object[] objs = client.invoke("sayHello", xmlString);
//invoke方法是默认返回Object[]数组。取出数组的第一位值得值就是返回值。
System.out.println(objs[0].toString());
都改了myeclipse就是通不过
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;import com.fasterxml.jackson.core.JsonProcessingException;@Service
public class CustomRestTemplate extends RestTemplate { private final Logger logger = LoggerFactory.getLogger(CustomRestTemplate.class);
@Autowired
CommonProperties commonProperties;
@Autowired
RestTemplate restTemplate; /**
* 提交服务器
*
* @param uri 地址
* @param map 头部
* @param hashMap 表单参数
* @return
* @throws JsonProcessingException
*/
public String custom_postForObject(String uri, Map<String, String> map) throws JsonProcessingException {
HttpHeaders header = new HttpHeaders();
MediaType mediaType = MediaType.parseMediaType("application/json;charset=utf-8");
header.setContentType(mediaType);
header.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString()); // 1、URL地址
String url = commonProperties.getPhp_root() + uri;
if (map != null) {
Set<String> set = new HashSet<String>();
for(Entry<String, String> item:map.entrySet())
set.add(item.getKey()+"="+item.getValue());
url = url +"?"+ StringUtils.join(set,"&");
}
// 2、提交
String result = "";
try{
result = restTemplate.postForObject(url, null, String.class);
}
catch(Exception ex)
{
logger.error(ex.getMessage() + ";url:"+ url);
}
return result;
}
/**
* 提交服务器
*
* @param uri 地址
* @param headerParams 头部
* @param bodyJsonParams 表单参数
* @return
* @throws JsonProcessingException
*/
public String custom_postForm(String uri, Map<String, String> headerParams, Map<String, String> bodyFormParams) throws JsonProcessingException {
// 1、URL地址
String url = commonProperties.getPhp_root() + uri;
if (headerParams != null) {
Set<String> set = new HashSet<String>();
for(Entry<String,String> item:headerParams.entrySet())
set.add(item.getKey()+"="+item.getValue());
url = url +"?"+ StringUtils.join(set,"&");
}
// 2、Header
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // 3、Body
MultiValueMap<String, String> body= new LinkedMultiValueMap<String, String>();
for(Entry<String,String> item:bodyFormParams.entrySet())
body.add(item.getKey(), item.getValue());
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(body, headers);
String data ="";
try
{
ResponseEntity<String> response = restTemplate.postForEntity( url, request , String.class );
data = response.getBody();
}
catch(Exception ex)
{
logger.error(ex.getMessage());
}
return data;
}
/**
* 提交服务器
*
* @param uri 地址
* @param headerParams 头部
* @param bodyJsonParams 表单参数
* @return
* @throws JsonProcessingException
*/
public String custom_postForObject(String uri, Map<String, String> headerParams, String bodyJsonParams) throws JsonProcessingException {
HttpHeaders header = new HttpHeaders();
MediaType mediaType = MediaType.parseMediaType("application/json;charset=utf-8");
header.setContentType(mediaType);
header.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString()); // 1、URL地址
String url = commonProperties.getPhp_root() + uri;
if (headerParams != null) {
Set<String> set = new HashSet<String>();
for(Entry<String,String> item:headerParams.entrySet())
set.add(item.getKey()+"="+item.getValue());
url = url +"?"+ StringUtils.join(set,"&");
}
// 1、Form
HttpEntity<String> formEntity = new HttpEntity<String>("",header);
if (bodyJsonParams != null && bodyJsonParams.equals("")==false) {
formEntity = new HttpEntity<String>(bodyJsonParams,header);
} // 2、提交
String result = "";
try {
result = restTemplate.postForObject(url, formEntity, String.class);
}
catch(Exception ex)
{
logger.error(ex.getMessage());
}
return result;
}
}