0

我最近才在我的肥皂服务器上安装,以防止人们在访问肥皂服务器时建立BoneCP过多的连接。mysql在我切换到boneCPsoap服务器之前工作正常,但是现在在我安装之后boneCP我可以看到WSDL如果我直接转到它的链接,但是当我将相同的链接加载到soapUI它时会加载wsdl但不显示任何功能全部。我的代码如下:

package testing;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import javax.xml.ws.Endpoint;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;
import com.sun.net.httpserver.*;

@WebService
public class test {

    static BoneCP connectionPool = null;
    static Connection con = null;


    @WebMethod
    public String login(@WebParam(name="username")String username,@WebParam(name="password") String password) throws SQLException {

        con = connectionPool.getConnection();
        Statement stmt = null;
        String query = " CALL authorize_user('" + username + "','" + password + "')";

        try {
            stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next()) {
                String login = rs.getString("au_result");

                if (login != null){
                    con.close();
                    return login;
                }
                else {
                    con.close();
                    return "Login Failed";
                }
            }
        } catch (SQLException e) {
            System.out.println("Error: " + e);
        } finally {
            if (stmt != null) {
                stmt.close();
            }
        }
        con.close();
        return "Login Failed";
    }


    public static void main(String[] args) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException, KeyManagementException, NoSuchProviderException {

        try{
            Class.forName("com.mysql.jdbc.Driver");

        }catch(Exception e){
            e.printStackTrace();
            return;
        }

        try{
            BoneCPConfig config = new BoneCPConfig();
            config.setJdbcUrl("jdbc:mysql://localhost:" + port + "/test");
            config.setUsername(username);
            config.setPassword(password);
            config.setMinConnectionsPerPartition(5);
            config.setMaxConnectionsPerPartition(10);
            config.setPartitionCount(1);
            connectionPool = new BoneCP(config);

            if(con != null){
                System.out.println("Connection successful");
            }
        }catch(Exception e){
            e.printStackTrace();
        }

        test test = new test();

        Endpoint endpoint = Endpoint.create(test);
        String uri = "/testing";
        String keystoreFile = "keystore.jks";
        String keyPass = "test_pass";
        int port = 8080;

        SSLContext ssl = SSLContext.getInstance("TLS");

        KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        KeyStore store = KeyStore.getInstance("JKS");

        store.load(new FileInputStream(keystoreFile),keyPass.toCharArray());

        keyFactory.init(store, keyPass.toCharArray());

        TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

        trustFactory.init(store);

        ssl.init(keyFactory.getKeyManagers(),
        trustFactory.getTrustManagers(), new SecureRandom());

        HttpsConfigurator configurator = new HttpsConfigurator(ssl);

        HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(port), 50);
        System.out.println("https server: " + httpsServer.getAddress());

        httpsServer.setHttpsConfigurator(configurator);

        com.sun.net.httpserver.HttpContext httpContext = httpsServer.createContext(uri);

        httpsServer.start();

        endpoint.publish(httpContext);
    }
}

这段代码与我一周前使用的工作代码基本完全相同,除了 main 方法中的 boneCP 部分。

4

1 回答 1

0

对于任何有兴趣并且将来可能会遇到这个问题的人:我在我的代码中发现了错误,它实际上根本没有与boneCP相关,而不是与@webparam(name = "")我的代码中其他一些函数的代码有关. 这些名称中有空格,因此在soap服务器中引起了问题。

于 2013-05-17T18:47:41.957 回答