Skip to content

Commit b95c5b0

Browse files
committed
Add cookie test in Android App
1 parent ed529a5 commit b95c5b0

File tree

3 files changed

+633
-2
lines changed

3 files changed

+633
-2
lines changed

src/AndroidClient/app/src/main/java/servicestack/net/androidclient/MainActivity.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
import android.view.ViewGroup;
3131
import android.widget.TextView;
3232

33+
import net.servicestack.android.AndroidServiceClient;
34+
import net.servicestack.client.AsyncSuccess;
35+
import net.servicestack.client.Log;
36+
3337
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
3438

3539
/**
@@ -175,6 +179,37 @@ public void onClick(View view) {
175179
}
176180
});
177181

182+
rootView.findViewById(R.id.btn_test_cookie)
183+
.setOnClickListener(new View.OnClickListener() {
184+
@Override
185+
public void onClick(View view) {
186+
// final AndroidServiceClient client = new AndroidServiceClient("http://validation.web-app.io", getContext());
187+
final AndroidServiceClient client = new AndroidServiceClient("http://validation.web-app.io");
188+
client.postAsync(new validationdtos.Authenticate()
189+
.setProvider("credentials")
190+
.setUserName("admin@email.com")
191+
.setPassword("p@55wOrd")
192+
, new AsyncSuccess<validationdtos.AuthenticateResponse>() {
193+
@Override
194+
public void success(validationdtos.AuthenticateResponse response) {
195+
try {
196+
client.setTokenCookie(response.getBearerToken());
197+
} catch (Exception e) {
198+
Log.e(e);
199+
}
200+
client.getAsync(new validationdtos.GetContacts(), new AsyncSuccess<validationdtos.GetContactsResponse>() {
201+
@Override
202+
public void success(validationdtos.GetContactsResponse response) {
203+
for (validationdtos.Contact contact : response.results) {
204+
Log.d("CONTACT: " + contact.name);
205+
}
206+
}
207+
});
208+
}
209+
});
210+
}
211+
});
212+
178213
return rootView;
179214
}
180215
}

0 commit comments

Comments
 (0)