Skip to content

Commit dce0044

Browse files
author
ehennum
committed
expose getCookies() in implementation but not public interface #973
1 parent e77b2be commit dce0044

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/SessionState.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
*/
1616
package com.marklogic.client;
1717

18-
import com.marklogic.client.impl.ClientCookie;
19-
20-
import java.util.List;
21-
18+
/**
19+
* Identifies a server state for sharing across multiple calls to server endpoints.
20+
*
21+
* Internally, the identifier is sent to the server as a session cookie.
22+
* The session cookie can be used for load balancing.
23+
*/
2224
public interface SessionState {
25+
/**
26+
* Provides the identifier used for the server state (for instance, for use in logging).
27+
* @return the session identifier
28+
*/
2329
public String getSessionId();
24-
List<ClientCookie> getCookies();
2530
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5414,7 +5414,7 @@ public void writeTo(BufferedSink sink) throws IOException {
54145414
}
54155415

54165416
public class CallRequestImpl implements CallRequest {
5417-
private SessionState session;
5417+
private SessionStateImpl session;
54185418
private Request.Builder requestBldr;
54195419
private RequestBody requestBody;
54205420
private boolean hasStreamingPart;
@@ -5423,9 +5423,12 @@ public class CallRequestImpl implements CallRequest {
54235423
private HttpUrl callBaseUri;
54245424

54255425
CallRequestImpl(String endpoint, HttpMethod method, SessionState session) {
5426+
if (session != null && !(session instanceof SessionStateImpl)) {
5427+
throw new IllegalArgumentException("Session state must be implemented by internal class: "+session.getClass().getName());
5428+
}
54265429
this.endpoint = endpoint;
54275430
this.method = method;
5428-
this.session = session;
5431+
this.session = (SessionStateImpl) session;
54295432
this.hasStreamingPart = false;
54305433
this.callBaseUri = new HttpUrl.Builder()
54315434
.scheme(baseUri.scheme())
@@ -5484,8 +5487,8 @@ public HttpMethod getHttpMethod() {
54845487
private void prepareRequestBuilder() {
54855488
this.requestBldr = setupRequest(callBaseUri, endpoint, null);
54865489
if (session != null) {
5487-
Calendar expiration = ((SessionStateImpl) session).getCreatedTimestamp() != null ?
5488-
(Calendar) ((SessionStateImpl) session).getCreatedTimestamp().clone() : null;
5490+
Calendar expiration = session.getCreatedTimestamp() != null ?
5491+
(Calendar) session.getCreatedTimestamp().clone() : null;
54895492
this.requestBldr = addCookies(this.requestBldr, session.getCookies(), expiration);
54905493
// Add the Cookie header for SessionId if we have a session object passed
54915494
this.requestBldr.addHeader(HEADER_COOKIE, "SessionID="+session.getSessionId());

marklogic-client-api/src/main/java/com/marklogic/client/impl/SessionStateImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ public String getSessionId() {
4040
return sessionId;
4141
}
4242

43-
@Override
44-
public List<ClientCookie> getCookies() {
43+
List<ClientCookie> getCookies() {
4544
return cookies;
4645
}
4746

48-
public void setCookies(List<ClientCookie> cookies) {
47+
void setCookies(List<ClientCookie> cookies) {
4948
if ( cookies != null ) {
5049
if(setCreatedTimestamp.compareAndSet(false, true)) {
5150
created = Calendar.getInstance();
@@ -61,7 +60,7 @@ public void setCookies(List<ClientCookie> cookies) {
6160
}
6261
}
6362

64-
public Calendar getCreatedTimestamp() {
63+
Calendar getCreatedTimestamp() {
6564
return created;
6665
}
6766
}

0 commit comments

Comments
 (0)