Package java.net

Examples of java.net.ProtocolException


         // get cookie name and value first

         end = set_cookie.indexOf('=', beg);
         if (end == -1)
            throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nNo '=' found "
               + "for token starting at " + "position " + beg);
         curr.name = set_cookie.substring(beg, end).trim();

         beg = Util.skipSpace(buf, end + 1);
         int comma = set_cookie.indexOf(',', beg);
         int semic = set_cookie.indexOf(';', beg);
         if (comma == -1 && semic == -1)
            end = len;
         else if (comma == -1)
            end = semic;
         else if (semic == -1)
            end = comma;
         else
         {
            if (comma > semic)
               end = semic;
            else
            {
               // try to handle broken servers which put commas
               // into cookie values
               int eq = set_cookie.indexOf('=', comma);
               if (eq > 0 && eq < semic)
                  end = set_cookie.lastIndexOf(',', eq);
               else
                  end = semic;
            }
         }
         curr.value = set_cookie.substring(beg, end).trim();

         beg = end;

         // now parse attributes

         boolean legal = true;
         parts : while (true) // parse all parts
         {
            if (beg >= len || buf[beg] == ',')
               break;

            // skip empty fields
            if (buf[beg] == ';')
            {
               beg = Util.skipSpace(buf, beg + 1);
               continue;
            }

            // first check for secure, as this is the only one w/o a '='
            if ((beg + 6 <= len) && set_cookie.regionMatches(true, beg, "secure", 0, 6))
            {
               curr.secure = true;
               beg += 6;

               beg = Util.skipSpace(buf, beg);
               if (beg < len && buf[beg] == ';') // consume ";"
                  beg = Util.skipSpace(buf, beg + 1);
               else if (beg < len && buf[beg] != ',')
                  throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nExpected "
                     + "';' or ',' at position " + beg);

               continue;
            }

            // alright, must now be of the form x=y
            end = set_cookie.indexOf('=', beg);
            if (end == -1)
               throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nNo '=' found "
                  + "for token starting at " + "position " + beg);

            String name = set_cookie.substring(beg, end).trim();
            beg = Util.skipSpace(buf, end + 1);
View Full Code Here


         {
            age = Integer.parseInt(value);
         }
         catch (NumberFormatException nfe)
         {
            throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nMax-Age '" + value
               + "' not a number");
         }
         cookie.expires = new Date(System.currentTimeMillis() + age * 1000L);
      }
      else if (name.equalsIgnoreCase("domain"))
View Full Code Here

         {
            sts = resp.getStatusCode();
         }
         catch (IOException ioe)
         {
            throw new ProtocolException(ioe.toString());
         }
         if (sts == 401)
            curr = new AuthorizationInfo(req.getConnection().getHost(), req.getConnection().getPort());
         else
            curr = new AuthorizationInfo(req.getConnection().getProxyHost(), req.getConnection().getProxyPort());
View Full Code Here

            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

            // 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

         // get cookie name and value first

         end = set_cookie.indexOf('=', beg);
         if (end == -1)
            throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nNo '=' found "
               + "for token starting at " + "position " + beg);
         curr.name = set_cookie.substring(beg, end).trim();

         beg = Util.skipSpace(buf, end + 1);
         int comma = set_cookie.indexOf(',', beg);
         int semic = set_cookie.indexOf(';', beg);
         if (comma == -1 && semic == -1)
            end = len;
         else if (comma == -1)
            end = semic;
         else if (semic == -1)
            end = comma;
         else
         {
            if (comma > semic)
               end = semic;
            else
            {
               // try to handle broken servers which put commas
               // into cookie values
               int eq = set_cookie.indexOf('=', comma);
               if (eq > 0 && eq < semic)
                  end = set_cookie.lastIndexOf(',', eq);
               else
                  end = semic;
            }
         }
         curr.value = set_cookie.substring(beg, end).trim();

         beg = end;

         // now parse attributes

         boolean legal = true;
         parts : while (true) // parse all parts
         {
            if (beg >= len || buf[beg] == ',')
               break;

            // skip empty fields
            if (buf[beg] == ';')
            {
               beg = Util.skipSpace(buf, beg + 1);
               continue;
            }

            // first check for secure, as this is the only one w/o a '='
            if ((beg + 6 <= len) && set_cookie.regionMatches(true, beg, "secure", 0, 6))
            {
               curr.secure = true;
               beg += 6;

               beg = Util.skipSpace(buf, beg);
               if (beg < len && buf[beg] == ';') // consume ";"
                  beg = Util.skipSpace(buf, beg + 1);
               else if (beg < len && buf[beg] != ',')
                  throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nExpected "
                     + "';' or ',' at position " + beg);

               continue;
            }

            // alright, must now be of the form x=y
            end = set_cookie.indexOf('=', beg);
            if (end == -1)
               throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nNo '=' found "
                  + "for token starting at " + "position " + beg);

            String name = set_cookie.substring(beg, end).trim();
            beg = Util.skipSpace(buf, end + 1);
View Full Code Here

         {
            age = Integer.parseInt(value);
         }
         catch (NumberFormatException nfe)
         {
            throw new ProtocolException("Bad Set-Cookie header: " + set_cookie + "\nMax-Age '" + value
               + "' not a number");
         }
         cookie.expires = new Date(System.currentTimeMillis() + age * 1000L);
      }
      else if (name.equalsIgnoreCase("domain"))
View Full Code Here

            }
            catch (IOException ioe)
            {
            }
            if (req.getData() != null)
               throw new ProtocolException("Received status code 411 even" + " though Content-Length was sent");

            if (log.isDebugEnabled())
               log.debug("Handling " + sts + " " + resp.getReasonLine()
                  + " - resending request with 'Content-length: 0'");
View Full Code Here

         {
            sts = resp.getStatusCode();
         }
         catch (IOException ioe)
         {
            throw new ProtocolException(ioe.toString());
         }
         if (sts == 401)
            curr = new AuthorizationInfo(req.getConnection().getHost(), req.getConnection().getPort());
         else
            curr = new AuthorizationInfo(req.getConnection().getProxyHost(), req.getConnection().getProxyPort());
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.