|
20 | 20 |
|
21 | 21 | package com.arangodb.internal.velocystream;
|
22 | 22 |
|
23 |
| -import javax.net.ssl.SSLContext; |
24 |
| - |
25 |
| -import org.slf4j.Logger; |
26 |
| -import org.slf4j.LoggerFactory; |
27 |
| - |
28 | 23 | import com.arangodb.ArangoDBException;
|
29 | 24 | import com.arangodb.internal.net.HostHandler;
|
30 | 25 | import com.arangodb.internal.velocystream.internal.AuthenticationRequest;
|
31 |
| -import com.arangodb.internal.velocystream.internal.VstConnectionSync; |
32 | 26 | import com.arangodb.internal.velocystream.internal.Message;
|
| 27 | +import com.arangodb.internal.velocystream.internal.VstConnectionSync; |
33 | 28 | import com.arangodb.util.ArangoSerialization;
|
34 | 29 | import com.arangodb.velocypack.exception.VPackParserException;
|
35 | 30 | import com.arangodb.velocystream.Request;
|
36 | 31 | import com.arangodb.velocystream.Response;
|
| 32 | +import org.slf4j.Logger; |
| 33 | +import org.slf4j.LoggerFactory; |
| 34 | + |
| 35 | +import javax.net.ssl.SSLContext; |
37 | 36 |
|
38 | 37 | /**
|
39 | 38 | * @author Mark Vollmary
|
40 | 39 | *
|
41 | 40 | */
|
42 | 41 | public class VstCommunicationSync extends VstCommunication<Response, VstConnectionSync> {
|
43 | 42 |
|
44 |
| - private static final Logger LOGGER = LoggerFactory.getLogger(VstCommunicationSync.class); |
45 |
| - |
46 |
| - public static class Builder { |
47 |
| - |
48 |
| - private final HostHandler hostHandler; |
49 |
| - private Integer timeout; |
50 |
| - private Long connectionTtl; |
51 |
| - private String user; |
52 |
| - private String password; |
53 |
| - private Boolean useSsl; |
54 |
| - private SSLContext sslContext; |
55 |
| - private Integer chunksize; |
56 |
| - private Integer maxConnections; |
57 |
| - |
58 |
| - public Builder(final HostHandler hostHandler) { |
59 |
| - super(); |
60 |
| - this.hostHandler = hostHandler; |
61 |
| - } |
62 |
| - |
63 |
| - public Builder(final Builder builder) { |
64 |
| - this(builder.hostHandler); |
65 |
| - timeout(builder.timeout).user(builder.user).password(builder.password).useSsl(builder.useSsl) |
66 |
| - .sslContext(builder.sslContext).chunksize(builder.chunksize).maxConnections(builder.maxConnections); |
67 |
| - } |
68 |
| - |
69 |
| - public Builder timeout(final Integer timeout) { |
70 |
| - this.timeout = timeout; |
71 |
| - return this; |
72 |
| - } |
73 |
| - |
74 |
| - public Builder user(final String user) { |
75 |
| - this.user = user; |
76 |
| - return this; |
77 |
| - } |
78 |
| - |
79 |
| - public Builder password(final String password) { |
80 |
| - this.password = password; |
81 |
| - return this; |
82 |
| - } |
83 |
| - |
84 |
| - public Builder useSsl(final Boolean useSsl) { |
85 |
| - this.useSsl = useSsl; |
86 |
| - return this; |
87 |
| - } |
88 |
| - |
89 |
| - public Builder sslContext(final SSLContext sslContext) { |
90 |
| - this.sslContext = sslContext; |
91 |
| - return this; |
92 |
| - } |
93 |
| - |
94 |
| - public Builder chunksize(final Integer chunksize) { |
95 |
| - this.chunksize = chunksize; |
96 |
| - return this; |
97 |
| - } |
98 |
| - |
99 |
| - public Builder maxConnections(final Integer maxConnections) { |
100 |
| - this.maxConnections = maxConnections; |
101 |
| - return this; |
102 |
| - } |
103 |
| - |
104 |
| - public Builder connectionTtl(final Long connectionTtl) { |
105 |
| - this.connectionTtl = connectionTtl; |
106 |
| - return this; |
107 |
| - } |
108 |
| - |
109 |
| - public VstCommunication<Response, VstConnectionSync> build(final ArangoSerialization util) { |
110 |
| - return new VstCommunicationSync(hostHandler, timeout, user, password, useSsl, sslContext, util, chunksize, |
111 |
| - maxConnections, connectionTtl); |
112 |
| - } |
113 |
| - |
114 |
| - } |
115 |
| - |
116 |
| - protected VstCommunicationSync(final HostHandler hostHandler, final Integer timeout, final String user, |
117 |
| - final String password, final Boolean useSsl, final SSLContext sslContext, final ArangoSerialization util, |
118 |
| - final Integer chunksize, final Integer maxConnections, final Long ttl) { |
119 |
| - super(timeout, user, password, useSsl, sslContext, util, chunksize, hostHandler); |
120 |
| - } |
121 |
| - |
122 |
| - @Override |
123 |
| - protected Response execute(final Request request, final VstConnectionSync connection) throws ArangoDBException { |
124 |
| - try { |
125 |
| - final Message requestMessage = createMessage(request); |
126 |
| - final Message responseMessage = send(requestMessage, connection); |
127 |
| - final Response response = createResponse(responseMessage); |
128 |
| - checkError(response); |
129 |
| - return response; |
130 |
| - } catch (final VPackParserException e) { |
131 |
| - throw new ArangoDBException(e); |
132 |
| - } |
133 |
| - } |
134 |
| - |
135 |
| - private Message send(final Message message, final VstConnectionSync connection) throws ArangoDBException { |
136 |
| - if (LOGGER.isDebugEnabled()) { |
137 |
| - LOGGER.debug(String.format("Send Message (id=%s, head=%s, body=%s)", message.getId(), message.getHead(), |
138 |
| - message.getBody() != null ? message.getBody() : "{}")); |
139 |
| - } |
140 |
| - return connection.write(message, buildChunks(message)); |
141 |
| - } |
142 |
| - |
143 |
| - @Override |
144 |
| - protected void authenticate(final VstConnectionSync connection) { |
145 |
| - final Response response = execute( |
146 |
| - new AuthenticationRequest(user, password != null ? password : "", ENCRYPTION_PLAIN), connection); |
147 |
| - checkError(response); |
148 |
| - } |
| 43 | + private static final Logger LOGGER = LoggerFactory.getLogger(VstCommunicationSync.class); |
| 44 | + |
| 45 | + protected VstCommunicationSync(final HostHandler hostHandler, final Integer timeout, final String user, |
| 46 | + final String password, final Boolean useSsl, final SSLContext sslContext, final ArangoSerialization util, |
| 47 | + final Integer chunksize, final Integer maxConnections, final Long ttl) { |
| 48 | + super(timeout, user, password, useSsl, sslContext, util, chunksize, hostHandler); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + protected Response execute(final Request request, final VstConnectionSync connection) throws ArangoDBException { |
| 53 | + try { |
| 54 | + final Message requestMessage = createMessage(request); |
| 55 | + final Message responseMessage = send(requestMessage, connection); |
| 56 | + final Response response = createResponse(responseMessage); |
| 57 | + checkError(response); |
| 58 | + return response; |
| 59 | + } catch (final VPackParserException e) { |
| 60 | + throw new ArangoDBException(e); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + private Message send(final Message message, final VstConnectionSync connection) throws ArangoDBException { |
| 65 | + if (LOGGER.isDebugEnabled()) { |
| 66 | + LOGGER.debug(String.format("Send Message (id=%s, head=%s, body=%s)", message.getId(), message.getHead(), |
| 67 | + message.getBody() != null ? message.getBody() : "{}")); |
| 68 | + } |
| 69 | + return connection.write(message, buildChunks(message)); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + protected void authenticate(final VstConnectionSync connection) { |
| 74 | + String token = "Negotiate YIICyAYGKwYBBQUCoIICvDCCArigDTALBgkqhkiG9xIBAgKiggKlBIICoWCCAp0GCSqGSIb3EgECAgEAboICjDCCAoigAwIBBaEDAgEOogcDBQAgAAAAo4IBkWGCAY0wggGJoAMCAQWhGhsYQlJVRUNLTElOVVguQVJBTkdPREIuQklaoiswKaADAgEBoSIwIBsESFRUUBsYYnJ1ZWNrbGludXguYXJhbmdvZGIuYml6o4IBNzCCATOgAwIBEqEDAgEBooIBJQSCASF4bHwiBfl70XzaMPPeOQRzY63S5PLwslzzxZArabFKF8s67531vAGmyMcjTPNvClIwew63bCMN4xtjJx+7G2oo+AnlQ+rNMBO5eKHJDsVbFo44P3tiz4Z8lGvK/gJuwCaA/25BaNachJT6RlhkS+x/ZsglKU6y0Okbiz42viSyC3mFpJx5gmcK2xMS6CAp6498JXlevR9F3EqQ67xlWIjWKntqPWK+gj4jU85AXD9ylJpOUm9/Wu82sUIUgT3+kg1x26DvD/5SkzqHLRTJvTRMaSglpqoUMcvSKhK0LRBzcqIxneo1egbg74Jvq/Pu/yZJUfkfBrXHuqQTecT2b8kboSuOp+FYc1J0Uw3xRpZu5peLBSfvIvmkj29uNzlalJQ/pIHdMIHaoAMCARKigdIEgc9/TWh3OUUKFBaXABytmHD8rNvUyBbZRYf8UuXsdi1coZUJRGBT0D53hMLLb1XoveJbci9S5L1xzpWbK3YDmMwH0EMwxSgNGPdZfblEXY9/XeKMA54tNJLnZxyWO0hdwNdN839uJd7hISamV6JxBSZjuKYbxW5sahgeBdJZvFxWxp0PFnSAnfX5yQwFn8AGSB0jHRFkgwNwTwfpIoFNsInd3lZXzSABVHqdcpGXD4uixd6yErtNjFjdQvPpo9m0lzypkwDImxA2Dvd1Tb3OF7k="; |
| 75 | +// Request request = new Request(null,null,null); |
| 76 | +// request.putHeaderParam("Authorization", token); |
| 77 | +// request.setType(1000); |
| 78 | + AuthenticationRequest request = new AuthenticationRequest(user, password != null ? password : "", ENCRYPTION_PLAIN); |
| 79 | + final Response response = execute(request, connection); |
| 80 | + checkError(response); |
| 81 | + } |
| 82 | + |
| 83 | + public static class Builder { |
| 84 | + |
| 85 | + private final HostHandler hostHandler; |
| 86 | + private Integer timeout; |
| 87 | + private Long connectionTtl; |
| 88 | + private String user; |
| 89 | + private String password; |
| 90 | + private Boolean useSsl; |
| 91 | + private SSLContext sslContext; |
| 92 | + private Integer chunksize; |
| 93 | + private Integer maxConnections; |
| 94 | + |
| 95 | + public Builder(final HostHandler hostHandler) { |
| 96 | + super(); |
| 97 | + this.hostHandler = hostHandler; |
| 98 | + } |
| 99 | + |
| 100 | + public Builder(final Builder builder) { |
| 101 | + this(builder.hostHandler); |
| 102 | + timeout(builder.timeout).user(builder.user).password(builder.password).useSsl(builder.useSsl) |
| 103 | + .sslContext(builder.sslContext).chunksize(builder.chunksize).maxConnections(builder.maxConnections); |
| 104 | + } |
| 105 | + |
| 106 | + public Builder timeout(final Integer timeout) { |
| 107 | + this.timeout = timeout; |
| 108 | + return this; |
| 109 | + } |
| 110 | + |
| 111 | + public Builder user(final String user) { |
| 112 | + this.user = user; |
| 113 | + return this; |
| 114 | + } |
| 115 | + |
| 116 | + public Builder password(final String password) { |
| 117 | + this.password = password; |
| 118 | + return this; |
| 119 | + } |
| 120 | + |
| 121 | + public Builder useSsl(final Boolean useSsl) { |
| 122 | + this.useSsl = useSsl; |
| 123 | + return this; |
| 124 | + } |
| 125 | + |
| 126 | + public Builder sslContext(final SSLContext sslContext) { |
| 127 | + this.sslContext = sslContext; |
| 128 | + return this; |
| 129 | + } |
| 130 | + |
| 131 | + public Builder chunksize(final Integer chunksize) { |
| 132 | + this.chunksize = chunksize; |
| 133 | + return this; |
| 134 | + } |
| 135 | + |
| 136 | + public Builder maxConnections(final Integer maxConnections) { |
| 137 | + this.maxConnections = maxConnections; |
| 138 | + return this; |
| 139 | + } |
| 140 | + |
| 141 | + public Builder connectionTtl(final Long connectionTtl) { |
| 142 | + this.connectionTtl = connectionTtl; |
| 143 | + return this; |
| 144 | + } |
| 145 | + |
| 146 | + public VstCommunication<Response, VstConnectionSync> build(final ArangoSerialization util) { |
| 147 | + return new VstCommunicationSync(hostHandler, timeout, user, password, useSsl, sslContext, util, chunksize, |
| 148 | + maxConnections, connectionTtl); |
| 149 | + } |
| 150 | + |
| 151 | + } |
149 | 152 |
|
150 | 153 | }
|
0 commit comments