/**
         * Opens the connection.
         */
        protected void create(Env env)

        {
            URL url = getURL(env, _curl.getURL(), _curl.getPort());

            if (url == null)
            {
                return;
            }

            if (_curl.getIsProxying())
            {
                URL proxyURL = getURL(env, _curl.getProxyURL(), _curl.getProxyPort());

                _conn = CurlHttpConnection.createConnection(url,
                                                            _curl.getUsername(),
                                                            _curl.getPassword(),
                                                            _curl,
                                                            proxyURL,
                                                            _curl.getProxyUsername(),
                                                            _curl.getProxyPassword(),
                                                            _curl.getProxyType());
            }
            else
            {
                _conn = CurlHttpConnection.createConnection(url,
                                                            _curl.getUsername(),
                                                            _curl.getPassword(),
                                                            _curl);
            }
        }
Exemple #2
0
        /**
         * Transfer data to the server.
         */
        protected void transfer(Env env)

        {
            super.transfer(env);

            CurlHttpConnection conn = getHttpConnection();
            OutputStream       @out = conn.getOutputStream();

            //out = new TestOutputStream(out);

            _body.writeTo(env, out);
        }
Exemple #3
0
        /**
         * Initializes the connection.
         */
        protected bool init(Env env)

        {
            if (!super.init(env))
            {
                return(false);
            }

            _body = PostBody.create(env, getCurlResource());

            if (_body == null)
            {
                return(false);
            }

            CurlHttpConnection conn = getHttpConnection();

            if (conn.getRequestProperty("Content-Type") == null)
            {
                conn.setRequestProperty("Content-Type",
                                        _body.getContentType());
            }

            if (conn.getRequestProperty("Content-Length") == null)
            {
                long contentLength = _body.getContentLength();

                if (contentLength >= 0)
                {
                    conn.setRequestProperty("Content-Length",
                                            String.valueOf(contentLength));
                }
                else if (false && _body.isChunked())
                {
                    conn.setRequestProperty("Transfer-Encoding", "chunked");
                }
            }

            conn.setDoOutput(true);

            return(true);
        }
Exemple #4
0
        /**
         * Transfer data to the server.
         */
        protected void transfer(Env env)

        {
            super.transfer(env);

            CurlHttpConnection conn = getHttpConnection();
            OutputStream       @out = conn.getOutputStream();

            CurlResource curl = getCurlResource();

            try {
                BinaryInput in = curl.getUploadFile();
                long length = curl.getUploadFileSize();

                long totalWritten = 0;

                if (curl.getReadCallback() != null)
                {
                    Callable callback = curl.getReadCallback();

                    Value     fileV   = env.wrapJava(in);
                    LongValue lengthV = LongValue.create(length);

                    while (totalWritten < length)
                    {
                        StringValue str
                            = callback.call(env, fileV, lengthV).ToStringValue(env);

                        int count = str.length();

                        if (count == 0)
                        {
                            break;
                        }

                        str.writeTo(out);

                        totalWritten += count;
                    }
                }
                else
                {
                    byte [] buffer = new byte[1024 * 4];

                    while (totalWritten < length)
                    {
                        int count = in.read(buffer, 0, buffer.length);

                        if (count < 0)
                        {
                            break;
                        }

                        @out.write(buffer, 0, count);

                        totalWritten += count;
                    }
                }
            }
            finally {
                @out.close();
            }
        }