Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void ping() throws java.io.IOException
        internal virtual void Ping()
        {
            _pingCount++;

            IDictionary <string, string> usageDataMap = _collector.UdcParams;

            StringBuilder uri = new StringBuilder("http://" + _address + "/" + "?");

            foreach (KeyValuePair <string, string> entry in usageDataMap.SetOfKeyValuePairs())
            {
                uri.Append(entry.Key);
                uri.Append("=");
                uri.Append(URLEncoder.encode(entry.Value, StandardCharsets.UTF_8.name()));
                uri.Append("+");
            }

            uri.Append(PING + "=").Append(_pingCount);

            URL           url = new URL(uri.ToString());
            URLConnection con = url.openConnection();

            con.DoInput   = true;
            con.DoOutput  = false;
            con.UseCaches = false;
            con.connect();

            con.InputStream.close();
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static String getResponse(String serverAddress) throws java.io.IOException
        private static string GetResponse(string serverAddress)
        {
            string        url        = "http://" + serverAddress + "/metrics";
            URLConnection connection = (new URL(url)).openConnection();

            connection.DoOutput = true;
            connection.connect();
            using (Scanner s = (new Scanner(connection.InputStream, "UTF-8")).useDelimiter("\\A"))
            {
                assertTrue(s.hasNext());
                string ret = s.next();
                assertFalse(s.hasNext());
                return(ret);
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void httpEndpointShouldBeAvailableAndResponsive() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void HttpEndpointShouldBeAvailableAndResponsive()
        {
            string        url        = "http://" + getConnectorAddress(( GraphDatabaseAPI )_database, "prometheus") + "/metrics";
            URLConnection connection = (new URL(url)).openConnection();

            connection.DoOutput = true;
            connection.connect();
            Scanner s = (new Scanner(connection.InputStream, "UTF-8")).useDelimiter("\\A");

            assertTrue(s.hasNext());
            string response = s.next();

            assertTrue(response.Contains(COUNTS_NODE));
            assertTrue(response.Contains(COUNTS_RELATIONSHIP_TYPE));
        }
Exemple #4
0
        protected internal virtual Dictionary <string, string> executeSimpleUPnPcommand(string controlUrl, string serviceType, string action, Dictionary <string, string> arguments)
        {
            Dictionary <string, string> result = null;

            StringBuilder body = new StringBuilder();

            body.Append(string.Format("<?xml version=\"1.0\"?>\r\n"));
            body.Append(string.Format("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"));
            body.Append(string.Format("<s:Body>\r\n"));
            body.Append(string.Format("  <u:{0} xmlns:u=\"{1}\">\r\n", action, serviceType));
            if (arguments != null)
            {
                foreach (string name in arguments.Keys)
                {
                    string value = arguments[name];
                    if (string.ReferenceEquals(value, null) || value.Length == 0)
                    {
                        body.Append(string.Format("    <{0} />\r\n", name));
                    }
                    else
                    {
                        body.Append(string.Format("    <{0}>{1}</{2}>\r\n", name, value, name));
                    }
                }
            }
            body.Append(string.Format("  </u:{0}>\r\n", action));
            body.Append(string.Format("</s:Body>\r\n"));
            body.Append(string.Format("</s:Envelope>\r\n"));

            if (log.TraceEnabled)
            {
                log.trace(string.Format("Sending UPnP command: {0}", body.ToString()));
            }

            sbyte[] bodyBytes = body.ToString().GetBytes();

            try
            {
                URL           url        = new URL(controlUrl);
                URLConnection connection = url.openConnection();
                if (connection is HttpURLConnection)
                {
                    HttpURLConnection httpURLConnection = (HttpURLConnection)connection;
                    httpURLConnection.RequestMethod = "POST";
                }
                connection.setRequestProperty("SOAPAction", string.Format("{0}#{1}", serviceType, action));
                connection.setRequestProperty("Content-Type", "text/xml");
                connection.setRequestProperty("Content-Length", Convert.ToString(bodyBytes.Length));
                connection.DoOutput = true;
                System.IO.Stream output = connection.OutputStream;
                output.Write(bodyBytes, 0, bodyBytes.Length);
                output.Flush();
                output.Close();

                connection.connect();

                System.IO.Stream response = connection.InputStream;
                StringBuilder    content  = new StringBuilder();
                sbyte[]          buffer   = new sbyte[1024];
                int n;
                do
                {
                    n = response.Read(buffer, 0, buffer.Length);
                    if (n > 0)
                    {
                        content.Append(StringHelper.NewString(buffer, 0, n));
                    }
                } while (n >= 0);
                response.Close();

                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("UPnP command serviceType {0}, action {1}, result: {2}", serviceType, action, content.ToString()));
                }

                result = parseSimpleCommandResponse(content.ToString());

                //if (log.DebugEnabled)
                {
                    string errorCode = result["errorCode"];
                    if (!string.ReferenceEquals(errorCode, null))
                    {
                        Console.WriteLine(string.Format("UPnP command {0}: errorCode = {1}", action, errorCode));
                    }
                }
            }
            catch (MalformedURLException e)
            {
                Console.WriteLine("executeUPnPcommand", e);
            }
            catch (IOException e)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine("executeUPnPcommand", e);
                }
            }

            return(result);
        }