-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-19163] Android: Removal of Apache HTTP Client #7036
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a4cc011
[TIMOB-19163] Android: Implemented HttpURLConnection for Android M to…
0d576d8
[TIMOB-19163] Added usage of java Cookies and other changes
96ead66
[TIMOB-19163] Code formatting changes and updated HTTPClient and Cook…
50b5b94
[TIMOB-19163] Changed HTTPClient in TiDrawableReference and TiLocatio…
68e8b1b
[TIMOB-19163] Android: Removed Apache thirdparty jar lib and source code
67b12c0
[TIMOB-19163] Android: Removed Apache from build
df280ad
[TIMOB-19163] Android: Removed Apache references
39e9b45
[TIMOB-19163] Android: Regression TIMOB-17575 - NPE searching for Res…
49cfde8
Merge branch 'master' of https://github.com/appcelerator/titanium_mob…
b2cb935
[TIMOB-19163] Android: Regression TIMOB-15380 - Fixed location not up…
4a86a06
Merge branch 'master' of https://github.com/appcelerator/titanium_mob…
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,10 @@ | |
|
||
package ti.modules.titanium.network; | ||
|
||
import java.net.HttpCookie; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
|
||
import org.apache.http.cookie.Cookie; | ||
import org.apache.http.impl.cookie.BasicClientCookie; | ||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.kroll.KrollProxy; | ||
import org.appcelerator.kroll.annotations.Kroll; | ||
|
@@ -41,29 +39,28 @@ public class CookieProxy extends KrollProxy | |
systemExpiryDateFormatter.setTimeZone(timezone); | ||
} | ||
|
||
private BasicClientCookie basicClientCookie; | ||
private HttpCookie httpCookie; | ||
|
||
public CookieProxy() | ||
{ | ||
super(); | ||
} | ||
|
||
public CookieProxy(Cookie cookie) | ||
public CookieProxy(HttpCookie cookie) | ||
{ | ||
super(); | ||
if (cookie instanceof BasicClientCookie) { | ||
basicClientCookie = (BasicClientCookie) cookie; | ||
setProperty(TiC.PROPERTY_NAME, basicClientCookie.getName()); | ||
setProperty(TiC.PROPERTY_VALUE, basicClientCookie.getValue()); | ||
setProperty(TiC.PROPERTY_DOMAIN, basicClientCookie.getDomain()); | ||
Date expiryDate = basicClientCookie.getExpiryDate(); | ||
if (expiryDate != null) { | ||
setProperty(TiC.PROPERTY_EXPIRY_DATE, httpExpiryDateFormatter.format(expiryDate)); | ||
} | ||
setProperty(TiC.PROPERTY_COMMENT, basicClientCookie.getComment()); | ||
setProperty(TiC.PROPERTY_PATH, basicClientCookie.getPath()); | ||
setProperty(TiC.PROPERTY_SECURE, basicClientCookie.isSecure()); | ||
setProperty(TiC.PROPERTY_VERSION, basicClientCookie.getVersion()); | ||
if (cookie instanceof HttpCookie) { | ||
httpCookie = (HttpCookie) cookie; | ||
setProperty(TiC.PROPERTY_NAME, httpCookie.getName()); | ||
setProperty(TiC.PROPERTY_VALUE, httpCookie.getValue()); | ||
setProperty(TiC.PROPERTY_DOMAIN, httpCookie.getDomain()); | ||
// PROPERTY_EXPIRY_DATE not used instead, PROPERTY_MAX_AGE is used | ||
// See http://developer.android.com/reference/java/net/HttpCookie.html for more info | ||
setProperty(TiC.PROPERTY_MAX_AGE, httpCookie.getMaxAge()); | ||
setProperty(TiC.PROPERTY_COMMENT, httpCookie.getComment()); | ||
setProperty(TiC.PROPERTY_PATH, httpCookie.getPath()); | ||
setProperty(TiC.PROPERTY_SECURE, httpCookie.getSecure()); | ||
setProperty(TiC.PROPERTY_VERSION, httpCookie.getVersion()); | ||
} else { | ||
Log.e(TAG, "Unable to create CookieProxy. Invalid cookie type."); | ||
} | ||
|
@@ -95,70 +92,65 @@ public void handleCreationDict(KrollDict dict) | |
String name = TiConvert.toString(getProperty(TiC.PROPERTY_NAME)); | ||
String value = TiConvert.toString(getProperty(TiC.PROPERTY_VALUE)); | ||
if (name != null) { | ||
this.basicClientCookie = new BasicClientCookie(name, value); | ||
this.httpCookie = new HttpCookie(name, value); | ||
} else { | ||
Log.w(TAG, "Unable to create the http client cookie. Need to provide a valid name."); | ||
return; | ||
} | ||
|
||
if (dict.containsKey(TiC.PROPERTY_DOMAIN)) { | ||
basicClientCookie.setDomain(TiConvert.toString(getProperty(TiC.PROPERTY_DOMAIN))); | ||
} | ||
if (dict.containsKey(TiC.PROPERTY_EXPIRY_DATE)) { | ||
try { | ||
basicClientCookie.setExpiryDate(httpExpiryDateFormatter.parse(TiConvert | ||
.toString(getProperty(TiC.PROPERTY_EXPIRY_DATE)))); | ||
} catch (Exception e) { | ||
Log.e(TAG, "Unable to set expiry date to the cookie.", e); | ||
} | ||
httpCookie.setDomain(TiConvert.toString(getProperty(TiC.PROPERTY_DOMAIN))); | ||
} | ||
if (dict.containsKey(TiC.PROPERTY_MAX_AGE)) { | ||
// PROPERTY_EXPIRY_DATE not used instead, PROPERTY_MAX_AGE is used | ||
// See http://developer.android.com/reference/java/net/HttpCookie.html for more info | ||
httpCookie.setMaxAge(TiConvert.toInt(getProperty(TiC.PROPERTY_MAX_AGE))); | ||
} | ||
if (dict.containsKey(TiC.PROPERTY_COMMENT)) { | ||
basicClientCookie.setComment(TiConvert.toString(getProperty(TiC.PROPERTY_COMMENT))); | ||
httpCookie.setComment(TiConvert.toString(getProperty(TiC.PROPERTY_COMMENT))); | ||
} | ||
if (dict.containsKey(TiC.PROPERTY_PATH)) { | ||
basicClientCookie.setPath(TiConvert.toString(getProperty(TiC.PROPERTY_PATH))); | ||
httpCookie.setPath(TiConvert.toString(getProperty(TiC.PROPERTY_PATH))); | ||
} | ||
if (dict.containsKey(TiC.PROPERTY_SECURE)) { | ||
basicClientCookie.setSecure(TiConvert.toBoolean(getProperty(TiC.PROPERTY_SECURE))); | ||
httpCookie.setSecure(TiConvert.toBoolean(getProperty(TiC.PROPERTY_SECURE))); | ||
} | ||
if (dict.containsKey(TiC.PROPERTY_VERSION)) { | ||
basicClientCookie.setVersion(TiConvert.toInt(getProperty(TiC.PROPERTY_VERSION))); | ||
httpCookie.setVersion(TiConvert.toInt(getProperty(TiC.PROPERTY_VERSION))); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPropertyChanged(String name, Object value) | ||
{ | ||
if (basicClientCookie == null) { | ||
if (httpCookie == null) { | ||
return; | ||
} | ||
|
||
super.onPropertyChanged(name, value); | ||
|
||
if (TiC.PROPERTY_VALUE.equals(name)) { | ||
basicClientCookie.setValue(TiConvert.toString(value)); | ||
httpCookie.setValue(TiConvert.toString(value)); | ||
} else if (TiC.PROPERTY_DOMAIN.equals(name)) { | ||
basicClientCookie.setDomain(TiConvert.toString(value)); | ||
} else if (TiC.PROPERTY_EXPIRY_DATE.equals(name)) { | ||
try { | ||
basicClientCookie.setExpiryDate(httpExpiryDateFormatter.parse(TiConvert.toString(value))); | ||
} catch (Exception e) { | ||
Log.e(TAG, "Unable to set expiry date to the cookie.", e); | ||
} | ||
httpCookie.setDomain(TiConvert.toString(value)); | ||
} else if (TiC.PROPERTY_MAX_AGE.equals(name)) { | ||
// PROPERTY_EXPIRY_DATE not used instead, PROPERTY_MAX_AGE is used | ||
// See http://developer.android.com/reference/java/net/HttpCookie.html for more info | ||
httpCookie.setMaxAge(TiConvert.toInt(value)); | ||
} else if (TiC.PROPERTY_COMMENT.equals(name)) { | ||
basicClientCookie.setComment(TiConvert.toString(value)); | ||
httpCookie.setComment(TiConvert.toString(value)); | ||
} else if (TiC.PROPERTY_PATH.equals(name)) { | ||
basicClientCookie.setPath(TiConvert.toString(value)); | ||
httpCookie.setPath(TiConvert.toString(value)); | ||
} else if (TiC.PROPERTY_SECURE.equals(name)) { | ||
basicClientCookie.setSecure(TiConvert.toBoolean(value)); | ||
httpCookie.setSecure(TiConvert.toBoolean(value)); | ||
} else if (TiC.PROPERTY_VERSION.equals(name)) { | ||
basicClientCookie.setVersion(TiConvert.toInt(value)); | ||
httpCookie.setVersion(TiConvert.toInt(value)); | ||
} | ||
} | ||
|
||
public BasicClientCookie getHTTPCookie() | ||
public HttpCookie getHTTPCookie() | ||
{ | ||
return basicClientCookie; | ||
return httpCookie; | ||
} | ||
|
||
@Kroll.getProperty @Kroll.method | ||
|
@@ -170,6 +162,6 @@ public String getName() | |
@Override | ||
public String getApiName() | ||
{ | ||
return "Ti.Network.Cookie"; | ||
return "Ti.Network.CookieProxy"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason for this change? A typo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A Typo. A very bad typo. Thanks for catching this. |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you modify the doc for this replacement property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will modify the docs.