コード例 #1
0
        public void testRemoteStreamsFileStream()
        {
            log.info("testRemoteStreamsFileStream(");
            String   str  = "hallo";
            FileInfo file = new FileInfo(Path.GetTempFileName() + " € ß.txt");

            File.WriteAllText(file.FullName, str);
            BContentStream istrm = new BContentStreamWrapper(file.OpenRead(), "text/plain", file.Length);

            istrm.FileName = file.Name;
            remote.SetImage(istrm);
            BContentStream istrmR = (BContentStream)remote.GetImage();

            TestUtils.assertEquals(log, "Content-Type", "text/plain", istrmR.ContentType);
            TestUtils.assertEquals(log, "Content-Length", file.Length, istrmR.ContentLength);
            TestUtils.assertEquals(log, "FileName", file.Name, istrmR.FileName);

            ByteBuffer buf  = BWire.bufferFromStream(istrmR, false);
            String     strR = File.ReadAllText(file.FullName);

            TestUtils.assertEquals(log, "stream", str, strR);

            TestUtils.assertEquals(log, "Content-Type", "text/plain", istrmR.ContentType);
            TestUtils.assertEquals(log, "Content-Length", file.Length, istrmR.ContentLength);
            TestUtils.assertEquals(log, "FileName", file.Name, istrmR.FileName);

            file.Delete();
            log.info(")testRemoteStreamsFileStream");
        }
コード例 #2
0
        private void internalTestThrowExOnRead(bool throwEx, bool throwError)
        {
            log.info("internalTestThrowExOnRead(throwEx=" + throwEx + ", throwError=" + throwError);

            IDictionary <int, Stream> streams = new Dictionary <int, Stream>();

            for (int i = 0; i < 3; i++)
            {
                String str   = "hello-" + i;
                Stream istrm = new MyInputStream(Encoding.ASCII.GetBytes(str), i == 1 && throwEx, i == 1 && throwError);
                streams[i] = istrm;
            }

            // An exception is thrown in HWireClient.
            try
            {
                log.info("setImages...");
                remote.SetImages(streams, -1);
                Assert.Fail("Exception expected");
            }
            catch (BException e)
            {
                log.info("setImages ex=" + e + ", OK");
                String expectedMessage = throwEx ? "Test Exception" : "Test Error";
                String expectedDetails = throwEx ? "System.IO.IOException: Test Exception" : "System.InvalidOperationException: Test Error";
                TestUtils.assertEquals(log, "Exception Code", BExceptionC.IOERROR, e.Code);
                TestUtils.assertEquals(log, "Exception Message", expectedMessage, e.Message);
                String readDetails = e.Details.Substring(0, expectedDetails.Length);
                TestUtils.assertEquals(log, "Exception Details", expectedDetails, readDetails);
            }

            {
                log.info("read streams");
                IDictionary <int, Stream> istrmsR = remote.GetImages();
                for (int i = 0; i < istrmsR.Count; i++)
                {
                    Stream     istrmR = istrmsR[i];
                    ByteBuffer buf    = BWire.bufferFromStream(istrmR, false);
                    String     strR   = Encoding.ASCII.GetString(buf.array(), buf.position(), buf.remaining());
                    log.info("strR=" + strR);
                }
            }

            // All streams must have been closed
            log.info("streams must be closed");
            for (int i = 0; i < streams.Count; i++)
            {
                MyInputStream istrm = (MyInputStream)streams[i];
                TestUtils.assertEquals(log, "InputStream.isClosed", true, istrm.isClosed);
            }

            log.info(")internalTestThrowExOnRead");
        }
コード例 #3
0
        public void testRemoteStreamsOneStreamNotChunked()
        {
            log.info("testRemoteStreamsOneStreamNotChunked(");
            String str   = "hello";
            Stream istrm = new MemoryStream(Encoding.ASCII.GetBytes(str));

            remote.SetImage(istrm);
            Stream     istrmR = remote.GetImage();
            ByteBuffer buf    = BWire.bufferFromStream(istrmR, false);
            String     strR   = Encoding.ASCII.GetString(buf.array(), buf.position(), buf.remaining());

            TestUtils.assertEquals(log, "stream", str, strR);
            log.info(")testRemoteStreamsOneStreamNotChunked");
        }
コード例 #4
0
        private void internalTestRemoteStreamsManyStreams(int nbOfStreams)
        {
            IDictionary <int, Stream> streams = new Dictionary <int, Stream>();

            for (int i = 0; i < nbOfStreams; i++)
            {
                String str   = "hello-" + i;
                Stream istrm = new MemoryStream(Encoding.ASCII.GetBytes(str));
                streams[i] = istrm;
            }
            remote.SetImages(streams, -1);
            Dictionary <int, Stream> istrmsR = remote.GetImages();

            TestUtils.assertEquals(log, "streams", streams, istrmsR); // Does not compare streams.
            for (int i = 0; i < nbOfStreams; i++)
            {
                Stream     istrmR = istrmsR[i];
                ByteBuffer buf    = BWire.bufferFromStream(istrmR, false);
                String     strR   = Encoding.ASCII.GetString(buf.array(), buf.position(), buf.remaining());
                TestUtils.assertEquals(log, "stream", "hello-" + i, strR);
            }
        }
コード例 #5
0
ファイル: IXConnFactory.cs プロジェクト: ThomasEcherer/elo
        protected override void internalAuthenticate(BClient_Indexserver client, BAsyncResult <bool> asyncResult)
        {
            // Aktuelle ClientInfo bereitstellen, wg. Landessprache, Zeitzone usw.
            ClientInfo ci = getLoginResult().clientInfo;

            // Verbindungsobjekt für GET-Request
            IXWireClient wire = (IXWireClient)client.getTransport().getWire();

            HttpWebResponse resp = null;

            try
            {
                String loginServletUrl = wire.getUrlForAuthentication();

                long negotiatedVersion     = client.getTransport().getProtocol().negotiatedVersion;
                long negotiatedBypsVersion = client.getTransport().getProtocol().negotiatedBypsVersion;

                // Schreibe diese 9er Version für die Verbindung zu IX 9.0.
                // Weil bei ELO 9 ein String-Vergleich gemacht wird, wäre sonst die Version 10 kleiner als die Version 9
                loginServletUrl += "?streamversion=" + BVersioning.stringToLong("9.99.0.0");

                loginServletUrl += "&bstreamversion=" + BVersioning.longToString(negotiatedVersion);
                loginServletUrl += "&bversion=" + negotiatedBypsVersion;

                loginServletUrl += "&responseformat=byps-binary";
                if (ci.language != null)
                {
                    loginServletUrl += "&language=" + ci.language;
                }
                if (ci.timeZone != null)
                {
                    loginServletUrl += "&timezone=" + HttpUtility.UrlEncode(ci.timeZone);
                }
                if (ci.country != null)
                {
                    loginServletUrl += "&country=" + ci.country;
                }
                if (ci.callId != null)
                {
                    loginServletUrl += "&callid=" + HttpUtility.UrlEncode(ci.callId);
                }
                if (computerName != null)
                {
                    loginServletUrl += "&computerName=" + HttpUtility.UrlEncode(computerName);
                }

                // Sitzungskennung übergeben.
                // Sie wird direkt verworfen und es wird eine neue erstellt.
                loginServletUrl += "&sessionid=" + HttpUtility.UrlEncode(client.getTransport().getSessionId());

                if (WebRequest.DefaultWebProxy != null)
                {
                    WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
                }

                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(loginServletUrl);
                req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                req.Credentials = CredentialCache.DefaultCredentials;

                //http://blogs.msdn.com/buckh/archive/2004/07/28/199706.aspx

                //CredentialCache credCache = new CredentialCache();
                //credCache.Add(new Uri(loginServletUrl), "NTLM",
                //              CredentialCache.DefaultNetworkCredentials);
                //req.Credentials = credCache;

                resp = (HttpWebResponse)req.GetResponse();

                if (resp.StatusCode != HttpStatusCode.OK)
                {
                    asyncResult(false, new BException((int)resp.StatusCode, "HTTP Status " + resp.StatusCode));
                }

                Stream     responseStream = resp.GetResponseStream();
                ByteBuffer buf            = BWire.bufferFromStream(responseStream, false);

                BMessageHeader header = new BMessageHeader();
                header.read(buf);

                // Neue Sitzungs-ID übernehmen
                if (!header.targetId.isZero())
                {
                    client.getTransport().setTargetId(header.targetId);
                    client.getTransport().setSessionId(header.sessionId);
                }

                BInput      bin         = client.getTransport().getInput(header, buf);
                LoginResult loginResult = (LoginResult)bin.load();

                this.setLoginResult(loginResult);
                asyncResult(false, null);
            }
            catch (Exception e)
            {
                asyncResult(false, e);
            }
            finally
            {
                if (resp != null)
                {
                    resp.Close();
                }
            }
        }