Esempio n. 1
0
        public void TestGetConnectionEndPoint()
        {
            AFSwinxConnection connection = new AFSwinxConnection("example.com", 8080, "/AFServer/resource", "http");

            String actual = Utils.GetConnectionEndPoint(connection);
            String expected = "http://example.com:8080/AFServer/resource";
            Assert.AreEqual(actual, expected);

            //test without port
            connection.setPort(0);
            expected = "http://example.com/AFServer/resource";
            actual = Utils.GetConnectionEndPoint(connection);
            Assert.AreEqual(actual, expected);
        }
Esempio n. 2
0
 public AFSwinxConnectionPack parseDocument(XmlDocument documentToParse)
 {
     // Prepare connection pack
     AFSwinxConnectionPack connectionPack = new AFSwinxConnectionPack();
     // Find root of document
     XmlNodeList childs = documentToParse.GetElementsByTagName(CONNECTION_TAG);
     foreach (IXmlNode connectionRoot in childs)
     {
         if (connectionRoot.NodeType != NodeType.ElementNode)
         {
             continue;
         }
         // For each connection check if it's id is id which must be parsed
         XmlElement nodeElement = (XmlElement)connectionRoot;
         if (nodeElement.GetAttribute(CONNECTION_ID_ATTRIBUTE).Equals(connectionId))
         {
             XmlNodeList connectionsTypes = connectionRoot.ChildNodes;
             for (uint j = 0; j < connectionsTypes.Length; j++)
             {
                 IXmlNode concreteConnection = connectionsTypes.Item(j);
                 if (concreteConnection.NodeType != NodeType.ElementNode)
                 {
                     continue;
                 }
                 String connectionName = concreteConnection.NodeName;
                 XmlNodeList nodeProperties = concreteConnection.ChildNodes;
                 // Create new connection
                 AFSwinxConnection connection = new AFSwinxConnection();
                 for (uint k = 0; k < nodeProperties.Length; k++)
                 {
                     // Set connection properties
                     IXmlNode property = nodeProperties.Item(k);
                     String nodeName = property.NodeName;
                     String nodeValue = property.InnerText;
                     if (nodeName.Equals(END_POINT))
                     {
                         connection.setAddress(evaluateEL(nodeValue));
                     }
                     else if (nodeName.Equals(END_POINT_PARAMETERS))
                     {
                         connection.setParameters(evaluateEL(nodeValue));
                     }
                     else if (nodeName.Equals(PROTOCOL))
                     {
                         connection.setProtocol(evaluateEL(nodeValue));
                     }
                     else if (nodeName.Equals(PORT))
                     {
                         String port = evaluateEL(nodeValue);
                         if (!String.IsNullOrEmpty(port))
                         {
                             connection.setPort(Convert.ToInt32(evaluateEL(nodeValue)));
                         }
                     }
                     else if (nodeName.Equals(HEADER_PARAM))
                     {
                         parseHeaderParam(connection, property.ChildNodes);
                     }
                     else if (nodeName.Equals(HTTP_METHOD))
                     {
                         String method = evaluateEL(nodeValue);
                         if (method.ToLower().Equals("get"))
                         {
                             connection.setHttpMethod(HttpMethod.Get);
                         }
                         else if (method.ToLower().Equals("post"))
                         {
                             connection.setHttpMethod(HttpMethod.Post);
                         }
                         else if (method.ToLower().Equals("put"))
                         {
                             connection.setHttpMethod(HttpMethod.Put);
                         }
                         else if (method.ToLower().Equals("delete"))
                         {
                             connection.setHttpMethod(HttpMethod.Delete);
                         }
                         else
                         {
                             //method not supported
                         }
                         //get method
                     }
                     else if (nodeName.Equals(SECURITY_PARAMS))
                     {
                         parseSecurityParams(connection, property.ChildNodes);
                     }
                 }
                 // Set created connection to connection holder based on connection type
                 if (connectionName.Equals(METAMODEL_CONNECTION))
                 {
                     connection.setHttpMethod(HttpMethod.Get);
                     connectionPack.setMetamodelConnection(connection);
                 }
                 else if (connectionName.Equals(DATA_CONNECTION))
                 {
                     connection.setHttpMethod(HttpMethod.Get);
                     connectionPack.setDataConnection(connection);
                 }
                 else if (connectionName.Equals(SEND_CONNECTION))
                 {
                     if (connection.getHttpMethod() == null)
                     {
                         connection.setHttpMethod(HttpMethod.Post);
                     }
                     connectionPack.setSendConnection(connection);
                 }
                 else if (connectionName.Equals(REMOVE_CONNECTION))
                 {
                     if (connection.getHttpMethod() == null)
                     {
                         connection.setHttpMethod(HttpMethod.Delete);
                     }
                 }
             }
         }
     }
     return connectionPack;
 }