Skip to content
This repository was archived by the owner on Jan 21, 2024. It is now read-only.

Commit 6668c1e

Browse files
committed
Merge pull request #1740 from prb112/master
Updates for API Management Support
2 parents bcaea00 + 2728d84 commit 6668c1e

File tree

1 file changed

+64
-17
lines changed

1 file changed

+64
-17
lines changed

sdk/com.ibm.sbt.core/src/main/java/com/ibm/sbt/services/endpoints/AbstractEndpoint.java

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,39 @@ public abstract class AbstractEndpoint implements Endpoint, Cloneable {
9090
protected static final String PLATFORM_SAMETIME = "sametime";
9191
protected static final String PLATFORM_DROPBOX = "dropbox";
9292
protected static final String PLATFORM_TWITTER = "twitter";
93+
94+
//Adds support for the API Management feature
95+
private static final String HEADER_APIM_SESSION_ID = "apim-session-id";
96+
private String apiSessionId = "";
9397

9498
public AbstractEndpoint() {
9599
}
100+
101+
/**
102+
* sets the api session id
103+
*/
104+
public void setSessionId(String sessionId){
105+
this.apiSessionId = sessionId;
106+
}
107+
108+
/**
109+
* gets the session id for the given endpoint and the user
110+
* @return {String} the session id for the given user
111+
*/
112+
public String getSessionId(){
113+
return apiSessionId;
114+
}
115+
/**
116+
* checks for a given api-session-id on a response, and updates the endpoint with the given id.
117+
* @return {Response} the Response from the API call, and updates the Endpoint
118+
*/
119+
public Response processSessionId(Response response){
120+
String val = response.getResponseHeader(HEADER_APIM_SESSION_ID);
121+
if(val != null){
122+
this.setSessionId(val);
123+
}
124+
return response;
125+
}
96126

97127
/* (non-Javadoc)
98128
* @see com.ibm.sbt.services.endpoints.Endpoint#setListener(com.ibm.sbt.services.client.ClientServiceListener)
@@ -420,7 +450,8 @@ public void setHttpProxy(String httpProxy) {
420450
@Override
421451
public Response xhr(String method, ClientService.Args args, Object content) throws ClientServicesException {
422452
ClientService srv = getClientService();
423-
return srv.xhr(method,args,content);
453+
Response res = srv.xhr(method,args,content);
454+
return processSessionId(res);
424455
}
425456
@Override
426457
public ClientService getClientService() throws ClientServicesException {
@@ -457,70 +488,86 @@ public ClientService getClientService() throws ClientServicesException {
457488

458489
@Override
459490
public Response xhrGet(String serviceUrl) throws ClientServicesException {
460-
return getClientService().get(serviceUrl);
491+
Response res = getClientService().get(serviceUrl);
492+
return processSessionId(res);
461493
}
462494
@Override
463495
public Response xhrGet(String serviceUrl, Map<String, String> parameters) throws ClientServicesException {
464-
return getClientService().get(serviceUrl, parameters);
496+
Response res = getClientService().get(serviceUrl, parameters);
497+
return processSessionId(res);
465498
}
466499
@Override
467500
public Response xhrGet(String serviceUrl, Map<String, String> parameters, Handler format) throws ClientServicesException {
468-
return getClientService().get(serviceUrl, parameters, format);
501+
Response res = getClientService().get(serviceUrl, parameters, format);
502+
return processSessionId(res);
469503
}
470504
@Override
471505
public Response xhrGet(Args args) throws ClientServicesException {
472-
return getClientService().get(args);
506+
Response res = getClientService().get(args);
507+
return processSessionId(res);
473508
}
474509

475510
@Override
476511
public Response xhrPost(String serviceUrl, Object content) throws ClientServicesException {
477-
return getClientService().post(serviceUrl, content);
512+
Response res = getClientService().post(serviceUrl, content);
513+
return processSessionId(res);
478514
}
479515
@Override
480516
public Response xhrPost(String serviceUrl, Map<String, String> parameters, Object content) throws ClientServicesException {
481-
return getClientService().post(serviceUrl, parameters, content);
517+
Response res = getClientService().post(serviceUrl, parameters, content);
518+
return processSessionId(res);
482519
}
483520
@Override
484521
public Response xhrPost(String serviceUrl, Map<String, String> parameters, Object content, Handler format) throws ClientServicesException {
485-
return getClientService().post(serviceUrl, parameters, content, format);
522+
Response res = getClientService().post(serviceUrl, parameters, content, format);
523+
return processSessionId(res);
486524
}
487525
@Override
488526
public Response xhrPost(Args args, Object content) throws ClientServicesException {
489-
return getClientService().post(args, content);
527+
Response res = getClientService().post(args, content);
528+
return processSessionId(res);
490529
}
491530

492531
@Override
493532
public Response xhrPut(String serviceUrl, Object content) throws ClientServicesException {
494-
return getClientService().put(serviceUrl, content);
533+
Response res = getClientService().put(serviceUrl, content);
534+
return processSessionId(res);
495535
}
496536
@Override
497537
public Response xhrPut(String serviceUrl, Map<String, String> parameters, Object content) throws ClientServicesException {
498-
return getClientService().put(serviceUrl, parameters, content);
538+
Response res = getClientService().put(serviceUrl, parameters, content);
539+
return processSessionId(res);
499540
}
500541
@Override
501542
public Response xhrPut(String serviceUrl, Map<String, String> parameters, Object content, Handler format) throws ClientServicesException {
502-
return getClientService().put(serviceUrl, parameters, content, format);
543+
Response res = getClientService().put(serviceUrl, parameters, content, format);
544+
return processSessionId(res);
503545
}
504546
@Override
505547
public Response xhrPut(Args args, Object content) throws ClientServicesException {
506-
return getClientService().put(args, content);
548+
Response res = getClientService().put(args, content);
549+
return processSessionId(res);
507550
}
508551

509552
@Override
510553
public Response xhrDelete(String serviceUrl) throws ClientServicesException {
511-
return getClientService().delete(serviceUrl);
554+
Response res = getClientService().delete(serviceUrl);
555+
return processSessionId(res);
512556
}
513557
@Override
514558
public Response xhrDelete(String serviceUrl, Map<String, String> parameters) throws ClientServicesException {
515-
return getClientService().delete(serviceUrl, parameters);
559+
Response res = getClientService().delete(serviceUrl, parameters);
560+
return processSessionId(res);
516561
}
517562
@Override
518563
public Response xhrDelete(String serviceUrl, Map<String, String> parameters, Handler format) throws ClientServicesException {
519-
return getClientService().delete(serviceUrl, parameters, format);
564+
Response res = getClientService().delete(serviceUrl, parameters, format);
565+
return processSessionId(res);
520566
}
521567
@Override
522568
public Response xhrDelete(Args args) throws ClientServicesException {
523-
return getClientService().delete(args);
569+
Response res = getClientService().delete(args);
570+
return processSessionId(res);
524571
}
525572
@Override
526573
public String getProxyQueryArgs() {

0 commit comments

Comments
 (0)