从uddi java中查找并调用Web服务

时间:2015-04-25 16:46:46

标签: java eclipse web-services juddi

所以我一直在寻找好几天,但仍然无法找到一种简单的工作方法。这就是我想要做的事情:

1 - 根据关键字搜索和查找在UDDI中注册的Web服务 2 - 确定适合和使用/称呼的服务

所有这些都使用Java(Eclipse)。

我不想创建自己的uddi,也不想发布服务,只需找到存储在公共UDDI中的现有服务(我相信那里有一个,对吧?)。我认为这两个任务(找到WS,调用WS)很容易,并且可以找到要使用的示例代码,但我找不到。

我在搜索时遇到了Juddi,但不确定它是否适用于我的情况以及它是否值得安装。

任何教程?建议?我找到了以下代码,但无法找到jar文件来使用它的库:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uddi.createbulk;

import javax.xml.bind.JAXB;
import org.apache.juddi.v3.client.config.UDDIClient;
import org.apache.juddi.v3.client.config.UDDIClientContainer;
import org.apache.juddi.v3.client.transport.Transport;
import org.apache.juddi.v3_service.JUDDIApiPortType;
import org.uddi.api_v3.*;
import org.uddi.v3_service.UDDIInquiryPortType;
import org.uddi.v3_service.UDDIPublicationPortType;
import org.uddi.v3_service.UDDISecurityPortType;

/**
 *
 * @author Alex
 */
public class UddiFindService {

    private static UDDISecurityPortType security = null;
    private static JUDDIApiPortType juddiApi = null;
    private static UDDIPublicationPortType publish = null;
    private static UDDIInquiryPortType inquiry = null;

    public UddiFindService() {
        try {
            // create a manager and read the config in the archive; 
            // you can use your config file name
            UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
            // register the clerkManager with the client side container
            UDDIClientContainer.addClient(clerkManager);
            // a ClerkManager can be a client to multiple UDDI nodes, so 
            // supply the nodeName (defined in your uddi.xml.
            // The transport can be WS, inVM, RMI etc which is defined in the uddi.xml
            Transport transport = clerkManager.getTransport("default");
            // Now you create a reference to the UDDI API
            security = transport.getUDDISecurityService();
            juddiApi = transport.getJUDDIApiService();
            publish = transport.getUDDIPublishService();
            inquiry = transport.getUDDIInquiryService();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void find() {
        try {
            // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges
            // and can save other publishers).
            GetAuthToken getAuthTokenRoot = new GetAuthToken();
            getAuthTokenRoot.setUserID("root");
            getAuthTokenRoot.setCred("root");

            // Making API call that retrieves the authentication token for the 'root' user.
            AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
            System.out.println("root AUTHTOKEN = " + rootAuthToken.getAuthInfo());

            GetServiceDetail fs = new GetServiceDetail();
            fs.setAuthInfo(rootAuthToken.getAuthInfo());
            fs.getServiceKey().add("mykey");
            ServiceDetail serviceDetail = inquiry.getServiceDetail(fs);
            if (serviceDetail == null || serviceDetail.getBusinessService().isEmpty()) {
                System.out.println("mykey is not registered");
            } else {
                JAXB.marshal(serviceDetail, System.out);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String args[]) {
        UddiFindService sp = new UddiFindService();
        sp.find();
    }
}

0 个答案:

没有答案