Author: thilina
Date: Sun Sep 11 06:39:49 2005
New Revision: 280132

URL: http://svn.apache.org/viewcvs?rev=280132&view=rev
Log:
Moving MD5 string generation and EndpointReference seriazation to a utils class

Added:
    
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaUtils.java
Modified:
    
webservices/kandula/trunk/java/src/org/apache/kandula/utility/EndpointReferenceFactory.java
    
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaListener.java

Modified: 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/EndpointReferenceFactory.java
URL: 
http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/utility/EndpointReferenceFactory.java?rev=280132&r1=280131&r2=280132&view=diff
==============================================================================
--- 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/EndpointReferenceFactory.java
 (original)
+++ 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/EndpointReferenceFactory.java
 Sun Sep 11 06:39:49 2005
@@ -1,86 +1,129 @@
 /*

- * Copyright  2004 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.

- *

+ * Copyright 2004 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.kandula.utility;

 

-import org.apache.kandula.typemapping.EndPointReference;

-import org.xmlsoap.schemas.ws.x2002.x07.utility.impl.PortReferenceTypeImpl;

-import org.xmlsoap.schemas.ws.x2004.x03.addressing.ReferencePropertiesType;

-import 
org.xmlsoap.schemas.ws.x2004.x03.addressing.impl.EndpointReferenceTypeImpl;

-

 import java.io.InputStream;

 import java.net.InetAddress;

 import java.util.Properties;

 

+import javax.xml.namespace.QName;

+

+import org.apache.axis2.addressing.AnyContentType;

+import org.apache.axis2.addressing.EndpointReference;

+

 public class EndpointReferenceFactory {

-       static final String PROPERTY_FILE= "endpoints.conf";

-       static final String PROTOCOL_PROPERTY= "protocol";

-       static final String HOST_PROPERTY= "host";

-       static final String PORT_PROPERTY= "port";

-       static EndpointReferenceFactory instance= null;

-       Properties properties= null;

-       String location= null;

-

-       private EndpointReferenceFactory() {

-               InputStream in= 
getClass().getClassLoader().getResourceAsStream(PROPERTY_FILE);

-               properties= new Properties();

-               try {

-                       properties.load(in);

-                       in.close();

-                       String host= properties.getProperty(HOST_PROPERTY);

-                       if (host == null)

-                               host= 
InetAddress.getLocalHost().getHostAddress();

-                       location=

-                               properties.getProperty(PROTOCOL_PROPERTY)

-                                       + "://"

-                                       + host

-                                       + ":"

-                                       + properties.getProperty(PORT_PROPERTY);

-               }

-               catch (Exception e) {

-                       if (e instanceof RuntimeException)

-                               throw (RuntimeException)e;

-                       else

-                               throw new RuntimeException(e);

-               }

-       }

-

-       public static EndpointReferenceFactory getInstance() {

-               if (instance == null)

-                       instance= new EndpointReferenceFactory();

-               return instance;

-       }

- 

-       public EndPointReference getRegistrationEndpoint()

-       {

-           //TODO set this somehow reading the conf file

-           return EndPointReference.Factory.newInstance();

-       }

-//     public EndpointReferenceTypeImpl 
getEndpointReference(PortReferenceTypeImpl portType, ReferencePropertiesType 
referenceProperties) {

-//             try {

-//                     EndpointReferenceTypeImpl endpointReference = new 
EndpointReferenceTypeImpl(SchemaTypeImpl.);

-//                     endpointReference.setPortTypesetPortType(portType);

-//                     endpointReference.setProperties(referenceProperties);

-//                     return endpointReference;

-//             }

-//             catch (Exception e) {

-//                     if (e instanceof RuntimeException)

-//                             throw (RuntimeException)e;

-//                     else

-//                             throw new RuntimeException(e);

-//             }

-//     }

-}

+    static final String PROPERTY_FILE = "endpoints.conf";

+

+    static final String PROTOCOL_PROPERTY = "protocol";

+

+    static final String HOST_PROPERTY = "host";

+

+    static final String PORT_PROPERTY = "port";

+

+    private static EndpointReferenceFactory instance = null;

+

+    Properties properties = null;

+

+    String location = null;

+

+    private EndpointReferenceFactory() {

+//        InputStream in = getClass().getClassLoader().getResourceAsStream(

+//                PROPERTY_FILE);

+//        properties = new Properties();

+//        try {

+//            properties.load(in);

+//            in.close();

+//            String host = properties.getProperty(HOST_PROPERTY);

+//            if (host == null)

+//                host = InetAddress.getLocalHost().getHostAddress();

+//            location = properties.getProperty(PROTOCOL_PROPERTY) + "://" + 
host

+//                    + ":" + properties.getProperty(PORT_PROPERTY);

+//        } catch (Exception e) {

+//            if (e instanceof RuntimeException)

+//                throw (RuntimeException) e;

+//            else

+//                throw new RuntimeException(e);

+//        }

+    }

+

+    public static EndpointReferenceFactory getInstance() {

+        if (instance == null)

+            instance = new EndpointReferenceFactory();

+        return instance;

+    }

+

+    public EndpointReference getRegistrationEndpoint(String id) {

+        //TODO set this somehow reading the conf file

+        EndpointReference epr = new EndpointReference(

+                "http://localhost:8082/axis/services/RegistrationCoordinator";);

+        AnyContentType refProperties = new AnyContentType();

+        refProperties.addReferenceValue(

+                new QName("http://ws.apache.org/Kandula";, "id"), id);

+        epr.setReferenceProperties(refProperties);

+        return epr;

+    }

+    

+    public EndpointReference getCompletionParticipantEndpoint(String id) {

+        //TODO set this somehow reading the conf file

+        EndpointReference epr = new EndpointReference(

+                "http://localhost:5059/axis/services/CompletionParticipant";);

+        AnyContentType refProperties = new AnyContentType();

+        refProperties.addReferenceValue(

+                new QName("http://ws.apache.org/Kandula";, "id"), id);

+        epr.setReferenceProperties(refProperties);

+        return epr;

+    }

+

+    public EndpointReference getCompletionEndpoint(String id) {

+        //TODO set this somehow reading the conf file

+        EndpointReference epr = new EndpointReference(

+                "http://localhost:8082/axis/services/RegistrationCoordinator";);

+        AnyContentType refProperties = new AnyContentType();

+        refProperties.addReferenceValue(

+                new QName("http://ws.apache.org/Kandula";, "id"), id);

+        epr.setReferenceProperties(refProperties);

+        return epr;

+    }

+

+    public EndpointReference get2PCEndpoint(String id) {

+        //TODO set this somehow reading the conf file

+        EndpointReference epr = new EndpointReference(

+                "http://localhost:8082/axis/services/RegistrationCoordinator";);

+        AnyContentType refProperties = new AnyContentType();

+        refProperties.addReferenceValue(

+                new QName("http://ws.apache.org/Kandula";, "id"), id);

+        epr.setReferenceProperties(refProperties);

+        return epr;

+    }

+    // public EndpointReferenceTypeImpl

+    // getEndpointReference(PortReferenceTypeImpl portType,

+    // ReferencePropertiesType referenceProperties) {

+    //         try {

+    //                 EndpointReferenceTypeImpl endpointReference = new

+    // EndpointReferenceTypeImpl(SchemaTypeImpl.);

+    //                 endpointReference.setPortTypesetPortType(portType);

+    //                 endpointReference.setProperties(referenceProperties);

+    //                 return endpointReference;

+    //         }

+    //         catch (Exception e) {

+    //                 if (e instanceof RuntimeException)

+    //                         throw (RuntimeException)e;

+    //                 else

+    //                         throw new RuntimeException(e);

+    //         }

+    // }

+}
\ No newline at end of file

Modified: 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaListener.java
URL: 
http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaListener.java?rev=280132&r1=280131&r2=280132&view=diff
==============================================================================
--- 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaListener.java
 (original)
+++ 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaListener.java
 Sun Sep 11 06:39:49 2005
@@ -42,9 +42,9 @@
 
     protected static org.apache.axis2.description.OperationDescription[] 
operations;
 
-    SimpleHTTPServer receiver = null;
+    private SimpleHTTPServer receiver = null;
 
-    boolean serverStarted = false;
+    private boolean serverStarted = false;
 
     public static final int SERVER_PORT = 5059;
 
@@ -71,6 +71,12 @@
             System.out.print("Server started on port " + SERVER_PORT + 
".....");
         }
 
+    }
+    
+    public void stop()
+    {
+        receiver.stop();
+        serverStarted = false;
     }
 
     /**

Added: 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaUtils.java
URL: 
http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaUtils.java?rev=280132&view=auto
==============================================================================
--- 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaUtils.java 
(added)
+++ 
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaUtils.java 
Sun Sep 11 06:39:49 2005
@@ -0,0 +1,110 @@
+/*
+ * Copyright  2004 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.kandula.utility;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Iterator;
+import java.util.Random;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.AnyContentType;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.AddressingConstants.Final;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.soap.SOAPFactory;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Thilina Gunarathne </a>
+ */
+public class KandulaUtils {
+    public static void endpointToOM(EndpointReference epr, OMElement 
parentEPR,SOAPFactory factory)
+    {
+        OMNamespace wsAddressing = factory.createOMNamespace(
+                AddressingConstants.Submission.WSA_NAMESPACE,
+                AddressingConstants.WSA_DEFAULT_PRFIX);
+        OMElement addressElement = factory.createOMElement("Address",
+                wsAddressing);
+        addressElement.setText(epr.getAddress());
+        parentEPR.addChild(addressElement);
+        AnyContentType referenceValues = epr.getReferenceProperties();
+        if (referenceValues != null) {
+            OMElement refPropertyElement = factory.createOMElement(
+                    "ReferenceProperties", wsAddressing);
+            parentEPR.addChild(refPropertyElement);
+            Iterator iterator = referenceValues.getKeys();
+            while (iterator.hasNext()) {
+                QName key = (QName) iterator.next();
+                String value = referenceValues.getReferenceValue(key);
+                OMElement omElement = factory.createOMElement(key,
+                        refPropertyElement);
+                refPropertyElement.addChild(omElement);
+                if (Final.WSA_NAMESPACE.equals(wsAddressing)) {
+                    omElement.addAttribute(
+                            Final.WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE,
+                            Final.WSA_TYPE_ATTRIBUTE_VALUE, wsAddressing);
+                }
+                omElement.setText(value);
+            }
+        }
+    }
+    /**
+     * MD5 a random string with localhost/date etc will return 128 bits
+     * construct a string of 18 characters from those bits.
+     * @return string
+     */
+    public static String getRandomStringOf18Characters() {
+        Random myRand = new Random();
+        long rand = myRand.nextLong();
+        String sid;
+        try {
+            sid = InetAddress.getLocalHost().toString();
+        } catch (UnknownHostException e) {
+            sid = Thread.currentThread().getName();
+        }
+        long time = System.currentTimeMillis();
+        StringBuffer sb = new StringBuffer();
+        sb.append(sid);
+        sb.append(":");
+        sb.append(Long.toString(time));
+        sb.append(":");
+        sb.append(Long.toString(rand));
+        MessageDigest md5 = null;
+        try {
+            md5 = MessageDigest.getInstance("MD5");
+        } catch (NoSuchAlgorithmException e) {
+            //System.out.println("Error: " + e);
+            //todo heve to be properly handle
+        }
+        md5.update(sb.toString().getBytes());
+        byte[] array = md5.digest();
+        StringBuffer sb2 = new StringBuffer();
+        for (int j = 0; j < array.length; ++j) {
+            int b = array[j] & 0xFF;
+            sb2.append(Integer.toHexString(b));
+        }
+        int begin = myRand.nextInt();
+        if(begin < 0) begin = begin * -1;
+        begin = begin % 8;
+        return new String(sb2.toString().substring(begin, begin + 
18)).toUpperCase();
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to