Skip to content

Commit afbf491

Browse files
committed
Merge branch 'dev' of github.com:androidquery/androidquery into dev
2 parents 52f9f37 + 4fc38e5 commit afbf491

File tree

5 files changed

+111
-11
lines changed

5 files changed

+111
-11
lines changed

dist/build-full.jardesc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<jardesc>
3-
<jar path="AndroidQuery/dist/android-query-full.0.24.2-beta.jar"/>
3+
<jar path="AndroidQuery/dist/android-query-full.0.25.1-beta.jar"/>
44
<options buildIfNeeded="true" compress="true" descriptionLocation="/AndroidQuery/dist/build-full.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
55
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
66
<selectedProjects/>

dist/build.jardesc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<jardesc>
3-
<jar path="AndroidQuery/dist/android-query.0.23.16.jar"/>
3+
<jar path="AndroidQuery/dist/android-query.0.24.3.jar"/>
44
<options buildIfNeeded="true" compress="true" descriptionLocation="/AndroidQuery/dist/build.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
55
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
66
<selectedProjects/>

src/com/androidquery/callback/AbstractAjaxCallback.java

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.lang.ref.Reference;
2929
import java.lang.ref.WeakReference;
3030
import java.net.HttpURLConnection;
31+
import java.net.MalformedURLException;
3132
import java.net.URL;
3233
import java.util.ArrayList;
3334
import java.util.Date;
@@ -1445,6 +1446,28 @@ private static DefaultHttpClient getClient(){
14451446
return client;
14461447
}
14471448

1449+
//helper method to support underscore subdomain
1450+
private HttpResponse execute(HttpUriRequest hr, DefaultHttpClient client, HttpContext context) throws ClientProtocolException, IOException{
1451+
1452+
HttpResponse response = null;
1453+
1454+
if(hr.getURI().getAuthority().contains("_")) {
1455+
URL urlObj = hr.getURI().toURL();
1456+
HttpHost host;
1457+
if(urlObj.getPort() == -1) {
1458+
host = new HttpHost(urlObj.getHost(), 80, urlObj.getProtocol());
1459+
} else {
1460+
host = new HttpHost(urlObj.getHost(), urlObj.getPort(), urlObj.getProtocol());
1461+
}
1462+
response = client.execute(host, hr, context);
1463+
} else {
1464+
response = client.execute(hr, context);
1465+
}
1466+
1467+
1468+
return response;
1469+
}
1470+
14481471

14491472
private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers, AjaxStatus status) throws ClientProtocolException, IOException{
14501473

@@ -1494,14 +1517,16 @@ private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers,
14941517
HttpResponse response = null;
14951518

14961519
try{
1497-
response = client.execute(hr, context);
1520+
//response = client.execute(hr, context);
1521+
response = execute(hr, client, context);
14981522
}catch(HttpHostConnectException e){
14991523

15001524
//if proxy is used, automatically retry without proxy
15011525
if(proxy != null){
15021526
AQUtility.debug("proxy failed, retrying without proxy");
15031527
hp.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
1504-
response = client.execute(hr, context);
1528+
//response = client.execute(hr, context);
1529+
response = execute(hr, client, context);
15051530
}else{
15061531
throw e;
15071532
}
@@ -1566,11 +1591,12 @@ private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers,
15661591
os = new BufferedOutputStream(new FileOutputStream(file));
15671592
}
15681593

1569-
//AQUtility.time("copy");
1570-
1571-
copy(entity.getContent(), os, getEncoding(entity), (int) entity.getContentLength());
1594+
is = entity.getContent();
1595+
if("gzip".equalsIgnoreCase(getEncoding(entity))){
1596+
is = new GZIPInputStream(is);
1597+
}
15721598

1573-
//AQUtility.timeEnd("copy", 0);
1599+
copy(is, os, (int) entity.getContentLength());
15741600

15751601

15761602
os.flush();
@@ -1612,6 +1638,29 @@ private String getEncoding(HttpEntity entity){
16121638

16131639
}
16141640

1641+
private void copy(InputStream is, OutputStream os, int max) throws IOException{
1642+
1643+
1644+
1645+
Object o = null;
1646+
1647+
if(progress != null){
1648+
o = progress.get();
1649+
}
1650+
1651+
Progress p = null;
1652+
1653+
if(o != null){
1654+
p = new Progress(o);
1655+
}
1656+
1657+
AQUtility.copy(is, os, max, p);
1658+
1659+
1660+
}
1661+
1662+
1663+
/*
16151664
private void copy(InputStream is, OutputStream os, String encoding, int max) throws IOException{
16161665
16171666
if("gzip".equalsIgnoreCase(encoding)){
@@ -1634,7 +1683,7 @@ private void copy(InputStream is, OutputStream os, String encoding, int max) thr
16341683
16351684
16361685
}
1637-
1686+
*/
16381687

16391688
/**
16401689
* Set the authentication type of this request. This method requires API 5+.
@@ -1888,6 +1937,14 @@ private static void writeData(DataOutputStream dos, String name, String filename
18881937
dos.writeBytes(twoHyphens + boundary + lineEnd);
18891938
dos.writeBytes("Content-Disposition: form-data; name=\""+name+"\";"
18901939
+ " filename=\"" + filename + "\"" + lineEnd);
1940+
1941+
1942+
//added to specify type
1943+
dos.writeBytes("Content-Type: application/octet-stream");
1944+
dos.writeBytes(lineEnd);
1945+
dos.writeBytes("Content-Transfer-Encoding: binary");
1946+
dos.writeBytes(lineEnd);
1947+
18911948
dos.writeBytes(lineEnd);
18921949

18931950
AQUtility.copy(is, dos);

src/com/androidquery/util/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
public interface Constants {
2020

2121

22-
public static final String VERSION = "0.24.3";
22+
public static final String VERSION = "0.25.1";
2323

2424
public static final int LAYER_TYPE_SOFTWARE = 1;
2525
public static final int LAYER_TYPE_HARDWARE = 2;

tests/src/com/androidquery/test/AQueryXmlTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ public class AQueryXmlTest extends AbstractTest<AQueryTestActivity> {
3131

3232
private XmlDom xml;
3333

34+
private String url;
35+
private Object result;
36+
private AjaxStatus status;
37+
38+
public void done(String url, Object result, AjaxStatus status){
39+
40+
this.url = url;
41+
this.result = result;
42+
this.status = status;
43+
44+
log("done", result);
45+
46+
assertTrue(AQUtility.isUIThread());
47+
48+
done();
49+
50+
}
51+
3452
public AQueryXmlTest() throws SAXException {
3553
super(AQueryTestActivity.class);
3654

@@ -170,4 +188,29 @@ public void testText3() throws Exception{
170188

171189
}
172190

191+
public void testMalformXml(){
192+
193+
String url = "http://www.bbc.co.uk/nepali/index.xml";
194+
195+
AjaxCallback<XmlDom> cb = new AjaxCallback<XmlDom>(){
196+
@Override
197+
public void callback(String url, XmlDom object, AjaxStatus status) {
198+
done(url, object, status);
199+
}
200+
};
201+
cb.url(url).type(XmlDom.class);
202+
203+
aq.ajax(cb);
204+
205+
waitAsync();
206+
207+
XmlDom xml = (XmlDom) result;
208+
209+
assertNotNull(xml);
210+
211+
AQUtility.debug(xml);
212+
213+
214+
}
215+
173216
}

0 commit comments

Comments
 (0)