-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8 added PoC QuickSearch.jspa calling.
Only jql like inputs are handled. Wanted to use OkHttp library by retrofit, but there is nasty unresolved for few months bug square/okhttp#184 which doesn't work very well when some parts (e.g. analytics library in that case) doesn't use him. Fixed bug with calling quicksearch two times when using hardware keyboard ENTER button (key down and key up). Extracted AuthorizationHeaderGenerator because it's used also with this QuerySearch call.
- Loading branch information
Showing
5 changed files
with
77 additions
and
16 deletions.
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
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
42 changes: 42 additions & 0 deletions
42
src/main/java/com/tadamski/arij/issue/list/drawer/QuerySearch.java
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.tadamski.arij.issue.list.drawer; | ||
|
||
import android.net.Uri; | ||
|
||
import com.tadamski.arij.account.service.LoginInfo; | ||
import com.tadamski.arij.util.retrofit.AuthorizationHeaderGenerator; | ||
|
||
import java.io.DataOutputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.net.URLEncoder; | ||
|
||
/** | ||
* Created by tmszdmsk on 31.07.13. | ||
*/ | ||
public class QuerySearch { | ||
private AuthorizationHeaderGenerator authorizationHeaderGenerator = new AuthorizationHeaderGenerator(); | ||
|
||
public String getJql(String query, LoginInfo loginInfo) { | ||
try { | ||
HttpURLConnection connection = (HttpURLConnection) new URL(loginInfo.getBaseURL() + "/secure/QuickSearch.jspa").openConnection(); | ||
String content = "searchString=" + URLEncoder.encode(query, "UTF-8"); | ||
connection.setRequestMethod("POST"); | ||
connection.setRequestProperty("Authorization", authorizationHeaderGenerator.getValue(loginInfo)); | ||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | ||
connection.setInstanceFollowRedirects(false); | ||
connection.setDoOutput(true); | ||
connection.setDoInput(true); | ||
DataOutputStream out = new DataOutputStream(connection.getOutputStream()); | ||
|
||
out.writeBytes(content); | ||
out.flush(); | ||
out.close(); | ||
String location = connection.getHeaderField("Location"); | ||
Uri uri = Uri.parse(location); | ||
String jql = uri.getQueryParameter("jql"); | ||
return jql; | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/tadamski/arij/util/retrofit/AuthorizationHeaderGenerator.java
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.tadamski.arij.util.retrofit; | ||
|
||
import android.util.Base64; | ||
|
||
import com.tadamski.arij.account.service.LoginInfo; | ||
|
||
/** | ||
* Created by tmszdmsk on 31.07.13. | ||
*/ | ||
public class AuthorizationHeaderGenerator { | ||
public String getValue(LoginInfo credentials) { | ||
byte[] toEncode = (credentials.getUsername() + ":" + credentials.getPassword()).getBytes(); | ||
return "Basic " + Base64.encodeToString(toEncode, Base64.NO_WRAP); | ||
} | ||
} |
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