http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiDigitalSignatureTmodel.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiDigitalSignatureTmodel.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiDigitalSignatureTmodel.java new file mode 100644 index 0000000..608e8f4 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiDigitalSignatureTmodel.java @@ -0,0 +1,173 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import java.util.concurrent.atomic.AtomicReference; +import org.apache.juddi.v3.client.config.UDDIClient; +import org.apache.juddi.v3.client.config.UDDIClientContainer; +import org.apache.juddi.v3.client.cryptor.DigSigUtil; +import org.apache.juddi.v3.client.transport.Transport; +import org.uddi.api_v3.*; +import org.uddi.v3_service.UDDIInquiryPortType; +import org.uddi.v3_service.UDDIPublicationPortType; +import org.uddi.v3_service.UDDISecurityPortType; + +/** + * This class shows you how to digitally sign a tmodel and verify the signature + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiDigitalSignatureTmodel { + + private static UDDISecurityPortType security = null; + private static UDDIInquiryPortType inquiry = null; + private static UDDIPublicationPortType publish = null; + private static UDDIClient clerkManager = null; + + /** + * This sets up the ws proxies using uddi.xml in META-INF + */ + public UddiDigitalSignatureTmodel() { + try { + // create a manager and read the config in the archive; + // you can use your config file name + clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml"); + Transport transport = clerkManager.getTransport(); + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + inquiry = transport.getUDDIInquiryService(); + publish = transport.getUDDIPublishService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Main entry point + * + * @param args + */ + public static void main(String args[]) { + UddiDigitalSignatureTmodel sp = new UddiDigitalSignatureTmodel(); + sp.Fire(null, null); + } + + public void Fire(String token, String key) { + try { + DigSigUtil ds = null; + + //option 1), set everything manually + ds = new DigSigUtil(); + ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE, "keystore.jks"); + ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILETYPE, "JKS"); + ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE_PASSWORD, "Test"); + ds.put(DigSigUtil.SIGNATURE_KEYSTORE_KEY_ALIAS, "Test"); + ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_BASE64, "true"); + + ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SERIAL, "true"); + ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SUBJECTDN, "true"); + ds.put(DigSigUtil.TRUSTSTORE_FILE, "truststore.jks"); + ds.put(DigSigUtil.TRUSTSTORE_FILETYPE, "JKS"); + ds.put(DigSigUtil.TRUSTSTORE_FILE_PASSWORD, "Test"); + + //option 2), load it from the juddi config file + //ds = new DigSigUtil(clerkManager.getClientConfig().getDigitalSignatureConfiguration()); + //login + if (token == null) //option, load from juddi config + { + token = GetAuthKey(clerkManager.getClerk("default").getPublisher(), + clerkManager.getClerk("default").getPassword()); + } + if (key==null){ + SaveTModel stm = new SaveTModel(); + stm.setAuthInfo(token); + TModel tm = new TModel(); + tm.setName(new Name("my cool signed tmodel", null)); + stm.getTModel().add(tm); + TModelDetail saveTModel = publish.saveTModel(stm); + key = saveTModel.getTModel().get(0).getTModelKey(); + } + + TModel be = GetTmodelDetails(key); + if (!be.getSignature().isEmpty()) + { + System.out.println("WARN, the entity with the key " + key + " is already signed! aborting"); + return; + } + + //DigSigUtil.JAXB_ToStdOut(be); + System.out.println("signing"); + TModel signUDDI_JAXBObject = ds.signUddiEntity(be); + DigSigUtil.JAXB_ToStdOut(signUDDI_JAXBObject); + System.out.println("signed, saving"); + + SaveTModel sb = new SaveTModel(); + sb.setAuthInfo(token); + sb.getTModel().add(signUDDI_JAXBObject); + publish.saveTModel(sb); + System.out.println("saved, fetching"); + + be = GetTmodelDetails(key); + DigSigUtil.JAXB_ToStdOut(be); + System.out.println("verifing"); + AtomicReference<String> msg = new AtomicReference<String>(); + boolean verifySigned_UDDI_JAXB_Object = ds.verifySignedUddiEntity(be, msg); + if (verifySigned_UDDI_JAXB_Object) { + System.out.println("signature validation passed (expected)"); + } else { + System.out.println("signature validation failed (not expected)"); + } + System.out.println(msg.get()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private TModel GetTmodelDetails(String key) throws Exception { + // BusinessInfo get + GetTModelDetail r = new GetTModelDetail(); + r.getTModelKey().add(key); + return inquiry.getTModelDetail(r).getTModel().get(0); + } + + /** + * Gets a UDDI style auth token, otherwise, appends credentials to the + * ws proxies (not yet implemented) + * + * @param username + * @param password + * @param style + * @return + */ + private String GetAuthKey(String username, String password) { + try { + + GetAuthToken getAuthTokenRoot = new GetAuthToken(); + getAuthTokenRoot.setUserID(username); + getAuthTokenRoot.setCred(password); + + // Making API call that retrieves the authentication token for the 'root' user. + AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot); + System.out.println("root AUTHTOKEN = " + "don't log auth tokens!"); + return rootAuthToken.getAuthInfo(); + } catch (Exception ex) { + System.out.println("Could not authenticate with the provided credentials " + ex.getMessage()); + } + return null; + } +}
http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindBinding.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindBinding.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindBinding.java new file mode 100644 index 0000000..e257499 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindBinding.java @@ -0,0 +1,106 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import org.apache.juddi.v3.client.UDDIConstants; +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; + +/** + * This class shows you how to find an endpoint by searching through all + * services + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiFindBinding { + + private static UDDISecurityPortType security = null; + private static JUDDIApiPortType juddiApi = null; + private static UDDIPublicationPortType publish = null; + private static UDDIInquiryPortType inquiry = null; + + public UddiFindBinding() { + 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"); + Transport transport = clerkManager.getTransport(); + // 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 Fire(String token) { + 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"); + + if (token == null) { + // Making API call that retrieves the authentication token for the 'root' user. + AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot); + System.out.println("root AUTHTOKEN = " + "don't log auth tokens!"); + token = rootAuthToken.getAuthInfo(); + } + FindService fs = new FindService(); + fs.setAuthInfo(token); + fs.getName().add(new Name()); + fs.getName().get(0).setValue("%"); + fs.setFindQualifiers(new FindQualifiers()); + fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH); + + ServiceList findService = inquiry.findService(fs); + System.out.println(findService.getServiceInfos().getServiceInfo().size()); + GetServiceDetail gs = new GetServiceDetail(); + for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) { + gs.getServiceKey().add(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey()); + } + + ServiceDetail serviceDetail = inquiry.getServiceDetail(gs); + for (int i = 0; i < serviceDetail.getBusinessService().size(); i++) { + //System.out.println(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size()); + if (serviceDetail.getBusinessService().get(i).getBindingTemplates() != null) { + for (int k = 0; k < serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size(); k++) { + if (serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getAccessPoint() != null) { + System.out.println(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getAccessPoint().getValue()); + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) { + UddiFindBinding sp = new UddiFindBinding(); + sp.Fire(null); + } +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindEndpoints.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindEndpoints.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindEndpoints.java new file mode 100644 index 0000000..41fe7f9 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiFindEndpoints.java @@ -0,0 +1,78 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import java.util.List; +import org.apache.juddi.v3.client.config.UDDIClerk; +import org.apache.juddi.v3.client.config.UDDIClient; +import org.apache.juddi.v3.client.transport.Transport; +import org.uddi.v3_service.UDDIInquiryPortType; +import org.uddi.v3_service.UDDISecurityPortType; + +/** + * This class show you how get all available Access Points/Endpoints for a + * service. This is harder than it sounds due to the complexity of UDDI's data + * structure. The output is the list of URLs given a service's key + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiFindEndpoints { + + private static UDDISecurityPortType security = null; + private static UDDIInquiryPortType inquiry = null; + static UDDIClerk clerk = null; + + public UddiFindEndpoints() { + 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"); + clerk = clerkManager.getClerk("default"); + // 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(); + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + inquiry = transport.getUDDIInquiryService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void Fire(String authtoken, String key) { + try { + if (key == null) { + key = "uddi:juddi.apache.org:services-inquiry"; + } + + List<String> endpoints = clerk.getEndpoints(key); + System.out.println("Endpoints returned: " + endpoints.size()); + for (int i = 0; i < endpoints.size(); i++) { + System.out.println(endpoints.get(i)); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) { + UddiFindEndpoints sp = new UddiFindEndpoints(); + sp.Fire(null, null); + } +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiGetServiceDetails.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiGetServiceDetails.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiGetServiceDetails.java new file mode 100644 index 0000000..fccb9be --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiGetServiceDetails.java @@ -0,0 +1,95 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +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; + +/** + * This class show you how to get all available information for service + * (excluding OperationalInfo) + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiGetServiceDetails { + + private static UDDISecurityPortType security = null; + private static JUDDIApiPortType juddiApi = null; + private static UDDIPublicationPortType publish = null; + private static UDDIInquiryPortType inquiry = null; + + public UddiGetServiceDetails() { + 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"); + Transport transport = clerkManager.getTransport(); + // 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 Fire(String token, String key) { + if (key == null) { + System.out.println("No key provided!"); + return; + } + try { + // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges + // and can save other publishers). + if (token == null) { + + 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 = " + "don't log auth tokens!"); + token = rootAuthToken.getAuthInfo(); + } + GetServiceDetail fs = new GetServiceDetail(); + fs.setAuthInfo(token); + fs.getServiceKey().add(key); + 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[]) { + UddiGetServiceDetails sp = new UddiGetServiceDetails(); + sp.Fire(null, "uddi:juddi.apache.org:services-inquiry"); + } +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiKeyGenerator.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiKeyGenerator.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiKeyGenerator.java new file mode 100644 index 0000000..9350e0b --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiKeyGenerator.java @@ -0,0 +1,104 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import org.apache.juddi.v3.client.config.UDDIClerk; +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; + +/** + * This is an example how to make a UDDI key generator, which will enable you to + * make UDDI v3 keys with (almost) whatever pattern you want + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiKeyGenerator { + + private static UDDISecurityPortType security = null; + private static JUDDIApiPortType juddiApi = null; + private static UDDIPublicationPortType publish = null; + private static UDDIInquiryPortType inquiry = null; + + public UddiKeyGenerator() { + 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"); + Transport transport = clerkManager.getTransport(); + // 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 Fire(String token, String domain) { + try { + // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges + // and can save other publishers). + if (token == null) { + GetAuthToken getAuthTokenRoot = new GetAuthToken(); + getAuthTokenRoot.setUserID("uddi"); + getAuthTokenRoot.setCred("uddi"); + + // Making API call that retrieves the authentication token for the 'root' user. + AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot); + System.out.println("uddi AUTHTOKEN = " + "don't log auth tokens!"); + token = rootAuthToken.getAuthInfo(); + } + SaveTModel st = new SaveTModel(); + st.setAuthInfo(token); + st.getTModel().add(UDDIClerk.createKeyGenator(domain, domain, "en")); + TModelDetail saveTModel = publish.saveTModel(st); + + System.out.println("Saved! key = " + saveTModel.getTModel().get(0).getTModelKey()); + /* + //Hey! tModel Key Generators can be nested too! + st = new SaveTModel(); + st.setAuthInfo(rootAuthToken.getAuthInfo()); + st.getTModel().add(UDDIClerk.createKeyGenator("uddi:bea.com:servicebus.default:keygenerator", "bea.com:servicebus.default", "en")); + publish.saveTModel(st); + + // This code block proves that you can create tModels based on a nested keygen + st = new SaveTModel(); + TModel m = new TModel(); + m.setTModelKey("uddi:bea.com:servicebus.default.proxytest2"); + m.setName(new Name("name", "lang")); + st.setAuthInfo(rootAuthToken.getAuthInfo()); + st.getTModel().add(m); + publish.saveTModel(st); + + */ + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) { + UddiKeyGenerator sp = new UddiKeyGenerator(); + sp.Fire(null, "www.juddi.is.cool.org"); + } +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiRelatedBusinesses.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiRelatedBusinesses.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiRelatedBusinesses.java new file mode 100644 index 0000000..a1ca4d5 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiRelatedBusinesses.java @@ -0,0 +1,154 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import java.util.ArrayList; +import java.util.GregorianCalendar; +import java.util.List; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.ws.Holder; +import org.apache.juddi.v3.client.config.UDDIClient; +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.UDDIPublicationPortType; +import org.uddi.v3_service.UDDISecurityPortType; + +/** + * This will create two businesses under different users, then setup a + * relationship between the two + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiRelatedBusinesses { + + private static UDDISecurityPortType security = null; + private static JUDDIApiPortType juddiApi = null; + private static UDDIPublicationPortType publish = null; + + public UddiRelatedBusinesses() { + 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"); + Transport transport = clerkManager.getTransport(); + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + juddiApi = transport.getJUDDIApiService(); + publish = transport.getUDDIPublishService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void Fire(String businessKey, String authInfo, String businessKey1, String authInfo1, String relationship) throws Exception { + try { + + DatatypeFactory df = DatatypeFactory.newInstance(); + GregorianCalendar gcal = new GregorianCalendar(); + gcal.setTimeInMillis(System.currentTimeMillis()); + XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal); + + //ROOT creates half of the relationship + //create a business relationship (publisher assertion) + Holder<List<PublisherAssertion>> x = new Holder<List<PublisherAssertion>>(); + PublisherAssertion pa = new PublisherAssertion(); + pa.setFromKey(businessKey); + pa.setToKey(businessKey1); + pa.setKeyedReference(new KeyedReference()); + pa.getKeyedReference().setKeyName("Subsidiary"); + pa.getKeyedReference().setKeyValue(relationship); + + pa.getKeyedReference().setTModelKey("uddi:uddi.org:relationships"); + x.value = new ArrayList<PublisherAssertion>(); + x.value.add(pa); + publish.setPublisherAssertions(authInfo, x); + + //now "UDDI" the user, creates the other half. It has to be mirrored exactly + x = new Holder<List<PublisherAssertion>>(); + pa = new PublisherAssertion(); + pa.setFromKey(businessKey); + pa.setToKey(businessKey1); + pa.setKeyedReference(new KeyedReference()); + pa.getKeyedReference().setKeyName("Subsidiary"); + pa.getKeyedReference().setKeyValue(relationship); + + pa.getKeyedReference().setTModelKey("uddi:uddi.org:relationships"); + x.value = new ArrayList<PublisherAssertion>(); + x.value.add(pa); + publish.setPublisherAssertions(authInfo1, x); + + System.out.println("Success!"); + /* + * Here's some notes: + * You can use + * List<AssertionStatusItem> assertionStatusReport = publish.getAssertionStatusReport(UDDIAuthToken.getAuthInfo(), CompletionStatus.STATUS_FROM_KEY_INCOMPLETE); + * to determine if there's any assertions/relationships requests that are pending + * this should have one item it in, the relationship that's incomplete + * + * There's also publish.deletePublisherAssertions(); + */ + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) throws Exception { + UddiRelatedBusinesses sp = new UddiRelatedBusinesses(); + + 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 = " + "don't log auth tokens!"); + BusinessEntity rootbiz = sp.CreateBusiness("root"); + + getAuthTokenRoot = new GetAuthToken(); + getAuthTokenRoot.setUserID("uddi"); + getAuthTokenRoot.setCred("uddi"); + + // Making API call that retrieves the authentication token for the 'root' user. + AuthToken uddiAuthToken = security.getAuthToken(getAuthTokenRoot); + System.out.println("uddi AUTHTOKEN = " + "don't log auth tokens!"); + BusinessEntity uddibiz = sp.CreateBusiness("uddi"); + + //save user uddi's business + SaveBusiness sb = new SaveBusiness(); + sb.setAuthInfo(uddiAuthToken.getAuthInfo()); + sb.getBusinessEntity().add(uddibiz); + BusinessDetail uddibize = publish.saveBusiness(sb); + + sb = new SaveBusiness(); + sb.setAuthInfo(rootAuthToken.getAuthInfo()); + sb.getBusinessEntity().add(rootbiz); + BusinessDetail rootbize = publish.saveBusiness(sb); + + sp.Fire(rootbize.getBusinessEntity().get(0).getBusinessKey(), rootAuthToken.getAuthInfo(), + uddibize.getBusinessEntity().get(0).getBusinessKey(), uddiAuthToken.getAuthInfo(), + "parent-child"); + } + + private BusinessEntity CreateBusiness(String user) { + BusinessEntity be = new BusinessEntity(); + be.getName().add(new Name(user + "'s business", null)); + return be; + } + +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiReplication.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiReplication.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiReplication.java new file mode 100644 index 0000000..3e5175c --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiReplication.java @@ -0,0 +1,134 @@ +/* + * Copyright 2014 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.juddi.v3.client.cli; + +import java.math.BigInteger; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.xml.bind.JAXB; +import javax.xml.ws.BindingProvider; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.juddi.v3.client.UDDIService; +import org.apache.juddi.v3.client.config.UDDIClient; +import org.uddi.repl_v3.ChangeRecord; +import org.uddi.repl_v3.ChangeRecordIDType; +import org.uddi.repl_v3.ChangeRecords; +import org.uddi.repl_v3.DoPing; +import org.uddi.repl_v3.GetChangeRecords; +import org.uddi.repl_v3.HighWaterMarkVectorType; +import org.uddi.v3_service.UDDIReplicationPortType; + +/** + * + * @author Alex O'Ree + */ +class UddiReplication { + + public UddiReplication(UDDIClient client, String nodename) throws ConfigurationException { + + uddiReplicationPort = new UDDIService().getUDDIReplicationPort(); + ((BindingProvider) uddiReplicationPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, client.getClientConfig().getUDDINode(nodename).getReplicationUrl()); + } + + UDDIReplicationPortType uddiReplicationPort = null; + + String DoPing() { + try { + String doPing = uddiReplicationPort.doPing(new DoPing()); + System.out.println("Ping Success, remote node's id is " + doPing); + return doPing; + } catch (Exception ex) { + Logger.getLogger(UddiReplication.class.getName()).log(Level.SEVERE, null, ex); + } + return null; + } + + void GetHighWatermarks() { + try { + List<ChangeRecordIDType> highWaterMarks = uddiReplicationPort.getHighWaterMarks(); + System.out.println("Success...."); + System.out.println("Node, USN"); + for (int i = 0; i < highWaterMarks.size(); i++) { + System.out.println( + highWaterMarks.get(i).getNodeID() + ", " + + highWaterMarks.get(i).getOriginatingUSN()); + } + } catch (Exception ex) { + Logger.getLogger(UddiReplication.class.getName()).log(Level.SEVERE, null, ex); + } + } + + void GetChangeRecords(Long record, String sourcenode) { + try { + HighWaterMarkVectorType highWaterMarkVectorType = new HighWaterMarkVectorType(); + + highWaterMarkVectorType.getHighWaterMark().add(new ChangeRecordIDType(DoPing(), record)); + GetChangeRecords req = new GetChangeRecords(); + req.setRequestingNode(sourcenode); + req.setChangesAlreadySeen(highWaterMarkVectorType); + req.setResponseLimitCount(BigInteger.valueOf(100)); + ChangeRecords res = uddiReplicationPort.getChangeRecords(req); + List<ChangeRecord> changeRecords = res.getChangeRecord(); + System.out.println("Success...." + changeRecords.size() + " records returned"); + System.out.println("Node, USN, type"); + for (int i = 0; i < changeRecords.size(); i++) { + System.out.println( + changeRecords.get(i).getChangeID().getNodeID() + ", " + + changeRecords.get(i).getChangeID().getOriginatingUSN() + ": " + + GetChangeType(changeRecords.get(i))); + JAXB.marshal(changeRecords.get(i), System.out); + } + } catch (Exception ex) { + Logger.getLogger(UddiReplication.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private String GetChangeType(ChangeRecord get) { + if (get.getChangeRecordAcknowledgement() != null) { + return "ACK"; + } + if (get.getChangeRecordConditionFailed() != null) { + return "ConditionFailed"; + } + if (get.getChangeRecordCorrection() != null) { + return "Correction"; + } + if (get.getChangeRecordDelete() != null) { + return "Deletion"; + } + if (get.getChangeRecordDeleteAssertion() != null) { + return "Delete Assertion"; + } + if (get.getChangeRecordHide() != null) { + return "Hide tmodel"; + } + if (get.getChangeRecordNewData() != null) { + return "New Data"; + } + if (get.getChangeRecordNewDataConditional() != null) { + return "New data conditional"; + } + if (get.getChangeRecordNull() != null) { + return "Null"; + } + if (get.getChangeRecordPublisherAssertion() != null) { + return "New publisher assertion"; + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribe.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribe.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribe.java new file mode 100644 index 0000000..20d2907 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribe.java @@ -0,0 +1,244 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import javax.xml.datatype.DatatypeFactory; +import org.apache.juddi.jaxb.PrintUDDI; +import org.apache.juddi.v3.client.UDDIConstants; +import org.apache.juddi.v3.client.config.UDDIClerk; +import org.apache.juddi.v3.client.config.UDDIClient; +import org.apache.juddi.v3.client.subscription.ISubscriptionCallback; +import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener; +import org.apache.juddi.v3.client.transport.Transport; +import org.apache.juddi.v3_service.JUDDIApiPortType; +import org.uddi.api_v3.*; +import org.uddi.sub_v3.Subscription; +import org.uddi.sub_v3.SubscriptionFilter; +import org.uddi.sub_v3.SubscriptionResultsList; +import org.uddi.v3_service.UDDIInquiryPortType; +import org.uddi.v3_service.UDDIPublicationPortType; +import org.uddi.v3_service.UDDISecurityPortType; +import org.uddi.v3_service.UDDISubscriptionPortType; + +/** + * Thie class shows you how to create a business and a subscription using UDDI + * Subscription asynchronous callbacks + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiSubscribe implements ISubscriptionCallback, Runnable { + + private static UDDISecurityPortType security = null; + private static JUDDIApiPortType juddiApi = null; + private static UDDIPublicationPortType publish = null; + private static UDDIInquiryPortType uddiInquiryService = null; + private static UDDISubscriptionPortType uddiSubscriptionService = null; + boolean callbackRecieved = false; + private UDDIClerk clerk = null; + private UDDIClient client = null; + + public UddiSubscribe() { + try { + // create a manager and read the config in the archive; + // you can use your config file name + client = new UDDIClient("META-INF/simple-publish-uddi.xml"); + clerk = client.getClerk("default"); + Transport transport = client.getTransport(); + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + juddiApi = transport.getJUDDIApiService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + String nodename = "default"; + public UddiSubscribe(UDDIClient client, String nodename, Transport transport) { + try { + // create a manager and read the config in the archive; + // you can use your config file name + //client = new UDDIClient("META-INF/simple-publish-uddi.xml"); + clerk = client.getClerk(nodename); + this.nodename = nodename; + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + juddiApi = transport.getJUDDIApiService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) throws Exception { + UddiSubscribe sp = new UddiSubscribe(); + sp.Fire(); + } + + public void Fire() throws Exception { + + TModel createKeyGenator = UDDIClerk.createKeyGenator("somebusiness", "A test key domain SubscriptionCallbackTest1", "SubscriptionCallbackTest1"); + + clerk.register(createKeyGenator); + System.out.println("Registered tModel keygen: " + createKeyGenator.getTModelKey()); + + //setup the business to attach to + BusinessEntity be = new BusinessEntity(); + be.setBusinessKey("uddi:somebusiness:somebusinesskey"); + be.getName().add(new Name("somebusiness SubscriptionCallbackTest1", null)); + be.setBusinessServices(new BusinessServices()); + BusinessService bs = new BusinessService(); + bs.setBusinessKey("uddi:somebusiness:somebusinesskey"); + bs.setServiceKey("uddi:somebusiness:someservicekey"); + bs.getName().add(new Name("service SubscriptionCallbackTest1", null)); + be.getBusinessServices().getBusinessService().add(bs); + BusinessEntity register = clerk.register(be); + System.out.println("Registered business keygen: " + register.getBusinessKey()); + + //start up our listener + BindingTemplate start = SubscriptionCallbackListener.start(client, nodename); + + //register for callbacks + SubscriptionCallbackListener.registerCallback(this); + + Subscription sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setFindBusiness(new FindBusiness()); + sub.getSubscriptionFilter().getFindBusiness().setFindQualifiers(new FindQualifiers()); + sub.getSubscriptionFilter().getFindBusiness().getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH); + sub.getSubscriptionFilter().getFindBusiness().getName().add(new Name(UDDIConstants.WILDCARD, null)); + + Subscription subscriptionBiz = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered FindBusiness subscription key: " + (subscriptionBiz.getSubscriptionKey()) + " bindingkey: " + subscriptionBiz.getBindingKey()); + + sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setFindService(new FindService()); + sub.getSubscriptionFilter().getFindService().setFindQualifiers(new FindQualifiers()); + sub.getSubscriptionFilter().getFindService().getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH); + sub.getSubscriptionFilter().getFindService().getName().add(new Name(UDDIConstants.WILDCARD, null)); + + Subscription subscriptionSvc = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered FindService subscription key: " + (subscriptionSvc.getSubscriptionKey()) + " bindingkey: " + subscriptionSvc.getBindingKey()); + + sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setFindTModel(new FindTModel()); + sub.getSubscriptionFilter().getFindTModel().setFindQualifiers(new FindQualifiers()); + sub.getSubscriptionFilter().getFindTModel().getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH); + sub.getSubscriptionFilter().getFindTModel().setName(new Name(UDDIConstants.WILDCARD, null)); + + Subscription subscriptionTM = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered FindTModel subscription key: " + (subscriptionTM.getSubscriptionKey()) + " bindingkey: " + subscriptionTM.getBindingKey()); + + sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport()); + sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_COMPLETE); + + Subscription subscriptionPA = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered Completed PublisherAssertion subscription key: " + (subscriptionPA.getSubscriptionKey()) + " bindingkey: " + subscriptionTM.getBindingKey()); + + sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport()); + sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_FROM_KEY_INCOMPLETE); + + Subscription subscriptionPA2 = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered FROM incomplete PublisherAssertion subscription key: " + (subscriptionPA2.getSubscriptionKey()) + " bindingkey: " + subscriptionTM.getBindingKey()); + + sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport()); + sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_TO_KEY_INCOMPLETE); + + Subscription subscriptionPA3 = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered TO incomplete PublisherAssertion subscription key: " + (subscriptionPA3.getSubscriptionKey()) + " bindingkey: " + subscriptionTM.getBindingKey()); + + sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport()); + sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_BOTH_INCOMPLETE); + + Subscription subscriptionPA4 = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered recently deleted PublisherAssertion subscription key: " + (subscriptionPA4.getSubscriptionKey()) + " bindingkey: " + subscriptionTM.getBindingKey()); + + System.out.println("Waiting for callbacks. Now would be a good time to launch either another program or juddi-gui to make some changes. Press any key to stop!"); + //Thread hook = new Thread(this); + // Runtime.getRuntime().addShutdownHook(hook); + + System.in.read(); + + SubscriptionCallbackListener.stop(client, nodename, start.getBindingKey()); + clerk.unRegisterSubscription(subscriptionBiz.getSubscriptionKey()); + clerk.unRegisterSubscription(subscriptionSvc.getSubscriptionKey()); + clerk.unRegisterSubscription(subscriptionTM.getSubscriptionKey()); + clerk.unRegisterSubscription(subscriptionPA.getSubscriptionKey()); + clerk.unRegisterSubscription(subscriptionPA2.getSubscriptionKey()); + clerk.unRegisterSubscription(subscriptionPA3.getSubscriptionKey()); + clerk.unRegisterSubscription(subscriptionPA4.getSubscriptionKey()); + + clerk.unRegisterTModel(createKeyGenator.getTModelKey()); + + clerk.unRegisterBusiness("uddi:somebusiness:somebusinesskey"); + + //Runtime.getRuntime().removeShutdownHook(hook); + } + + private boolean running = true; + PrintUDDI<SubscriptionResultsList> p = new PrintUDDI<SubscriptionResultsList>(); + + @Override + public void HandleCallback(SubscriptionResultsList body) { + System.out.println("Callback received!"); + System.out.println(p.print(body)); + } + + @Override + public void NotifyEndpointStopped() { + System.out.println("The endpoint was stopped!"); + } + + @Override + public void run() { + running = false; + } +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeAssertionStatus.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeAssertionStatus.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeAssertionStatus.java new file mode 100644 index 0000000..7440876 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeAssertionStatus.java @@ -0,0 +1,163 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import javax.xml.datatype.DatatypeFactory; +import org.apache.juddi.jaxb.PrintUDDI; +import org.apache.juddi.v3.client.UDDIConstants; +import org.apache.juddi.v3.client.config.UDDIClerk; +import org.apache.juddi.v3.client.config.UDDIClient; +import org.apache.juddi.v3.client.subscription.ISubscriptionCallback; +import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener; +import org.apache.juddi.v3.client.transport.Transport; +import org.apache.juddi.v3_service.JUDDIApiPortType; +import org.uddi.api_v3.*; +import org.uddi.sub_v3.Subscription; +import org.uddi.sub_v3.SubscriptionFilter; +import org.uddi.sub_v3.SubscriptionResultsList; +import org.uddi.v3_service.UDDIInquiryPortType; +import org.uddi.v3_service.UDDIPublicationPortType; +import org.uddi.v3_service.UDDISecurityPortType; +import org.uddi.v3_service.UDDISubscriptionPortType; + +/** + * Thie class shows you how to create a business and a subscription using UDDI + * Subscription asynchronous callbacks for Assertion Status Reports + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiSubscribeAssertionStatus implements ISubscriptionCallback, Runnable { + + private static UDDISecurityPortType security = null; + private static JUDDIApiPortType juddiApi = null; + private static UDDIPublicationPortType publish = null; + private static UDDIInquiryPortType uddiInquiryService = null; + private static UDDISubscriptionPortType uddiSubscriptionService = null; + boolean callbackRecieved = false; + private UDDIClerk clerk = null; + private UDDIClient client = null; + + public UddiSubscribeAssertionStatus() { + try { + // create a manager and read the config in the archive; + // you can use your config file name + client = new UDDIClient("META-INF/simple-publish-uddi.xml"); + clerk = client.getClerk("default"); + Transport transport = client.getTransport(); + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + juddiApi = transport.getJUDDIApiService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public UddiSubscribeAssertionStatus(Transport transport) { + try { + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + juddiApi = transport.getJUDDIApiService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public static void main(String args[]) throws Exception { + UddiSubscribeAssertionStatus sp = new UddiSubscribeAssertionStatus(); + sp.Fire("default"); + } + + public void Fire(String nodename) throws Exception { + + TModel createKeyGenator = UDDIClerk.createKeyGenator("somebusiness", "A test key domain SubscriptionCallbackTest1", "SubscriptionCallbackTest1"); + + clerk.register(createKeyGenator); + System.out.println("Registered tModel keygen: " + createKeyGenator.getTModelKey()); + + //setup the business to attach to + BusinessEntity be = new BusinessEntity(); + be.setBusinessKey("uddi:somebusiness:somebusinesskey"); + be.getName().add(new Name("somebusiness SubscriptionCallbackTest1", null)); + be.setBusinessServices(new BusinessServices()); + BusinessService bs = new BusinessService(); + bs.setBusinessKey("uddi:somebusiness:somebusinesskey"); + bs.setServiceKey("uddi:somebusiness:someservicekey"); + bs.getName().add(new Name("service SubscriptionCallbackTest1", null)); + be.getBusinessServices().getBusinessService().add(bs); + BusinessEntity register = clerk.register(be); + System.out.println("Registered business keygen: " + register.getBusinessKey()); + + //start up our listener + BindingTemplate start = SubscriptionCallbackListener.start(client, nodename); + + //register for callbacks + SubscriptionCallbackListener.registerCallback(this); + + Subscription sub = new Subscription(); + sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000)); + sub.setBindingKey(start.getBindingKey()); + sub.setSubscriptionFilter(new SubscriptionFilter()); + sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport()); + //it's optional + + //sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_COMPLETE); + Subscription subscriptionBiz = clerk.register(sub, clerk.getUDDINode().getApiNode()); + + System.out.println("Registered GetAssertionStatus subscription key: " + (subscriptionBiz.getSubscriptionKey()) + " bindingkey: " + subscriptionBiz.getBindingKey()); + + System.out.println("Waiting for callbacks. Now would be a good time to launch either another program or juddi-gui to make some changes. Press any key to stop!"); + //Thread hook = new Thread(this); + // Runtime.getRuntime().addShutdownHook(hook); + + System.in.read(); + + SubscriptionCallbackListener.stop(client, nodename, start.getBindingKey()); + clerk.unRegisterSubscription(subscriptionBiz.getSubscriptionKey()); + + clerk.unRegisterTModel(createKeyGenator.getTModelKey()); + + clerk.unRegisterBusiness("uddi:somebusiness:somebusinesskey"); + + //Runtime.getRuntime().removeShutdownHook(hook); + } + + private boolean running = true; + PrintUDDI<SubscriptionResultsList> p = new PrintUDDI<SubscriptionResultsList>(); + + @Override + public void HandleCallback(SubscriptionResultsList body) { + System.out.println("Callback received!"); + System.out.println(p.print(body)); + } + + @Override + public void NotifyEndpointStopped() { + System.out.println("The endpoint was stopped!"); + } + + @Override + public void run() { + running = false; + } +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeValidate.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeValidate.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeValidate.java new file mode 100644 index 0000000..5afb0e5 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscribeValidate.java @@ -0,0 +1,137 @@ +/* + * Copyright 2001-2013 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.juddi.v3.client.cli; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import org.apache.juddi.v3.client.config.UDDIClient; +import org.apache.juddi.v3.client.transport.Transport; +import org.apache.juddi.v3_service.JUDDIApiPortType; +import org.uddi.api_v3.*; +import org.uddi.sub_v3.CoveragePeriod; +import org.uddi.sub_v3.GetSubscriptionResults; +import org.uddi.sub_v3.SubscriptionResultsList; +import org.uddi.v3_service.UDDIInquiryPortType; +import org.uddi.v3_service.UDDIPublicationPortType; +import org.uddi.v3_service.UDDISecurityPortType; +import org.uddi.v3_service.UDDISubscriptionListenerPortType; +import org.uddi.v3_service.UDDISubscriptionPortType; + +/** + * This class shows you how to get the results of an existing subscription in + * UDDI. + * + * @author <a href="mailto:[email protected]">Alex O'Ree</a> + */ +public class UddiSubscribeValidate { + + private static UDDISecurityPortType security = null; + private static JUDDIApiPortType juddiApi = null; + private static UDDIPublicationPortType publish = null; + private static UDDIInquiryPortType uddiInquiryService = null; + private static UDDISubscriptionPortType uddiSubscriptionService = null; + private static UDDISubscriptionListenerPortType uddiSubscriptionListenerService = null; + + public UddiSubscribeValidate() { + 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"); + Transport transport = clerkManager.getTransport(); + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + juddiApi = transport.getJUDDIApiService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + uddiSubscriptionListenerService = transport.getUDDISubscriptionListenerService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public UddiSubscribeValidate(Transport transport) { + try { + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + juddiApi = transport.getJUDDIApiService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + uddiSubscriptionListenerService = transport.getUDDISubscriptionListenerService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * gets subscription results synchronously + * + * @param authtoken + * @param key + */ + public void go(String authtoken, String key) { + if (key == null) { + System.out.println("No key was specified!"); + return; + } + try { + + // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges + // and can save other publishers). + if (authtoken == null) { + 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 = " + "don't log 'em"); + authtoken = rootAuthToken.getAuthInfo(); + } + DatatypeFactory df = DatatypeFactory.newInstance(); + GregorianCalendar gcal = new GregorianCalendar(); + gcal.setTimeInMillis(System.currentTimeMillis()); + XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal); + + // + GetSubscriptionResults req = new GetSubscriptionResults(); + req.setAuthInfo(authtoken); + //TODO insert your subscription key values here + req.setSubscriptionKey(key); + req.setCoveragePeriod(new CoveragePeriod()); + req.getCoveragePeriod().setEndPoint(xcal); + + gcal = new GregorianCalendar(); + //Time range that we want change logs on + gcal.add(Calendar.MONTH, -1); + req.getCoveragePeriod().setStartPoint(df.newXMLGregorianCalendar(gcal)); + SubscriptionResultsList subscriptionResults = uddiSubscriptionService.getSubscriptionResults(req); + System.out.println("items modified: " + subscriptionResults.getBusinessDetail().getBusinessEntity().size()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) { + UddiSubscribeValidate sp = new UddiSubscribeValidate(); + sp.go(null, null); + } +} http://git-wip-us.apache.org/repos/asf/juddi/blob/9dafe4e8/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscriptionManagement.java ---------------------------------------------------------------------- diff --git a/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscriptionManagement.java b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscriptionManagement.java new file mode 100644 index 0000000..6068c14 --- /dev/null +++ b/juddi-client-cli/src/main/java/org/apache/juddi/v3/client/cli/UddiSubscriptionManagement.java @@ -0,0 +1,149 @@ +/* + * Copyright 2014 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.juddi.v3.client.cli; + +import java.util.List; +import javax.xml.datatype.DatatypeFactory; +import org.apache.juddi.jaxb.PrintUDDI; +import org.apache.juddi.v3.client.UDDIConstants; +import org.apache.juddi.v3.client.config.UDDIClerk; +import org.apache.juddi.v3.client.config.UDDIClient; +import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener; +import org.apache.juddi.v3.client.transport.Transport; +import org.apache.juddi.v3_service.JUDDIApiPortType; +import org.uddi.api_v3.BindingTemplate; +import org.uddi.api_v3.BusinessEntity; +import org.uddi.api_v3.BusinessService; +import org.uddi.api_v3.BusinessServices; +import org.uddi.api_v3.FindBusiness; +import org.uddi.api_v3.FindQualifiers; +import org.uddi.api_v3.FindService; +import org.uddi.api_v3.FindTModel; +import org.uddi.api_v3.Name; +import org.uddi.api_v3.TModel; +import org.uddi.sub_v3.DeleteSubscription; +import org.uddi.sub_v3.Subscription; +import org.uddi.sub_v3.SubscriptionFilter; +import org.uddi.sub_v3.SubscriptionResultsList; +import org.uddi.v3_service.UDDIInquiryPortType; +import org.uddi.v3_service.UDDIPublicationPortType; +import org.uddi.v3_service.UDDISecurityPortType; +import org.uddi.v3_service.UDDISubscriptionPortType; + +/** + * + * @author Alex O'Ree + */ +public class UddiSubscriptionManagement { + + private static UDDISecurityPortType security = null; + + private static UDDIPublicationPortType publish = null; + private static UDDIInquiryPortType uddiInquiryService = null; + private static UDDISubscriptionPortType uddiSubscriptionService = null; + + private UDDIClerk clerk = null; + private UDDIClient client = null; + + public UddiSubscriptionManagement() { + try { + // create a manager and read the config in the archive; + // you can use your config file name + client = new UDDIClient("META-INF/simple-publish-uddi.xml"); + clerk = client.getClerk("default"); + Transport transport = client.getTransport(); + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public UddiSubscriptionManagement(Transport transport) { + try { + + // Now you create a reference to the UDDI API + security = transport.getUDDISecurityService(); + publish = transport.getUDDIPublishService(); + uddiInquiryService = transport.getUDDIInquiryService(); + uddiSubscriptionService = transport.getUDDISubscriptionService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) throws Exception { + UddiSubscriptionManagement sp = new UddiSubscriptionManagement(); + sp.PrintSubscriptions(null); + } + + public void PrintSubscriptions(String authtoken) throws Exception { + + if (authtoken == null) { + authtoken = clerk.getAuthToken(); + } + List<Subscription> subscriptions = uddiSubscriptionService.getSubscriptions(authtoken); + System.out.println(subscriptions.size() + " subscriptions found"); + for (int i = 0; i < subscriptions.size(); i++) { + System.out.println("_____________________________________"); + + System.out.println(p.print(subscriptions.get(i))); + } + } + + public void DeleteSubscription(String authtoken, String key) throws Exception { + + if (authtoken == null) { + authtoken = clerk.getAuthToken(); + } + if (key == null) { + System.out.println("No key specified!"); + return; + } + DeleteSubscription ds = new DeleteSubscription(); + ds.setAuthInfo(authtoken); + ds.getSubscriptionKey().add(key); + uddiSubscriptionService.deleteSubscription(ds); + System.out.println("Deleted!"); + + } + + public void DeleteAllSubscriptions(String authtoken) throws Exception { + + if (authtoken == null) { + authtoken = clerk.getAuthToken(); + } + List<Subscription> subscriptions = uddiSubscriptionService.getSubscriptions(authtoken); + System.out.println(subscriptions.size() + " subscriptions found"); + for (int i = 0; i < subscriptions.size(); i++) { + System.out.println("_____________________________________"); + System.out.println(subscriptions.get(i).getSubscriptionKey()); + DeleteSubscription ds = new DeleteSubscription(); + ds.setAuthInfo(authtoken); + ds.getSubscriptionKey().add(subscriptions.get(i).getSubscriptionKey()); + uddiSubscriptionService.deleteSubscription(ds); + System.out.println("Deleted!"); + } + + } + + private boolean running = true; + PrintUDDI<Subscription> p = new PrintUDDI<Subscription>(); + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
