Package java.net

Examples of java.net.ProtocolException


    * @exception ProtocolException if already connected.
    */
   public void setRequestMethod(String method) throws ProtocolException
   {
      if (connected)
         throw new ProtocolException("Already connected!");

      if (log.isDebugEnabled())
         log.debug(urlString + " Setting request method: " + method);

      this.method = method.trim().toUpperCase();
View Full Code Here


    * @see java.net.URLConnection#setDoInput(boolean)
    */
   public InputStream getInputStream() throws IOException
   {
      if (!doInput)
         throw new ProtocolException("Input not enabled! (use setDoInput(true))");

      if (!connected)
         connect();

      InputStream stream;
View Full Code Here

    * @see HTTPClient.HttpOutputStream
    */
   public synchronized OutputStream getOutputStream() throws IOException
   {
      if (connected)
         throw new ProtocolException("Already connected!");

      if (!doOutput)
         throw new ProtocolException("Output not enabled! (use setDoOutput(true))");
      if (!method_set)
         method = "POST";
      else if (method.equals("HEAD") || method.equals("GET") || method.equals("TRACE"))
         throw new ProtocolException("Method " + method + " does not support output!");

      if (getRequestProperty("Content-type") == null)
         setRequestProperty("Content-type", "application/x-www-form-urlencoded");

      if (output_stream == null)
View Full Code Here

            if (cont_len < 0)
               throw new NumberFormatException();
         }
         catch (NumberFormatException nfe)
         {
            throw new ProtocolException("Invalid Content-length header" + " received: " + cl_hdr);
         }
      }

      // parse the Transfer-Encoding header
View Full Code Here

         if (Version.equalsIgnoreCase("HTTP")) // NCSA bug
            Version = "HTTP/1.0";
      }
      catch (NoSuchElementException e)
      {
         throw new ProtocolException("Invalid HTTP status line received: " + sts_line);
      }
      try
      {
         ReasonLine = elem.nextToken("").trim();
      }
View Full Code Here

          */
         if (sep == -1)
            sep = hdr.indexOf(' ');
         if (sep == -1)
         {
            throw new ProtocolException("Invalid HTTP header received: " + hdr);
         }

         String hdr_name = hdr.substring(0, sep).trim();
         String hdr_value = hdr.substring(sep + 1).trim();

View Full Code Here

      {
         cookies = Util.parseHeader(set_cookie);
      }
      catch (ParseException pe)
      {
         throw new ProtocolException(pe.getMessage());
      }

      Cookie cookie_arr[] = new Cookie[cookies.size()];
      int cidx = 0;
      for (int idx = 0; idx < cookie_arr.length; idx++)
      {
         HttpHeaderElement c_elem = (HttpHeaderElement)cookies.elementAt(idx);

         // set NAME and VALUE

         if (c_elem.getValue() == null)
            throw new ProtocolException("Bad Set-Cookie2 header: " + set_cookie + "\nMissing value " + "for cookie '"
               + c_elem.getName() + "'");
         Cookie2 curr = new Cookie2(req);
         curr.name = c_elem.getName();
         curr.value = c_elem.getValue();

         // set all params

         NVPair[] params = c_elem.getParams();
         boolean discard_set = false, secure_set = false;
         for (int idx2 = 0; idx2 < params.length; idx2++)
         {
            String name = params[idx2].getName().toLowerCase();

            // check for required value parts
            if ((name.equals("version") || name.equals("max-age") || name.equals("domain") || name.equals("path")
               || name.equals("comment") || name.equals("commenturl"))
               && params[idx2].getValue() == null)
            {
               throw new ProtocolException("Bad Set-Cookie2 header: " + set_cookie + "\nMissing value " + "for "
                  + params[idx2].getName() + " attribute in cookie '" + c_elem.getName() + "'");
            }

            if (name.equals("version")) // Version
            {
               if (curr.version != -1)
                  continue;
               try
               {
                  curr.version = Integer.parseInt(params[idx2].getValue());
               }
               catch (NumberFormatException nfe)
               {
                  throw new ProtocolException("Bad Set-Cookie2 header: " + set_cookie + "\nVersion '"
                     + params[idx2].getValue() + "' not a number");
               }
            }
            else if (name.equals("path")) // Path
            {
               if (curr.path_set)
                  continue;
               curr.path = params[idx2].getValue();
               curr.path_set = true;
            }
            else if (name.equals("domain")) // Domain
            {
               if (curr.domain_set)
                  continue;
               String d = params[idx2].getValue().toLowerCase();

               // add leading dot if not present and if domain is
               // not the full host name
               if (d.charAt(0) != '.' && !d.equals(curr.domain))
                  curr.domain = "." + d;
               else
                  curr.domain = d;
               curr.domain_set = true;
            }
            else if (name.equals("max-age")) // Max-Age
            {
               if (curr.expires != null)
                  continue;
               int age;
               try
               {
                  age = Integer.parseInt(params[idx2].getValue());
               }
               catch (NumberFormatException nfe)
               {
                  throw new ProtocolException("Bad Set-Cookie2 header: " + set_cookie + "\nMax-Age '"
                     + params[idx2].getValue() + "' not a number");
               }
               curr.expires = new Date(System.currentTimeMillis() + age * 1000L);
            }
            else if (name.equals("port")) // Port
            {
               if (curr.port_set)
                  continue;

               if (params[idx2].getValue() == null)
               {
                  curr.port_list = new int[1];
                  curr.port_list[0] = req.getConnection().getPort();
                  curr.port_set = true;
                  continue;
               }

               curr.port_list_str = params[idx2].getValue();
               StringTokenizer tok = new StringTokenizer(params[idx2].getValue(), ",");
               curr.port_list = new int[tok.countTokens()];
               for (int idx3 = 0; idx3 < curr.port_list.length; idx3++)
               {
                  String port = tok.nextToken().trim();
                  try
                  {
                     curr.port_list[idx3] = Integer.parseInt(port);
                  }
                  catch (NumberFormatException nfe)
                  {
                     throw new ProtocolException("Bad Set-Cookie2 header: " + set_cookie + "\nPort '" + port
                        + "' not a number");
                  }
               }
               curr.port_set = true;
            }
            else if (name.equals("discard")) // Domain
            {
               if (discard_set)
                  continue;
               curr.discard = true;
               discard_set = true;
            }
            else if (name.equals("secure")) // Secure
            {
               if (secure_set)
                  continue;
               curr.secure = true;
               secure_set = true;
            }
            else if (name.equals("comment")) // Comment
            {
               if (curr.comment != null)
                  continue;
               try
               {
                  curr.comment = new String(params[idx2].getValue().getBytes("8859_1"), "UTF8");
               }
               catch (UnsupportedEncodingException usee)
               {
                  throw new Error(usee.toString()); /* shouldn't happen */
               }
            }
            else if (name.equals("commenturl")) // CommentURL
            {
               if (curr.comment_url != null)
                  continue;
               try
               {
                  curr.comment_url = new URI(params[idx2].getValue());
               }
               catch (ParseException pe)
               {
                  throw new ProtocolException("Bad Set-Cookie2 header: " + set_cookie + "\nCommentURL '"
                     + params[idx2].getValue() + "' not a valid URL");
               }
            }
            // ignore unknown element
         }
View Full Code Here

    }

    @Override
    public InputStream getInputStream() throws IOException {
        if (!doInput) {
            throw new ProtocolException(Msg.getString("K008d")); //$NON-NLS-1$
        }

        // connect before sending requests
        connect();
        doRequest();
View Full Code Here

    }

    @Override
    public OutputStream getOutputStream() throws IOException {
        if (!doOutput) {
            throw new ProtocolException(Msg.getString("K008e")); //$NON-NLS-1$
        }

        // you can't write after you read
        if (sentRequest) {
            throw new ProtocolException(Msg.getString("K0090")); //$NON-NLS-1$
        }

        if (os != null) {
            return os;
        }

        // they are requesting a stream to write to. This implies a POST method
        if (method == GET) {
            method = POST;
        }

        // If the request method is neither PUT or POST, then you're not writing
        if (method != PUT && method != POST) {
            throw new ProtocolException(Msg.getString("K008f", method)); //$NON-NLS-1$
        }

        int limit = -1;
        String contentLength = reqHeader.get("Content-Length"); //$NON-NLS-1$
        if (contentLength != null) {
View Full Code Here

                        || responseCode == HTTP_MOVED_TEMP
                        || responseCode == HTTP_SEE_OTHER || responseCode == HTTP_USE_PROXY)
                        && os == null) {

                    if (++redirect > 4) {
                        throw new ProtocolException(Msg.getString("K0093")); //$NON-NLS-1$
                    }
                    String location = getHeaderField("Location"); //$NON-NLS-1$
                    if (location != null) {
                        // start over
                        if (responseCode == HTTP_USE_PROXY) {
View Full Code Here

TOP

Related Classes of java.net.ProtocolException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.