File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
src/AndroidClient/client/src
main/java/net/servicestack/client
test/java/net/servicestack/client/tests Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 55
66import com .google .gson .Gson ;
77import com .google .gson .GsonBuilder ;
8- import com .google .gson .JsonArray ;
98import com .google .gson .JsonElement ;
109import com .google .gson .JsonObject ;
1110
1615import java .io .InputStreamReader ;
1716import java .io .UnsupportedEncodingException ;
1817import java .lang .reflect .Field ;
19- import java .lang .reflect .Modifier ;
2018import java .lang .reflect .Type ;
19+ import java .net .CookieHandler ;
20+ import java .net .CookieManager ;
2121import java .net .HttpURLConnection ;
2222import java .net .URL ;
2323import java .net .URLEncoder ;
2424import java .nio .charset .Charset ;
25- import java .util .ArrayList ;
2625import java .util .Date ;
27- import java .util .Iterator ;
2826import java .util .Map ;
2927import java .util .UUID ;
3028
@@ -50,6 +48,11 @@ public class JsonServiceClient implements ServiceClient {
5048 public JsonServiceClient (String baseUrl ) {
5149 this .baseUrl = baseUrl .endsWith ("/" ) ? baseUrl : baseUrl + "/" ;
5250 this .replyUrl = this .baseUrl + "json/reply/" ;
51+
52+ //Automatically populate response cookies
53+ if (CookieHandler .getDefault () == null ){
54+ CookieHandler .setDefault (new CookieManager ());
55+ }
5356 }
5457
5558 public void setTimeout (int timeoutMs ) {
Original file line number Diff line number Diff line change @@ -52,4 +52,24 @@ public void test_does_transparently_send_BasicAuthHeader_on_401_response(){
5252 assertEquals ("test DisplayName" , response .getDisplayName ());
5353 assertNotNull (response .getSessionId ());
5454 }
55+
56+ public void test_can_authenticate_with_CredentialsAuth (){
57+ ServiceClient client = CreateClient ();
58+
59+ AuthenticateResponse authResponse = client .post (new Authenticate ()
60+ .setProvider ("credentials" )
61+ .setUserName ("test" )
62+ .setPassword ("test" ));
63+
64+ assertEquals ("1" , authResponse .getUserId ());
65+ assertEquals ("test" , authResponse .getUserName ());
66+ assertNotNull (authResponse .getSessionId ());
67+
68+ TestAuthResponse response = client .get (new TestAuth ());
69+
70+ assertEquals ("1" , response .getUserId ());
71+ assertEquals ("test" , response .getUserName ());
72+ assertEquals ("test DisplayName" , response .getDisplayName ());
73+ assertNotNull (response .getSessionId ());
74+ }
5575}
You can’t perform that action at this time.
0 commit comments