关于网友提出的“ 求救关于服务查找的程序?邦我看看!谢谢”问题疑问,本网通过在网上对“ 求救关于服务查找的程序?邦我看看!谢谢”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 求救关于服务查找的程序?邦我看看!谢谢描述:
//jaxrquerybyname.java
import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;
import java.net.*;
import java.util.*;
public class JAXRQueryByName {
static Connection connection = null;
public JAXRQueryByName() {}
public static void main(String[] args) {
String queryURL = "http://localhost:8080/RegistryServer";
String publishURL = "http://localhost:8080/RegistryServer";
if (args.length < 1) {
System.out.println("Usage: ant " + "-Dquery-string=
System.exit(1);
}
String queryString = new String(args[0]);
System.out.println("Query string is " + queryString);
JAXRQueryByName jq = new JAXRQueryByName();
connection = jq.makeConnection(queryURL, publishURL);
jq.executeQuery(queryString);
}
public Connection makeConnection(String queryUrl,
String publishUrl) {
String httpProxyHost = "";
String httpProxyPort = "";
System.setProperty("com.sun.xml.registry.ConnectionFactoryClass","com.sun.xml.registry.uddi.ConnectionFactoryImpl");
Properties props = new Properties();
props.setProperty("javax.xml.registry.factoryClass", "com.sun.xml.registry.uddi.ConnectionFactoryImpl");
props.setProperty("javax.xml.registry.queryManagerURL",queryUrl);
props.setProperty("com.sun.xml.registry.http.proxyHost", httpProxyHost);
props.setProperty("com.sun.xml.registry.http.proxyPort", httpProxyPort);
try {
ConnectionFactory factory = ConnectionFactory.newInstance();
factory.setProperties(props);
connection = factory.createConnection();
System.out.println("Created connection to registry");
} catch (Exception e) {
e.printStackTrace();
if (connection != null) {
try {
connection.close();
} catch (JAXRException je) {}
}
}
return connection;
}
public Collection executeQuery(String qString) {
RegistryService rs = null;
BusinessQueryManager bqm = null;
Collection orgs = null;
try {
rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
System.out.println("Got registry service and " + "query manager");
Collection findQualifiers = new ArrayList();
findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
Collection namePatterns = new ArrayList();
namePatterns.add(qString);
BulkResponse response = bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null);
orgs = response.getCollection();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return orgs;
}
public String getName(RegistryObject ro)
throws JAXRException {
try {
return ro.getName().getValue();
} catch (NullPointerException npe) {
return "No Name";
}
}
public String getDescription(RegistryObject ro)
throws JAXRException {
try {
return ro.getDescription().getValue();
} catch (NullPointerException npe) {
return "No Description";
}
}
public String getKey(RegistryObject ro)
throws JAXRException {
try {
return ro.getKey().getId();
} catch (NullPointerException npe) {
return "No Key";
}
}
}