Package java.net

Examples of java.net.ProtocolException


            break;

         if (!first) // expect ","
         {
            if (buf[beg] != ',')
               throw new ProtocolException("Bad Authentication header " + "format: '" + challenge
                  + "'\nExpected \",\" at position " + beg);

            beg = Util.skipSpace(buf, beg + 1); // find param name
            if (beg == len)
               break;
            if (buf[beg] == ',') // skip empty params
            {
               end = beg;
               continue;
            }
         }

         int pstart = beg;

         // extract name
         end = beg + 1;
         while (end < len && !Character.isWhitespace(buf[end]) && buf[end] != '=' && buf[end] != ',')
            end++;

         // hack to deal with schemes which use cookies in challenge
         if (first && (end == len || buf[end] == '=' && (end + 1 == len || (buf[end + 1] == '=' && end + 2 == len))))
         {
            curr.cookie = challenge.substring(beg, len);
            beg = len;
            break;
         }

         String param_name = challenge.substring(beg, end), param_value;

         beg = Util.skipSpace(buf, end); // find "=" or ","

         if (beg < len && buf[beg] != '=' && buf[beg] != ',' ||
         /* This deals with the M$ crap */
         !first && (beg == len || buf[beg] == ','))
         {
            // It's not a param, but another challenge
            beg = pstart;
            break;
         }

         if (beg < len && buf[beg] == '=') // we have a value
         {
            beg = Util.skipSpace(buf, beg + 1);
            if (beg == len)
               throw new ProtocolException("Bad Authentication header " + "format: " + challenge
                  + "\nUnexpected EOL after token" + " at position " + (end - 1));
            if (buf[beg] != '"') // it's a token
            {
               end = Util.skipToken(buf, beg);
               if (end == beg)
                  throw new ProtocolException("Bad Authentication header " + "format: " + challenge
                     + "\nToken expected at " + "position " + beg);
               param_value = challenge.substring(beg, end);
            }
            else
            // it's a quoted-string
            {
               end = beg++;
               do
                  end = challenge.indexOf('"', end + 1);
               while (end != -1 && challenge.charAt(end - 1) == '\\');
               if (end == -1)
                  throw new ProtocolException("Bad Authentication header " + "format: " + challenge
                     + "\nClosing <\"> for " + "quoted-string starting at position " + beg + " not found");
               param_value = Util.dequoteString(challenge.substring(beg, end));
               end++;
            }
         }
View Full Code Here


            new URI(req.getConnection().getProtocol(), req.getConnection().getHost(), req.getConnection().getPort(),
               null);
         base = new URI(base, req.getRequestURI());
         URI res = new URI(base, loc);
         if (res.getHost() == null)
            throw new ProtocolException("Malformed URL in Location header: `" + loc + "' - missing host field");
         return res;
      }
      catch (ParseException pe)
      {
         throw new ProtocolException("Malformed URL in Location header: `" + loc + "' - exception was: "
            + pe.getMessage());
      }
   }
View Full Code Here

            // guard against infinite retries due to bugs

            num_tries++;
            if (num_tries > 10)
               throw new ProtocolException("Bug in authorization handling: server refused the given info 10 times");

            // defer handling if a stream was used

            if (req.getStream() != null)
            {
View Full Code Here

      if (auth_sent == null && prxy_sent == null && resp.getHeader("WWW-Authenticate") == null
         && resp.getHeader("Proxy-Authenticate") == null)
      {
         if (resp.getStatusCode() == 401)
            throw new ProtocolException("Missing WWW-Authenticate header");
         else
            throw new ProtocolException("Missing Proxy-Authenticate header");
      }
   }
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

            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

    */
   @Override
   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

    */
   @Override
   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

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.