I Implemented sample retrofit 2 response via GET type, where I click button to get the response, but I have Failure response
public interface GithubServise {
@GET("/users/waadalkatheri/repos")
Call<ResponseBody> getGithub();
}
public void loadData (View view){
String LINK = "https://api.github.com";
Retrofit retrofit = new Retrofit.Builder ().baseUrl (LINK).build ();
GithubServise githubServise= retrofit.create (GithubServise.class);
githubServise.getGithub ().enqueue (new Callback<ResponseBody> () {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
textView.setText (response.body ().string ());
Log.v ("TAG","yes");
} catch (IOException e) {
e.printStackTrace ();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
textView.setText ("no data");
}
});
}
Stacktrace
06-25 10:13:00.870 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: javax.net.ssl.SSLHandshakeException:
javax.net.ssl.SSLProtocolException: SSL handshake aborted:
ssl=0xb95dcb40: Failure in SSL library, usually a protocol error 06-25
10:13:00.874 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1
alert protocol version (external/openssl/ssl/s23_clnt.c:741
0x9dc27d4d:0x00000000) 06-25 10:13:00.886
2249-2249/com.example.waadalkatheri.retrofittraning W/System.err:
at
org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:436)
at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:302)
06-25 10:13:00.898 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:270)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:162)
06-25 10:13:00.902 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
06-25 10:13:00.910 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
06-25 10:13:00.926 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
06-25 10:13:00.930 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
06-25 10:13:00.934 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
06-25 10:13:00.938 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147) 06-25 10:13:00.942 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 06-25
10:13:00.946 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856) 06-25 10:13:00.950 2249-2249/com.example.waadalkatheri.retrofittraning W/System.err:
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted:
ssl=0xb95dcb40: Failure in SSL library, usually a protocol error 06-25
10:13:00.958 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1
alert protocol version (external/openssl/ssl/s23_clnt.c:741
0x9dc27d4d:0x00000000)
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native
Method) 06-25 10:13:00.962
2249-2249/com.example.waadalkatheri.retrofittraning W/System.err:
at
org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:395)
... 23 more 06-25 10:13:00.974 2249-2249/com.example.waadalkatheri.retrofittraning V/TAG: no data
06-25 10:13:00.978 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: javax.net.ssl.SSLHandshakeException:
javax.net.ssl.SSLProtocolException: SSL handshake aborted:
ssl=0xb95fea28: Failure in SSL library, usually a protocol error 06-25
10:13:00.986 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1
alert protocol version (external/openssl/ssl/s23_clnt.c:741
0x9dc27d4d:0x00000000) 06-25 10:13:01.002
2249-2249/com.example.waadalkatheri.retrofittraning W/System.err:
at
org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:436)
at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:302)
06-25 10:13:01.006 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:270)
06-25 10:13:01.010 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.RealConnection.connect(RealConnection.java:162)
06-25 10:13:01.014 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
06-25 10:13:01.018 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 06-25 10:13:01.022 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
06-25 10:13:01.026 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147) 06-25 10:13:01.030 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb95fea28: Failure in SSL library, usually a protocol
error
error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version (external/openssl/ssl/s23_clnt.c:741
0x9dc27d4d:0x00000000)
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native
Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:395)
06-25 10:13:01.034 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: ... 23 more 06-25 10:13:02.586
2249-2249/com.example.waadalkatheri.retrofittraning V/TAG: no data
06-25 10:13:02.586 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: javax.net.ssl.SSLHandshakeException:
javax.net.ssl.SSLProtocolException: SSL handshake aborted:
ssl=0xb95dcb40: Failure in SSL library, usually a protocol error 06-25
10:13:02.590 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1
alert protocol version (external/openssl/ssl/s23_clnt.c:741
0x9dc27d4d:0x00000000) 06-25 10:13:02.594
2249-2249/com.example.waadalkatheri.retrofittraning W/System.err:
at
org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:436)
06-25 10:13:02.598 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:302)
06-25 10:13:02.602 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:270)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:162)
06-25 10:13:02.606 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
06-25 10:13:02.610 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
06-25 10:13:02.614 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 06-25 10:13:02.618 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
06-25 10:13:02.622 2249-2249/com.example.waadalkatheri.retrofittraning
W/System.err: at
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856) 06-25 10:13:02.626 2249-2249/com.example.waadalkatheri.retrofittraning W/System.err:
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted:
ssl=0xb95dcb40: Failure in SSL library, usually a protocol error
error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version (external/openssl/ssl/s23_clnt.c:741
0x9dc27d4d:0x00000000)
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native
Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:395)
... 23 more
As seen here, your api https://api.github.com supports only TLS 1.2
. Your test device might have an android version 16+ and TLS 1.2
is supported in API level 16+, but are not enabled by default.For 20+ devices it is enabled by default. So for 16<device<20
create a custom SSLSocketFactory
with TLS 1.2
enabled like below
TLSSocketFactory.java
public class TLSSocketFactory extends SSLSocketFactory {
private SSLSocketFactory delegate;
public TLSSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
delegate = context.getSocketFactory();
}
@Override
public String[] getDefaultCipherSuites() {
return delegate.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return delegate.getSupportedCipherSuites();
}
@Override
public Socket createSocket() throws IOException {
return enableTLSOnSocket(delegate.createSocket());
}
@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
return enableTLSOnSocket(delegate.createSocket(s, host, port, autoClose));
}
@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
return enableTLSOnSocket(delegate.createSocket(host, port));
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
return enableTLSOnSocket(delegate.createSocket(host, port, localHost, localPort));
}
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return enableTLSOnSocket(delegate.createSocket(host, port));
}
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
return enableTLSOnSocket(delegate.createSocket(address, port, localAddress, localPort));
}
private Socket enableTLSOnSocket(Socket socket) {
if(socket != null && (socket instanceof SSLSocket)) {
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.2"});
}
return socket;
}
}
Now create an OkHttpClient
and add the client
to retrofit like this
public void loadData (View view){
OkHttpClient client=new OkHttpClient();
try {
client = new OkHttpClient.Builder()
.sslSocketFactory(new TLSSocketFactory())
.build();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
String LINK = "https://api.github.com";
Retrofit retrofit = new Retrofit.Builder ().client(client).baseUrl (LINK).build ();
GithubServise githubServise= retrofit.create (GithubServise.class);
githubServise.getGithub ().enqueue (new Callback<ResponseBody> () {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
textView.setText (response.body ().string ());
Log.v ("TAG","yes");
} catch (IOException e) {
e.printStackTrace ();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
textView.setText ("no data");
}
});
}
When onFailure gets called it means that the error was in the networking. So something in the conection is not working, maybe you have already checked these things..
Make sure you have internet conection and the url is correct by doing the same http request from your browser on your mobile (Chrome).
Check that in the manifest you have asked for the Internet permission:
uses-permission android:name="android.permission.INTERNET"
Try this code make pojo class for response ..
public class Owner{
@SerializedName("gists_url")
private String gistsUrl;
@SerializedName("repos_url")
private String reposUrl;
@SerializedName("following_url")
private String followingUrl;
@SerializedName("starred_url")
private String starredUrl;
@SerializedName("login")
private String login;
@SerializedName("followers_url")
private String followersUrl;
@SerializedName("type")
private String type;
@SerializedName("url")
private String url;
@SerializedName("subscriptions_url")
private String subscriptionsUrl;
@SerializedName("received_events_url")
private String receivedEventsUrl;
@SerializedName("avatar_url")
private String avatarUrl;
@SerializedName("events_url")
private String eventsUrl;
@SerializedName("html_url")
private String htmlUrl;
@SerializedName("site_admin")
private boolean siteAdmin;
@SerializedName("id")
private int id;
@SerializedName("gravatar_id")
private String gravatarId;
@SerializedName("node_id")
private String nodeId;
@SerializedName("organizations_url")
private String organizationsUrl;
public void setGistsUrl(String gistsUrl){
this.gistsUrl = gistsUrl;
}
public String getGistsUrl(){
return gistsUrl;
}
public void setReposUrl(String reposUrl){
this.reposUrl = reposUrl;
}
public String getReposUrl(){
return reposUrl;
}
public void setFollowingUrl(String followingUrl){
this.followingUrl = followingUrl;
}
public String getFollowingUrl(){
return followingUrl;
}
public void setStarredUrl(String starredUrl){
this.starredUrl = starredUrl;
}
public String getStarredUrl(){
return starredUrl;
}
public void setLogin(String login){
this.login = login;
}
public String getLogin(){
return login;
}
public void setFollowersUrl(String followersUrl){
this.followersUrl = followersUrl;
}
public String getFollowersUrl(){
return followersUrl;
}
public void setType(String type){
this.type = type;
}
public String getType(){
return type;
}
public void setUrl(String url){
this.url = url;
}
public String getUrl(){
return url;
}
public void setSubscriptionsUrl(String subscriptionsUrl){
this.subscriptionsUrl = subscriptionsUrl;
}
public String getSubscriptionsUrl(){
return subscriptionsUrl;
}
public void setReceivedEventsUrl(String receivedEventsUrl){
this.receivedEventsUrl = receivedEventsUrl;
}
public String getReceivedEventsUrl(){
return receivedEventsUrl;
}
public void setAvatarUrl(String avatarUrl){
this.avatarUrl = avatarUrl;
}
public String getAvatarUrl(){
return avatarUrl;
}
public void setEventsUrl(String eventsUrl){
this.eventsUrl = eventsUrl;
}
public String getEventsUrl(){
return eventsUrl;
}
public void setHtmlUrl(String htmlUrl){
this.htmlUrl = htmlUrl;
}
public String getHtmlUrl(){
return htmlUrl;
}
public void setSiteAdmin(boolean siteAdmin){
this.siteAdmin = siteAdmin;
}
public boolean isSiteAdmin(){
return siteAdmin;
}
public void setId(int id){
this.id = id;
}
public int getId(){
return id;
}
public void setGravatarId(String gravatarId){
this.gravatarId = gravatarId;
}
public String getGravatarId(){
return gravatarId;
}
public void setNodeId(String nodeId){
this.nodeId = nodeId;
}
public String getNodeId(){
return nodeId;
}
public void setOrganizationsUrl(String organizationsUrl){
this.organizationsUrl = organizationsUrl;
}
public String getOrganizationsUrl(){
return organizationsUrl;
}
}
public class Response{
@SerializedName("stargazers_count")
private int stargazersCount;
@SerializedName("pushed_at")
private String pushedAt;
@SerializedName("subscription_url")
private String subscriptionUrl;
@SerializedName("language")
private String language;
@SerializedName("branches_url")
private String branchesUrl;
@SerializedName("issue_comment_url")
private String issueCommentUrl;
@SerializedName("labels_url")
private String labelsUrl;
@SerializedName("subscribers_url")
private String subscribersUrl;
@SerializedName("releases_url")
private String releasesUrl;
@SerializedName("svn_url")
private String svnUrl;
@SerializedName("id")
private int id;
@SerializedName("forks")
private int forks;
@SerializedName("archive_url")
private String archiveUrl;
@SerializedName("git_refs_url")
private String gitRefsUrl;
@SerializedName("forks_url")
private String forksUrl;
@SerializedName("statuses_url")
private String statusesUrl;
@SerializedName("ssh_url")
private String sshUrl;
@SerializedName("license")
private Object license;
@SerializedName("full_name")
private String fullName;
@SerializedName("size")
private int size;
@SerializedName("languages_url")
private String languagesUrl;
@SerializedName("html_url")
private String htmlUrl;
@SerializedName("collaborators_url")
private String collaboratorsUrl;
@SerializedName("clone_url")
private String cloneUrl;
@SerializedName("name")
private String name;
@SerializedName("pulls_url")
private String pullsUrl;
@SerializedName("default_branch")
private String defaultBranch;
@SerializedName("hooks_url")
private String hooksUrl;
@SerializedName("trees_url")
private String treesUrl;
@SerializedName("tags_url")
private String tagsUrl;
@SerializedName("private")
private boolean jsonMemberPrivate;
@SerializedName("contributors_url")
private String contributorsUrl;
@SerializedName("has_downloads")
private boolean hasDownloads;
@SerializedName("notifications_url")
private String notificationsUrl;
@SerializedName("open_issues_count")
private int openIssuesCount;
@SerializedName("description")
private Object description;
@SerializedName("created_at")
private String createdAt;
@SerializedName("watchers")
private int watchers;
@SerializedName("keys_url")
private String keysUrl;
@SerializedName("deployments_url")
private String deploymentsUrl;
@SerializedName("has_projects")
private boolean hasProjects;
@SerializedName("archived")
private boolean archived;
@SerializedName("has_wiki")
private boolean hasWiki;
@SerializedName("updated_at")
private String updatedAt;
@SerializedName("comments_url")
private String commentsUrl;
@SerializedName("stargazers_url")
private String stargazersUrl;
@SerializedName("git_url")
private String gitUrl;
@SerializedName("has_pages")
private boolean hasPages;
@SerializedName("owner")
private Owner owner;
@SerializedName("commits_url")
private String commitsUrl;
@SerializedName("compare_url")
private String compareUrl;
@SerializedName("git_commits_url")
private String gitCommitsUrl;
@SerializedName("blobs_url")
private String blobsUrl;
@SerializedName("git_tags_url")
private String gitTagsUrl;
@SerializedName("merges_url")
private String mergesUrl;
@SerializedName("downloads_url")
private String downloadsUrl;
@SerializedName("has_issues")
private boolean hasIssues;
@SerializedName("url")
private String url;
@SerializedName("contents_url")
private String contentsUrl;
@SerializedName("mirror_url")
private Object mirrorUrl;
@SerializedName("milestones_url")
private String milestonesUrl;
@SerializedName("teams_url")
private String teamsUrl;
@SerializedName("fork")
private boolean fork;
@SerializedName("issues_url")
private String issuesUrl;
@SerializedName("events_url")
private String eventsUrl;
@SerializedName("issue_events_url")
private String issueEventsUrl;
@SerializedName("assignees_url")
private String assigneesUrl;
@SerializedName("open_issues")
private int openIssues;
@SerializedName("watchers_count")
private int watchersCount;
@SerializedName("node_id")
private String nodeId;
@SerializedName("homepage")
private Object homepage;
@SerializedName("forks_count")
private int forksCount;
public void setStargazersCount(int stargazersCount){
this.stargazersCount = stargazersCount;
}
public int getStargazersCount(){
return stargazersCount;
}
public void setPushedAt(String pushedAt){
this.pushedAt = pushedAt;
}
public String getPushedAt(){
return pushedAt;
}
public void setSubscriptionUrl(String subscriptionUrl){
this.subscriptionUrl = subscriptionUrl;
}
public String getSubscriptionUrl(){
return subscriptionUrl;
}
public void setLanguage(String language){
this.language = language;
}
public String getLanguage(){
return language;
}
public void setBranchesUrl(String branchesUrl){
this.branchesUrl = branchesUrl;
}
public String getBranchesUrl(){
return branchesUrl;
}
public void setIssueCommentUrl(String issueCommentUrl){
this.issueCommentUrl = issueCommentUrl;
}
public String getIssueCommentUrl(){
return issueCommentUrl;
}
public void setLabelsUrl(String labelsUrl){
this.labelsUrl = labelsUrl;
}
public String getLabelsUrl(){
return labelsUrl;
}
public void setSubscribersUrl(String subscribersUrl){
this.subscribersUrl = subscribersUrl;
}
public String getSubscribersUrl(){
return subscribersUrl;
}
public void setReleasesUrl(String releasesUrl){
this.releasesUrl = releasesUrl;
}
public String getReleasesUrl(){
return releasesUrl;
}
public void setSvnUrl(String svnUrl){
this.svnUrl = svnUrl;
}
public String getSvnUrl(){
return svnUrl;
}
public void setId(int id){
this.id = id;
}
public int getId(){
return id;
}
public void setForks(int forks){
this.forks = forks;
}
public int getForks(){
return forks;
}
public void setArchiveUrl(String archiveUrl){
this.archiveUrl = archiveUrl;
}
public String getArchiveUrl(){
return archiveUrl;
}
public void setGitRefsUrl(String gitRefsUrl){
this.gitRefsUrl = gitRefsUrl;
}
public String getGitRefsUrl(){
return gitRefsUrl;
}
public void setForksUrl(String forksUrl){
this.forksUrl = forksUrl;
}
public String getForksUrl(){
return forksUrl;
}
public void setStatusesUrl(String statusesUrl){
this.statusesUrl = statusesUrl;
}
public String getStatusesUrl(){
return statusesUrl;
}
public void setSshUrl(String sshUrl){
this.sshUrl = sshUrl;
}
public String getSshUrl(){
return sshUrl;
}
public void setLicense(Object license){
this.license = license;
}
public Object getLicense(){
return license;
}
public void setFullName(String fullName){
this.fullName = fullName;
}
public String getFullName(){
return fullName;
}
public void setSize(int size){
this.size = size;
}
public int getSize(){
return size;
}
public void setLanguagesUrl(String languagesUrl){
this.languagesUrl = languagesUrl;
}
public String getLanguagesUrl(){
return languagesUrl;
}
public void setHtmlUrl(String htmlUrl){
this.htmlUrl = htmlUrl;
}
public String getHtmlUrl(){
return htmlUrl;
}
public void setCollaboratorsUrl(String collaboratorsUrl){
this.collaboratorsUrl = collaboratorsUrl;
}
public String getCollaboratorsUrl(){
return collaboratorsUrl;
}
public void setCloneUrl(String cloneUrl){
this.cloneUrl = cloneUrl;
}
public String getCloneUrl(){
return cloneUrl;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setPullsUrl(String pullsUrl){
this.pullsUrl = pullsUrl;
}
public String getPullsUrl(){
return pullsUrl;
}
public void setDefaultBranch(String defaultBranch){
this.defaultBranch = defaultBranch;
}
public String getDefaultBranch(){
return defaultBranch;
}
public void setHooksUrl(String hooksUrl){
this.hooksUrl = hooksUrl;
}
public String getHooksUrl(){
return hooksUrl;
}
public void setTreesUrl(String treesUrl){
this.treesUrl = treesUrl;
}
public String getTreesUrl(){
return treesUrl;
}
public void setTagsUrl(String tagsUrl){
this.tagsUrl = tagsUrl;
}
public String getTagsUrl(){
return tagsUrl;
}
public void setJsonMemberPrivate(boolean jsonMemberPrivate){
this.jsonMemberPrivate = jsonMemberPrivate;
}
public boolean isJsonMemberPrivate(){
return jsonMemberPrivate;
}
public void setContributorsUrl(String contributorsUrl){
this.contributorsUrl = contributorsUrl;
}
public String getContributorsUrl(){
return contributorsUrl;
}
public void setHasDownloads(boolean hasDownloads){
this.hasDownloads = hasDownloads;
}
public boolean isHasDownloads(){
return hasDownloads;
}
public void setNotificationsUrl(String notificationsUrl){
this.notificationsUrl = notificationsUrl;
}
public String getNotificationsUrl(){
return notificationsUrl;
}
public void setOpenIssuesCount(int openIssuesCount){
this.openIssuesCount = openIssuesCount;
}
public int getOpenIssuesCount(){
return openIssuesCount;
}
public void setDescription(Object description){
this.description = description;
}
public Object getDescription(){
return description;
}
public void setCreatedAt(String createdAt){
this.createdAt = createdAt;
}
public String getCreatedAt(){
return createdAt;
}
public void setWatchers(int watchers){
this.watchers = watchers;
}
public int getWatchers(){
return watchers;
}
public void setKeysUrl(String keysUrl){
this.keysUrl = keysUrl;
}
public String getKeysUrl(){
return keysUrl;
}
public void setDeploymentsUrl(String deploymentsUrl){
this.deploymentsUrl = deploymentsUrl;
}
public String getDeploymentsUrl(){
return deploymentsUrl;
}
public void setHasProjects(boolean hasProjects){
this.hasProjects = hasProjects;
}
public boolean isHasProjects(){
return hasProjects;
}
public void setArchived(boolean archived){
this.archived = archived;
}
public boolean isArchived(){
return archived;
}
public void setHasWiki(boolean hasWiki){
this.hasWiki = hasWiki;
}
public boolean isHasWiki(){
return hasWiki;
}
public void setUpdatedAt(String updatedAt){
this.updatedAt = updatedAt;
}
public String getUpdatedAt(){
return updatedAt;
}
public void setCommentsUrl(String commentsUrl){
this.commentsUrl = commentsUrl;
}
public String getCommentsUrl(){
return commentsUrl;
}
public void setStargazersUrl(String stargazersUrl){
this.stargazersUrl = stargazersUrl;
}
public String getStargazersUrl(){
return stargazersUrl;
}
public void setGitUrl(String gitUrl){
this.gitUrl = gitUrl;
}
public String getGitUrl(){
return gitUrl;
}
public void setHasPages(boolean hasPages){
this.hasPages = hasPages;
}
public boolean isHasPages(){
return hasPages;
}
public void setOwner(Owner owner){
this.owner = owner;
}
public Owner getOwner(){
return owner;
}
public void setCommitsUrl(String commitsUrl){
this.commitsUrl = commitsUrl;
}
public String getCommitsUrl(){
return commitsUrl;
}
public void setCompareUrl(String compareUrl){
this.compareUrl = compareUrl;
}
public String getCompareUrl(){
return compareUrl;
}
public void setGitCommitsUrl(String gitCommitsUrl){
this.gitCommitsUrl = gitCommitsUrl;
}
public String getGitCommitsUrl(){
return gitCommitsUrl;
}
public void setBlobsUrl(String blobsUrl){
this.blobsUrl = blobsUrl;
}
public String getBlobsUrl(){
return blobsUrl;
}
public void setGitTagsUrl(String gitTagsUrl){
this.gitTagsUrl = gitTagsUrl;
}
public String getGitTagsUrl(){
return gitTagsUrl;
}
public void setMergesUrl(String mergesUrl){
this.mergesUrl = mergesUrl;
}
public String getMergesUrl(){
return mergesUrl;
}
public void setDownloadsUrl(String downloadsUrl){
this.downloadsUrl = downloadsUrl;
}
public String getDownloadsUrl(){
return downloadsUrl;
}
public void setHasIssues(boolean hasIssues){
this.hasIssues = hasIssues;
}
public boolean isHasIssues(){
return hasIssues;
}
public void setUrl(String url){
this.url = url;
}
public String getUrl(){
return url;
}
public void setContentsUrl(String contentsUrl){
this.contentsUrl = contentsUrl;
}
public String getContentsUrl(){
return contentsUrl;
}
public void setMirrorUrl(Object mirrorUrl){
this.mirrorUrl = mirrorUrl;
}
public Object getMirrorUrl(){
return mirrorUrl;
}
public void setMilestonesUrl(String milestonesUrl){
this.milestonesUrl = milestonesUrl;
}
public String getMilestonesUrl(){
return milestonesUrl;
}
public void setTeamsUrl(String teamsUrl){
this.teamsUrl = teamsUrl;
}
public String getTeamsUrl(){
return teamsUrl;
}
public void setFork(boolean fork){
this.fork = fork;
}
public boolean isFork(){
return fork;
}
public void setIssuesUrl(String issuesUrl){
this.issuesUrl = issuesUrl;
}
public String getIssuesUrl(){
return issuesUrl;
}
public void setEventsUrl(String eventsUrl){
this.eventsUrl = eventsUrl;
}
public String getEventsUrl(){
return eventsUrl;
}
public void setIssueEventsUrl(String issueEventsUrl){
this.issueEventsUrl = issueEventsUrl;
}
public String getIssueEventsUrl(){
return issueEventsUrl;
}
public void setAssigneesUrl(String assigneesUrl){
this.assigneesUrl = assigneesUrl;
}
public String getAssigneesUrl(){
return assigneesUrl;
}
public void setOpenIssues(int openIssues){
this.openIssues = openIssues;
}
public int getOpenIssues(){
return openIssues;
}
public void setWatchersCount(int watchersCount){
this.watchersCount = watchersCount;
}
public int getWatchersCount(){
return watchersCount;
}
public void setNodeId(String nodeId){
this.nodeId = nodeId;
}
public String getNodeId(){
return nodeId;
}
public void setHomepage(Object homepage){
this.homepage = homepage;
}
public Object getHomepage(){
return homepage;
}
public void setForksCount(int forksCount){
this.forksCount = forksCount;
}
public int getForksCount(){
return forksCount;
}
}
after that make retrofit object class..
public class ApiClient {
private final static String BASE_URL = "https://api.github.com";
public static ApiClient apiClient;
private Retrofit retrofit = null;
public static ApiClient getInstance() {
if (apiClient == null) {
apiClient = new ApiClient();
}
return apiClient;
}
//private static Retrofit storeRetrofit = null;
public Retrofit getClient() {
return getClient(null);
}
private Retrofit getClient(final Context context) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.readTimeout(60, TimeUnit.SECONDS);
client.writeTimeout(60, TimeUnit.SECONDS);
client.connectTimeout(60, TimeUnit.SECONDS);
client.addInterceptor(interceptor);
client.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
return chain.proceed(request);
}
});
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit;
}
}
after that make interface for api calling..
public interface ApiInterface {
@GET("/users/waadalkatheri/repos")
Call<Response> getdata();
}
after that api calling into activity and getting data..
ApiInterface apiInterface= ApiClient.getInstance().getClient().create(ApiInterface.class);
Call<Response> responseCall=apiInterface.getdata();
responseCall.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
if (response.isSuccessful() && response.body()!=null && response!=null){
Toast.makeText(getApplicationContext(),"GetData"+response.body().getLanguage(),Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Response> call, Throwable t) {
Log.d("Errror",t.getMessage());
}
});