Author: kstam
Date: Tue Mar  5 01:21:38 2013
New Revision: 1452616

URL: http://svn.apache.org/r1452616
Log:
JUDDI-555 adding additional examples

applying patch by Alex O'Ree

Added:
    juddi/trunk/juddi-examples/create-partition/
    juddi/trunk/juddi-examples/create-partition/README.txt
    juddi/trunk/juddi-examples/create-partition/pom.xml
    juddi/trunk/juddi-examples/create-partition/src/
    juddi/trunk/juddi-examples/create-partition/src/main/
    juddi/trunk/juddi-examples/create-partition/src/main/java/
    juddi/trunk/juddi-examples/create-partition/src/main/java/org/
    juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/
    juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/
    
juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/example/
    
juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/example/partition/
    
juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/example/partition/SimpleCreateTmodelPartition.java
    juddi/trunk/juddi-examples/create-partition/src/main/resources/
    juddi/trunk/juddi-examples/create-partition/src/main/resources/META-INF/
    
juddi/trunk/juddi-examples/create-partition/src/main/resources/META-INF/uddi.xml

Added: juddi/trunk/juddi-examples/create-partition/README.txt
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-examples/create-partition/README.txt?rev=1452616&view=auto
==============================================================================
--- juddi/trunk/juddi-examples/create-partition/README.txt (added)
+++ juddi/trunk/juddi-examples/create-partition/README.txt Tue Mar  5 01:21:38 
2013
@@ -0,0 +1,18 @@
+This example contains one class: the SimplePublish.java. When
+executed it will obtain an AuthToken and use it to publish
+a Publisher, a Business and a Service. 
+
+The easiest way to run execute the main of this class in from
+your IDE. If your IDE has maven integration it should set up
+the project class path for you, and you can simple run it from 
+there.
+
+You should see the following output being written to the console:
+
+root AUTHTOKEN = authtoken:0494e382-1ad3-4c52-8806-ae70a0ed37ad
+myPub AUTHTOKEN = authtoken:bf973e5f-7361-4c57-92f7-7b499b886b6d
+myBusiness key:  uddi:juddi.apache.org:6f3e4e62-e483-48ff-a1b3-6855310505c6
+myService key:  uddi:juddi.apache.org:549a9580-cd7b-4969-9b77-527ab9f8f261
+
+However since the keys are being generated in this case your keys will differ.
+

Added: juddi/trunk/juddi-examples/create-partition/pom.xml
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-examples/create-partition/pom.xml?rev=1452616&view=auto
==============================================================================
--- juddi/trunk/juddi-examples/create-partition/pom.xml (added)
+++ juddi/trunk/juddi-examples/create-partition/pom.xml Tue Mar  5 01:21:38 2013
@@ -0,0 +1,72 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.apache.juddi.example</groupId>
+               <artifactId>juddi-examples</artifactId>
+               <version>3.1.5-SNAPSHOT</version>
+               <relativePath>../pom.xml</relativePath>
+       </parent>
+       <artifactId>create-partition</artifactId>
+       <name>jUDDI Example Create Partition</name>
+       <description>Demonstrates the steps taken create a UDDI 
partition</description>
+
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.apache.juddi</groupId>
+                       <artifactId>uddi-ws</artifactId>
+                       <version>3.1.5-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.juddi</groupId>
+                       <artifactId>juddi-client</artifactId>
+                       <version>3.1.5-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
+
+       <profiles>
+               <profile>
+                       <id>default</id>
+                       <activation>
+                               <activeByDefault>true</activeByDefault>
+                       </activation>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               
<groupId>org.apache.maven.plugins</groupId>
+                                               
<artifactId>maven-surefire-plugin</artifactId>
+                                               <configuration>
+                                                       <skip>true</skip>
+                                               </configuration>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
+               <profile>
+                       <id>demo</id>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               
<groupId>org.codehaus.mojo</groupId>
+                                               
<artifactId>exec-maven-plugin</artifactId>
+                                               <version>1.1.1</version>
+                                               <executions>
+                                                       <execution>
+                                                               
<phase>test</phase>
+                                                               <goals>
+                                                                       
<goal>java</goal>
+                                                               </goals>
+                                                               <configuration>
+                                                                       
<mainClass>org.apache.juddi.example.partition.SimpleCreateTmodelPartition</mainClass>
+                                                               </configuration>
+                                                       </execution>
+                                               </executions>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
+       </profiles>
+
+</project>
+

Added: 
juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/example/partition/SimpleCreateTmodelPartition.java
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/example/partition/SimpleCreateTmodelPartition.java?rev=1452616&view=auto
==============================================================================
--- 
juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/example/partition/SimpleCreateTmodelPartition.java
 (added)
+++ 
juddi/trunk/juddi-examples/create-partition/src/main/java/org/apache/juddi/example/partition/SimpleCreateTmodelPartition.java
 Tue Mar  5 01:21:38 2013
@@ -0,0 +1,229 @@
+/*
+ * Copyright 2001-2010 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.example.browse;
+
+import java.util.Properties;
+import org.apache.juddi.ClassUtil;
+import org.apache.juddi.v3.client.config.UDDIClientContainer;
+import org.apache.juddi.v3.client.transport.Transport;
+import org.uddi.api_v3.AuthToken;
+import org.uddi.api_v3.BindingTemplates;
+import org.uddi.api_v3.CategoryBag;
+import org.uddi.api_v3.GetAuthToken;
+import org.uddi.api_v3.KeyedReference;
+import org.uddi.api_v3.Name;
+import org.uddi.api_v3.SaveTModel;
+import org.uddi.api_v3.TModel;
+import org.uddi.api_v3.TModelDetail;
+import org.uddi.v3_service.UDDIInquiryPortType;
+import org.uddi.v3_service.UDDIPublicationPortType;
+import org.uddi.v3_service.UDDISecurityPortType;
+
+/**
+ * An example for creating a key partition, aka key generator, aka 'special'
+ * tModel
+ *
+ * @author Alex O'Ree
+ */
+public class SimpleCreateTmodelPartition {
+
+    private static UDDISecurityPortType security = null;
+    private static UDDIInquiryPortType inquiry = null;
+    private static UDDIPublicationPortType publish = null;
+
+    /**
+     * This sets up the ws proxies using uddi.xml in META-INF
+     */
+    public SimpleCreateTmodelPartition() {
+        try {
+            String clazz = UDDIClientContainer.getUDDIClerkManager(null).
+                    
getClientConfig().getUDDINode("default").getProxyTransport();
+            Class<?> transportClass = ClassUtil.forName(clazz, 
Transport.class);
+            if (transportClass != null) {
+                Transport transport = (Transport) transportClass.
+                        getConstructor(String.class).newInstance("default");
+
+                security = transport.getUDDISecurityService();
+                inquiry = transport.getUDDIInquiryService();
+                publish = transport.getUDDIPublishService();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static void DisplayHelp() {
+        //TODO
+    }
+
+    /**
+     * Main entry point
+     *
+     * @param args
+     */
+    public static void main(String args[]) {
+        if (args.length == 1 && args[0].equalsIgnoreCase("help")) {
+            DisplayHelp();
+            return;
+        }
+        SimpleCreateTmodelPartition sp = new SimpleCreateTmodelPartition();
+        sp.Go(args);
+    }
+
+    public void Go(String[] args) {
+        try {
+            Properties prop = ParseArgs(args);
+            if (prop.containsKey("AuthStyle")) {
+                //TODO, determine a way to pass parameters from the command 
line, hardcoded for now
+                //UDDI Token
+                //HTTP Username/Password (basic or digest)
+                //HTTP Client Cert
+            }
+
+                       
+                       //Note: when creating a tModel Key Generator, aka 
Partition, you MUST follow the below pattern
+                       //for jUDDI, the following is required
+                       //      Name
+                       //      CategoryBag/KR for the below fixed values
+                       //      a tModelKey that starts with 
uddi:<something>:keygenerator - recommended all lower case
+
+            String key = GetAuthKey("uddi", "uddi", AuthStyle.UDDI_AUTH);
+            SaveTModel st = new SaveTModel();
+            st.setAuthInfo(key);
+            TModel tm = new TModel();
+            tm.setName(new Name());
+            tm.getName().setValue("My Company's Keymodel generator");
+            tm.getName().setLang("en");
+            tm.setCategoryBag(new CategoryBag());
+            KeyedReference kr = new KeyedReference();
+            kr.setTModelKey("uddi:uddi.org:categorization:types");
+            kr.setKeyName("uddi-org:keyGenerator");
+            kr.setKeyValue("keyGenerator");
+            tm.getCategoryBag().getKeyedReference().add(kr);
+            tm.setTModelKey("uddi:www.mycoolcompany.com:keygenerator");
+            st.getTModel().add(tm);
+            TModelDetail saveTModel = publish.saveTModel(st);
+            System.out.println("Creation of Partition Success!");
+
+            tm = new TModel();
+            tm.setName(new Name());
+            tm.getName().setValue("My Company's Department");
+            tm.getName().setLang("en");
+            tm.setTModelKey("uddi:www.mycoolcompany.com:department");
+            st.getTModel().add(tm);
+            saveTModel = publish.saveTModel(st);
+            System.out.println("Creation of tModel Department Success!");
+            
+             tm = new TModel();
+            tm.setName(new Name());
+            tm.getName().setValue("My Company's Authentication Method");
+            tm.getName().setLang("en");
+            tm.setTModelKey("uddi:www.mycoolcompany.com:authmode");
+            st.getTModel().add(tm);
+            saveTModel = publish.saveTModel(st);
+            System.out.println("Creation of tModel Auth Mode Success!");
+
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * This function is useful for translating UDDI's somewhat complex data
+     * format to something that is more useful.
+     *
+     * @param bindingTemplates
+     */
+    private void PrintBindingTemplates(BindingTemplates bindingTemplates) {
+        if (bindingTemplates == null) {
+            return;
+        }
+        for (int i = 0; i < bindingTemplates.getBindingTemplate().size(); i++) 
{
+            System.out.println("Binding Key: " + 
bindingTemplates.getBindingTemplate().get(i).getBindingKey());
+            //TODO The UDDI spec is kind of strange at this point.
+            //An access point could be a URL, a reference to another UDDI 
binding key, a hosting redirector (which is 
+            //esscentially a pointer to another UDDI registry) or a WSDL 
Deployment
+            //From an end client's perspective, all you really want is the 
endpoint.
+
+            //So if you have a wsdlDeployment useType, fetch the wsdl and 
parse for the invocation URL
+            //If its hosting director, you'll have to fetch that data from 
uddi recursively until the leaf node is found
+            //Consult the UDDI specification for more information
+
+            if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint() 
!= null) {
+                System.out.println("Access Point: " + 
bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getValue() + " 
type " + 
bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType());
+            }
+
+        }
+    }
+
+    private enum AuthStyle {
+
+        HTTP_BASIC,
+        HTTP_DIGEST,
+        HTTP_NTLM,
+        UDDI_AUTH,
+        HTTP_CLIENT_CERT
+    }
+
+    /**
+     * 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, AuthStyle 
style) {
+        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 = " + 
rootAuthToken.getAuthInfo());
+            return rootAuthToken.getAuthInfo();
+        } catch (Exception ex) {
+            System.out.println("Could not authenticate with the provided 
credentials " + ex.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Converts command line args into a simple property structure
+     *
+     * @param args
+     * @return
+     */
+    private Properties ParseArgs(String[] args) {
+
+        Properties p = new Properties();
+        if (args == null) {
+            return p;
+        }
+        for (int i = 0; i < args.length; i++) {
+            if (args[i] != null && args[i].length() >= 3) {
+                p.put(args[i].split("=")[0], args[i].split("=")[1]);
+            }
+        }
+        return p;
+    }
+}

Added: 
juddi/trunk/juddi-examples/create-partition/src/main/resources/META-INF/uddi.xml
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-examples/create-partition/src/main/resources/META-INF/uddi.xml?rev=1452616&view=auto
==============================================================================
--- 
juddi/trunk/juddi-examples/create-partition/src/main/resources/META-INF/uddi.xml
 (added)
+++ 
juddi/trunk/juddi-examples/create-partition/src/main/resources/META-INF/uddi.xml
 Tue Mar  5 01:21:38 2013
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<uddi>
+    <reloadDelay>5000</reloadDelay>
+    <manager name="example-manager">
+               <nodes>
+                       <node>
+                           <!-- required 'default' node -->
+                               <name>default</name> 
+                <properties>
+                    <property name="serverName" value="localhost"/>
+                    <property name="serverPort" value="8080"/>
+                </properties>
+                               <description>Main jUDDI node</description>
+                               <!-- JAX-WS Transport -->
+                               
<proxyTransport>org.apache.juddi.v3.client.transport.JAXWSTransport</proxyTransport>
+                               
<custodyTransferUrl>http://${serverName}:${serverPort}/juddiv3/services/custody-transfer</custodyTransferUrl>
+                               
<inquiryUrl>http://${serverName}:${serverPort}/juddiv3/services/inquiry</inquiryUrl>
+                       
<publishUrl>http://${serverName}:${serverPort}/juddiv3/services/publish</publishUrl>
+                       
<securityUrl>http://${serverName}:${serverPort}/juddiv3/services/security</securityUrl>
+                               
<subscriptionUrl>http://${serverName}:${serverPort}/juddiv3/services/subscription</subscriptionUrl>
+                               
<subscriptionListenerUrl>http://${serverName}:${serverPort}/juddiv3/services/subscription-listener</subscriptionListenerUrl>
+                               
<juddiApiUrl>http://${serverName}:${serverPort}/juddiv3/services/juddi-api</juddiApiUrl>
+                       </node>
+               </nodes>
+       </manager>
+</uddi>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to