esb 9 years ago
parent
commit
2f42aa0c72

+ 1 - 1
Hos-Resource-WS/src/main/java/com.yihu.ehr/common/ApplicationStart.java

@ -11,6 +11,7 @@ import com.yihu.ehr.util.log.LogUtil;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.xml.stream.XMLInputFactory;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -77,7 +78,6 @@ public class ApplicationStart implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent context) {
    }
    public static void main(String[] args) {

+ 11 - 5
Hos-Resource-WS/src/main/java/com.yihu.ehr/ws/SQLWebService.java

@ -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属性
            }