@Override
  public void writeExternal(ObjectOutput output) throws IOException {
    String data;
    Date date;
    List<Cookie> cookie_list = getCookies();
    output.writeInt(cookie_list.size());
    for (Cookie cookie : cookie_list) {
      output.writeUTF(cookie.getName());
      output.writeUTF(cookie.getValue());

      data = cookie.getComment();
      output.writeBoolean(data != null);
      if (data != null) output.writeUTF(data);

      date = cookie.getExpiryDate();
      output.writeBoolean(date != null);
      if (date != null) output.writeLong(date.getTime());

      data = cookie.getDomain();
      output.writeBoolean(data != null);
      if (data != null) output.writeUTF(data);

      data = cookie.getPath();
      output.writeBoolean(data != null);
      if (data != null) output.writeUTF(data);

      output.writeBoolean(cookie.isSecure());
      output.writeInt(cookie.getVersion());
    }
  }
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeObject(cookie.getName());
   out.writeObject(cookie.getValue());
   out.writeObject(cookie.getComment());
   out.writeObject(cookie.getDomain());
   out.writeObject(cookie.getExpiryDate());
   out.writeObject(cookie.getPath());
   out.writeInt(cookie.getVersion());
   out.writeBoolean(cookie.isSecure());
 }
 public List<Header> formatCookies(final List<Cookie> cookies) {
   if (cookies == null) {
     throw new IllegalArgumentException("List of cookies may not be null");
   }
   int version = Integer.MAX_VALUE;
   boolean isSetCookie2 = true;
   for (Cookie cookie : cookies) {
     if (!(cookie instanceof SetCookie2)) {
       isSetCookie2 = false;
     }
     if (cookie.getVersion() < version) {
       version = cookie.getVersion();
     }
   }
   if (version > 0) {
     if (isSetCookie2) {
       return getStrict().formatCookies(cookies);
     } else {
       return getObsoleteStrict().formatCookies(cookies);
     }
   } else {
     return getCompat().formatCookies(cookies);
   }
 }
 public boolean match(final Cookie cookie, final CookieOrigin origin) {
   if (cookie == null) {
     throw new IllegalArgumentException("Cookie may not be null");
   }
   if (origin == null) {
     throw new IllegalArgumentException("Cookie origin may not be null");
   }
   if (cookie.getVersion() > 0) {
     if (cookie instanceof SetCookie2) {
       return getStrict().match(cookie, origin);
     } else {
       return getObsoleteStrict().match(cookie, origin);
     }
   } else {
     return getCompat().match(cookie, origin);
   }
 }
 public void validate(final Cookie cookie, final CookieOrigin origin)
     throws MalformedCookieException {
   if (cookie == null) {
     throw new IllegalArgumentException("Cookie may not be null");
   }
   if (origin == null) {
     throw new IllegalArgumentException("Cookie origin may not be null");
   }
   if (cookie.getVersion() > 0) {
     if (cookie instanceof SetCookie2) {
       getStrict().validate(cookie, origin);
     } else {
       getObsoleteStrict().validate(cookie, origin);
     }
   } else {
     getCompat().validate(cookie, origin);
   }
 }
 public int getVersion() {
   return cookie.getVersion();
 }
Пример #7
0
 public InputStream executeRequest(String paramString1, HashMap<String, String> paramHashMap1, HashMap<String, String> paramHashMap2, String paramString2)
   throws FabException
 {
   InputStream localInputStream = null;
   ArrayList localArrayList = new ArrayList();
   Iterator localIterator3;
   if (paramHashMap2 != null)
     localIterator3 = paramHashMap2.keySet().iterator();
   while (true)
   {
     if (!localIterator3.hasNext());
     try
     {
       HttpResponse localHttpResponse = getThreadSafeClient().execute(getDefaultMethod(paramString1, localArrayList, paramString2), getFabHttpContext());
       HttpEntity localHttpEntity = localHttpResponse.getEntity();
       if ((!paramString1.contains("cdn1." + FabEnvironment.baseUrl() + "/")) && ((paramString1.contains("." + FabEnvironment.baseUrl() + "/")) || (paramString1.contains("/" + FabEnvironment.baseUrl() + "/"))))
       {
         List localList = cookieStore.getCookies();
         if (!localList.isEmpty())
         {
           localIterator1 = localList.iterator();
           if (localIterator1.hasNext())
             break label361;
           localStringBuilder = new StringBuilder();
           localIterator2 = fabCookieHash.keySet().iterator();
           if (localIterator2.hasNext())
             break label545;
           FabSharedPrefs.setFabCookies(localStringBuilder.toString());
         }
       }
       localInputStream = localHttpEntity.getContent();
       int i = localHttpResponse.getStatusLine().getStatusCode();
       if ((i < 200) || (i > 207))
         throw new FabException("Unable to contact server" + localHttpResponse.getStatusLine().getReasonPhrase());
     }
     catch (HttpResponseException localHttpResponseException)
     {
       while (true)
       {
         Iterator localIterator1;
         return localInputStream;
         String str2 = (String)localIterator3.next();
         BasicNameValuePair localBasicNameValuePair = new BasicNameValuePair(str2, (String)paramHashMap2.get(str2));
         localArrayList.add(localBasicNameValuePair);
         break;
         Cookie localCookie = (Cookie)localIterator1.next();
         if ((localCookie.getDomain().contains(FabEnvironment.baseDomain())) && (!localCookie.getName().contains("fab_session")))
           fabCookieHash.put(localCookie.getName(), localCookie.getName() + "=" + localCookie.getValue() + "; domain=" + localCookie.getDomain() + "<@@>" + localCookie.getName() + "<##>" + localCookie.getValue() + "<##>" + localCookie.isSecure() + "<##>" + localCookie.getVersion());
       }
     }
     catch (ClientProtocolException localClientProtocolException)
     {
       while (true)
       {
         Iterator localIterator2;
         throw new FabException(localClientProtocolException);
         str1 = (String)localIterator2.next();
         if ((!paramString1.contains("stay-signed-in/?enable=0")) || (!"tla".equalsIgnoreCase(str1)))
           break;
         fabCookieHash.remove(str1);
       }
     }
     catch (IOException localIOException)
     {
       while (true)
       {
         StringBuilder localStringBuilder;
         String str1;
         throw new FabException(localIOException);
         localStringBuilder.append((String)fabCookieHash.get(str1));
         localStringBuilder.append("<==>");
       }
     }
     catch (Exception localException)
     {
       label361: localException.toString();
       label545: throw new FabException(localException);
     }
   }
 }
Пример #8
0
  public boolean login() throws HTTPException {
    LoginParameters loginParameters = new LoginParameters();

    // Check the client cookies.  If 'enwikiUserID', 'enwikiUserName', and 'centralauth_Token' are
    // valid, already logged in.
    List<Cookie> cookies = client.getCookieStore().getCookies();
    int numCookieFound = 0;
    Iterator<Cookie> cookieItr = cookies.iterator();
    while (cookieItr.hasNext()) {
      Cookie cookie = cookieItr.next();
      if (cookie.getName().equalsIgnoreCase("enwikiUserID")) numCookieFound++;
      else if (cookie.getName().equalsIgnoreCase("enwikiUsername")) numCookieFound++;
      else if (cookie.getName().equalsIgnoreCase("centralauth_Token")) numCookieFound++;
      if (numCookieFound == 3) return true;
    }

    // Send the initial login request
    String loginQuery =
        url + "api.php?action=login&lgname=" + username + "&lgpassword="******"&format=xml";
    HttpPost loginRequest = new HttpPost(loginQuery);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody;
    try {
      responseBody = client.execute(loginRequest, responseHandler);
    } catch (ClientProtocolException e) {
      throw new HTTPException("An HTTP protocol error occurred.");
    } catch (IOException e) {
      e.printStackTrace();
      throw new HTTPException("The connection was aborted.");
    }
    loginParameters.setXMLParameters(responseBody);

    // Send the confirm token request
    String confirmTokenQuery =
        url
            + "api.php?action=login&lgname="
            + username
            + "&lgpassword="******"&lgtoken="
            + loginParameters.getToken()
            + "&format=xml";
    HttpPost confirmTokenRequest = new HttpPost(confirmTokenQuery);
    try {
      responseBody = client.execute(confirmTokenRequest, responseHandler);
    } catch (ClientProtocolException e) {
      throw new HTTPException("An HTTP protocol error occurred.");
    } catch (IOException e) {
      throw new HTTPException("The connection was aborted.");
    }
    loginParameters.setXMLParameters(responseBody);

    // Save the cookie information.
    cookies = client.getCookieStore().getCookies();
    cookieItr = cookies.iterator();
    ArrayList<String> cookieInfo = new ArrayList<String>();
    while (cookieItr.hasNext()) {
      Cookie cookie = cookieItr.next();
      if (cookie.isPersistent() && !cookie.isExpired(new Date())) {
        String cookieDetails =
            cookie.getComment()
                + ","
                + cookie.getCommentURL()
                + ","
                + cookie.getDomain()
                + ","
                + cookie.getName()
                + ","
                + cookie.getPath()
                + ","
                + cookie.getValue()
                + ","
                + cookie.getVersion()
                + ","
                + cookie.getExpiryDate().toString();
        cookieInfo.add(cookieDetails);
      }
    }
    addCookiesToFile(cookieInfo);

    return false;
  }