|
@ -9,17 +9,23 @@ import org.apache.commons.dbcp2.BasicDataSource;
|
|
|
import org.apache.cxf.endpoint.Client;
|
|
|
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.jws.WebService;
|
|
|
|
|
|
/**
|
|
|
* Created by Administrator on 2016/5/19.
|
|
|
*/
|
|
|
@WebService(endpointInterface = "com.yihu.ehr.ws.inf.ISQLWebService", targetNamespace = "com.yihu.ehr.ws.inf")
|
|
|
//@WebService(endpointInterface = "com.yihu.ehr.ws.inf.ISQLWebService", targetNamespace = "com.yihu.ehr.ws.inf")
|
|
|
@Controller
|
|
|
@RequestMapping("sql")
|
|
|
public class SQLWebService implements ISQLWebService {
|
|
|
public static JdbcTemplate jdbcTemplate = null;
|
|
|
|
|
|
@Override
|
|
|
@RequestMapping("excuteSQL")
|
|
|
@ResponseBody
|
|
|
public String excuteSQL(String sql) {
|
|
|
try {
|
|
|
if (jdbcTemplate == null) {
|
|
@ -73,7 +79,7 @@ public class SQLWebService implements ISQLWebService {
|
|
|
System.out.println(jdbcTemplate.queryForList(sql));
|
|
|
JSONArray jo = JSONArray.fromObject(jdbcTemplate.queryForList(sql));
|
|
|
XMLSerializer xmlSerializer = new XMLSerializer();
|
|
|
xmlSerializer.setRootName("req");
|
|
|
xmlSerializer.setRootName("Return");
|
|
|
xmlSerializer.setElementName("data");
|
|
|
xmlSerializer.setTypeHintsEnabled(false);//设置data class="object" 没有class
|
|
|
// xmlSerializer.setForceTopLevelObject(false);
|
|
@ -89,10 +95,10 @@ public class SQLWebService implements ISQLWebService {
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
|
|
|
Client client = factory.createClient("http://localhost:8080/service/sql?wsdl");
|
|
|
Client client = factory.createClient("http://172.19.103.37:8081/service/sql?wsdl");
|
|
|
|
|
|
try {
|
|
|
Object[] result = client.invoke("excuteSQL", "select * from stde_adapter_metadata"); // 按照方法的参数来提供值
|
|
|
Object[] result = client.invoke("excuteSQL", "select * from HDSC01_03"); // 按照方法的参数来提供值
|
|
|
if (result != null && result.length > 0) {
|
|
|
System.out.println(result[0]); // 通过getUsername来获取对象的username属性
|
|
|
}
|