Skip to content

Commit 57b74db

Browse files
committed
#82 - first cut, including http context resolution. tests work locally (except date ones and some log line finding - quite normal)
1 parent 5af0a27 commit 57b74db

File tree

80 files changed

+1934
-813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1934
-813
lines changed

baseline/baseline-app/src/main/java/com/betfair/cougar/baseline/BaselineServiceImpl.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@
7070
import com.betfair.cougar.core.api.events.EventTransportIdentity;
7171
import com.betfair.cougar.core.api.exception.CougarServiceException;
7272
import com.betfair.cougar.core.api.exception.ServerFaultCode;
73-
import com.betfair.cougar.core.api.transcription.SetBuilder;
73+
import com.betfair.cougar.core.api.builder.SetBuilder;
7474
import com.betfair.cougar.core.impl.ev.ConnectedResponseImpl;
7575
import com.betfair.cougar.core.impl.ev.DefaultSubscription;
7676
import com.betfair.cougar.core.impl.logging.AbstractLoggingControl;
77-
import com.betfair.cougar.core.impl.logging.Log4jLoggingControl;
7877
import com.betfair.cougar.core.impl.security.SSLAwareTokenResolver;
7978
import org.apache.log4j.Level;
8079
import org.slf4j.Logger;
@@ -813,7 +812,7 @@ public void onResult(ExecutionResult executionResult) {
813812
LOGGER.info("Bulk calls complete");
814813
try { latch.await(); } catch (InterruptedException e) {}
815814
long timeTaken = System.nanoTime() - startTime;
816-
LOGGER.info("All Latches returned in %,d ms", timeTaken/1000000);
815+
LOGGER.info("All Latches returned in %,d ms", timeTaken / 1000000);
817816
return timeTaken;
818817
}
819818

@@ -834,7 +833,7 @@ public SimpleResponse changeLogLevel(RequestContext ctx, String logName,
834833
}
835834

836835
LOGGER.warn("A warning message");
837-
LOGGER.info( "A warning message");
836+
LOGGER.info("A warning message");
838837

839838
return response;
840839
}

baseline/baseline-security/src/main/java/com/betfair/cougar/baseline/security/GeneralIdentityResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.betfair.cougar.baseline.security;
1818

19-
import com.betfair.cougar.api.ExecutionContextWithTokens;
19+
import com.betfair.cougar.api.DehydratedExecutionContext;
2020
import com.betfair.cougar.api.security.*;
2121

2222
import java.security.Principal;
@@ -26,7 +26,7 @@
2626
public class GeneralIdentityResolver implements IdentityResolver {
2727

2828
@Override
29-
public void resolve(IdentityChain chain, ExecutionContextWithTokens ctx) throws InvalidCredentialsException {
29+
public void resolve(IdentityChain chain, DehydratedExecutionContext ctx) throws InvalidCredentialsException {
3030
if (ctx.getIdentityTokens() != null && ctx.getIdentityTokens().size() > 0) {
3131
for (final IdentityToken tk: ctx.getIdentityTokens()) {
3232
String tokenValue = tk.getValue();

cougar-codegen-plugin/src/main/resources/templates/dataTypeBuilder.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.betfair.cougar.api.Validatable;
3838
import com.betfair.cougar.core.api.transcription.*;
3939
import com.betfair.cougar.core.api.ServiceVersion;
4040
import com.betfair.cougar.core.api.transcription.EnumUtils;
41+
import com.betfair.cougar.core.api.builder.*;
4142
import com.betfair.cougar.util.ValidationUtils;
4243
import ${package}.${majorVersion}.enumerations.*;
4344

cougar-framework/cougar-api/src/main/java/com/betfair/cougar/api/ExecutionContextWithTokens.java cougar-framework/cougar-api/src/main/java/com/betfair/cougar/api/DehydratedExecutionContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
*
2626
*/
27-
public interface ExecutionContextWithTokens extends ExecutionContext {
27+
public interface DehydratedExecutionContext extends ExecutionContext {
2828

2929
List<IdentityToken> getIdentityTokens();
3030

cougar-framework/cougar-api/src/main/java/com/betfair/cougar/api/export/Protocol.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,32 @@
1717
package com.betfair.cougar.api.export;
1818

1919
public enum Protocol {
20-
RESCRIPT,
21-
SOAP,
22-
JMS(false),
23-
JSON_RPC,
20+
RESCRIPT(ProtocolParadigm.Rpc),
21+
SOAP(ProtocolParadigm.Rpc),
22+
JMS(false, ProtocolParadigm.Event),
23+
JSON_RPC(ProtocolParadigm.Rpc),
2424
EPN(false),
25-
SOCKET(false);
25+
SOCKET(false, ProtocolParadigm.Rpc, ProtocolParadigm.Push),
26+
IN_PROCESS(false, ProtocolParadigm.Rpc, ProtocolParadigm.Push, ProtocolParadigm.Event);
27+
private Class bodyClass;
2628

27-
Protocol() {
28-
this(true);
29+
Protocol(ProtocolParadigm... paradigms) {
30+
this(true, paradigms);
2931
}
3032

31-
Protocol(boolean httpIsUnderlyingTransport) {
33+
Protocol(boolean httpIsUnderlyingTransport, ProtocolParadigm... paradigms) {
34+
this.paradigms = paradigms;
3235
this.httpIsUnderlyingTransport = httpIsUnderlyingTransport;
3336
}
3437

35-
private boolean httpIsUnderlyingTransport = true;
38+
private final ProtocolParadigm[] paradigms;
39+
private final boolean httpIsUnderlyingTransport;
3640

3741
public boolean underlyingTransportIsHttp() {
3842
return httpIsUnderlyingTransport;
3943
}
44+
45+
public ProtocolParadigm[] getParadigms() {
46+
return paradigms;
47+
}
4048
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.betfair.cougar.api.export;
2+
3+
/**
4+
*/
5+
public enum ProtocolParadigm {
6+
Rpc,
7+
Push,
8+
Event
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.betfair.cougar.api.export;
2+
3+
import java.util.HashMap;
4+
import java.util.HashSet;
5+
import java.util.Map;
6+
import java.util.Set;
7+
8+
/**
9+
* Registry of protocols.
10+
*/
11+
public class ProtocolRegistry {
12+
13+
private static Map<ProtocolParadigm, Set<Protocol>> protocolsByParadigm = new HashMap<>();
14+
private static Set<Protocol> protocols = new HashSet<>();
15+
16+
// todo: (#83)
17+
static
18+
{
19+
for (Protocol p : Protocol.values()) {
20+
registerProtocol(p);
21+
}
22+
}
23+
24+
public static void registerProtocol(Protocol p) {
25+
protocols.add(p);
26+
for (ProtocolParadigm pp : p.getParadigms()) {
27+
Set<Protocol> protocols = protocolsByParadigm.get(pp);
28+
if (protocols == null) {
29+
protocols = new HashSet<>();
30+
protocolsByParadigm.put(pp, protocols);
31+
}
32+
protocols.add(p);
33+
}
34+
}
35+
36+
public static Set<Protocol> protocols(ProtocolParadigm paradigm) {
37+
return protocolsByParadigm.get(paradigm);
38+
}
39+
}

cougar-framework/cougar-api/src/main/java/com/betfair/cougar/api/security/IdentityResolver.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
package com.betfair.cougar.api.security;
1818

19-
import com.betfair.cougar.api.ExecutionContextWithTokens;
19+
import com.betfair.cougar.api.DehydratedExecutionContext;
2020

2121
import java.util.List;
2222

2323
/**
2424
* The IdentityResolver resolves a set of credentials into an IdentityChain.
25-
*
25+
*
2626
* @see IdentityChain
2727
*
2828
*/
@@ -35,7 +35,7 @@ public interface IdentityResolver {
3535
* @param ctx the execution context resolved so far including identity tokens resolved by the {@link IdentityTokenResolver} (IdentityChain on this context will be null).
3636
* @throws InvalidCredentialsException
3737
*/
38-
public void resolve(IdentityChain chain, ExecutionContextWithTokens ctx) throws InvalidCredentialsException;
38+
public void resolve(IdentityChain chain, DehydratedExecutionContext ctx) throws InvalidCredentialsException;
3939

4040
/**
4141
* Given an identity chain, resolve back into a set of writable tokens

cougar-framework/cougar-core-api/src/main/java/com/betfair/cougar/core/api/GateRegisterer.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323
* instances with a given {@link CougarStartingGate}. Use these to save listeners having to
2424
* register themselves programmatically.
2525
* <p>
26-
* You can control ordering of listeners in Spring config by having different registerers
26+
* You can control ordering of listeners in Spring config by having different registerers
2727
* {@code depend-on} each other.
2828
* <p>
2929
* TODO think of a better name than 'registererererer'
3030
*/
3131
public class GateRegisterer {
3232

3333
/**
34-
* Construct with one or more listeners.
34+
* Construct with one or more listeners.
3535
* <p>
36-
* <strong>A note on wiring</strong>: you can pass a constructor-arg with a {@code list} of
36+
* <strong>A note on wiring</strong>: you can pass a constructor-arg with a {@code list} of
3737
* listeners, or a single listener, but you can't init with a (comma-separated) array.
38-
*
38+
*
3939
* @param gate
4040
* @param listeners listeners to register with the gate (see note about wiring, above)
4141
*/
4242
public GateRegisterer(CougarStartingGate gate, GateListener... listeners) {
43-
43+
4444
Assert.notEmpty(listeners, "GateRegisterer has no listeners.");
45-
Assert.notNull(gate, "GateRegister has not had a CougarStartingGate set.");
46-
45+
Assert.notNull(gate, "GateRegisterer has not had a CougarStartingGate set.");
46+
4747
for (GateListener listener : listeners) {
4848
gate.registerStartingListener(listener);
4949
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.betfair.cougar.core.api.builder;
2+
3+
import com.betfair.cougar.api.RequestUUID;
4+
import com.betfair.cougar.api.geolocation.GeoLocationDetails;
5+
6+
import java.util.BitSet;
7+
import java.util.Date;
8+
import java.util.List;
9+
10+
/**
11+
* Base utils for building ExecutionContexts
12+
*/
13+
public abstract class BaseExecutionContextBuilder<T extends BaseExecutionContextBuilder> {
14+
15+
private BitSet whatsSet = new BitSet(MAX_BASE_BITS+getNumSpecificComponents());
16+
17+
protected GeoLocationDetails location;
18+
protected RequestUUID uuid;
19+
protected Date receivedTime;
20+
protected Date requestTime;
21+
protected boolean traceLoggingEnabled;
22+
protected int transportSecurityStrengthFactor;
23+
24+
protected abstract int getNumSpecificComponents();
25+
protected final static int MAX_BASE_BITS = 6;
26+
27+
public T setLocation(GeoLocationDetails location) {
28+
this.location = location;
29+
set(0);
30+
return (T) this;
31+
}
32+
33+
public T setRequestUUID(RequestUUID uuid) {
34+
this.uuid = uuid;
35+
set(1);
36+
return (T) this;
37+
}
38+
39+
public T setReceivedTime(Date receivedTime) {
40+
this.receivedTime = receivedTime;
41+
set(2);
42+
return (T) this;
43+
}
44+
45+
public T setRequestTime(Date requestTime) {
46+
this.requestTime = requestTime;
47+
set(3);
48+
return (T) this;
49+
}
50+
51+
public T setTraceLoggingEnabled(boolean traceLoggingEnabled) {
52+
this.traceLoggingEnabled = traceLoggingEnabled;
53+
set(4);
54+
return (T) this;
55+
}
56+
57+
public T setTransportSecurityStrengthFactor(int factor) {
58+
transportSecurityStrengthFactor = factor;
59+
set(5);
60+
return (T) this;
61+
}
62+
63+
protected void beenSet(int subComponent) {
64+
set(MAX_BASE_BITS + subComponent);
65+
}
66+
67+
private void set(int bit) {
68+
if (whatsSet.get(bit)) {
69+
throw new IllegalStateException("Component has already been set");
70+
}
71+
whatsSet.set(bit);
72+
}
73+
74+
protected void checkReady() {
75+
if (whatsSet.nextClearBit(0) <= getNumSpecificComponents()) {
76+
throw new IllegalStateException("Not all components have been set on this execution context");
77+
}
78+
}
79+
80+
public Date getRequestTime() {
81+
return requestTime;
82+
}
83+
84+
public Object getRequestUUID() {
85+
return uuid;
86+
}
87+
}

cougar-framework/cougar-core-api/src/main/java/com/betfair/cougar/core/api/transcription/Builder.java cougar-framework/cougar-core-api/src/main/java/com/betfair/cougar/core/api/builder/Builder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.betfair.cougar.core.api.transcription;
17+
package com.betfair.cougar.core.api.builder;
1818

1919
/**
2020
* Defines a class which can build other classes. Used to construct bound data types using the builder pattern.

0 commit comments

Comments
 (0)