Package com.betfair.cougar.api

Examples of com.betfair.cougar.api.ExecutionContextWithTokens


        return registry.keySet();
    }

    private ExecutionContext resolveIdentitiesIfRequired(final ExecutionContext ctx) {
        if (ctx instanceof ExecutionContextWithTokens) {
            ExecutionContextWithTokens contextWithTokens = (ExecutionContextWithTokens) ctx;
            if (identityResolver == null) {
                contextWithTokens.setIdentityChain(new IdentityChainImpl(new ArrayList<Identity>()));
                // if there's no identity resolver then it can't tokenise any tokens back to the transport..
                contextWithTokens.getIdentityTokens().clear();
                return contextWithTokens;
            }
            else {
                IdentityChain chain = new IdentityChainImpl();
                try {
                    identityResolver.resolve(chain, contextWithTokens);
                }
                catch (InvalidCredentialsException e) {
                    if (e.getCredentialFaultCode() != null) { // Check if a custom error code should be used
                        ServerFaultCode sfc = ServerFaultCode.getByCredentialFaultCode(e.getCredentialFaultCode());
                        throw new CougarFrameworkException(sfc, "Credentials supplied were invalid", e);
                    }
                    throw new CougarFrameworkException(ServerFaultCode.SecurityException, "Credentials supplied were invalid", e);
                }
                // ensure the identity chain set in the context is immutable
                contextWithTokens.setIdentityChain(new IdentityChainImpl(chain.getIdentities()));
                contextWithTokens.getIdentityTokens().clear();
                List<IdentityToken> tokens = identityResolver.tokenise(contextWithTokens.getIdentity());
                if (tokens != null) {
                    contextWithTokens.getIdentityTokens().addAll(tokens);
                }
                return contextWithTokens;
            }
        }
        // might not be in the case of a client, or a batched transport which will have executed a seperate command to resolve identities for e.g.
View Full Code Here


        return false;
  }

  @Override
  protected CommandResolver<HttpCommand> createCommandResolver(final HttpCommand http) {
        final ExecutionContextWithTokens context = resolveExecutionContext(http, http.getRequest(), http.getClientX509CertificateChain(), true);


    final List<JsonRpcRequest> requests = new ArrayList<JsonRpcRequest>();
    final List<ExecutionCommand> commands = new ArrayList<ExecutionCommand>();
    final List<JsonRpcResponse> responses = new ArrayList<JsonRpcResponse>();

    JsonNode root;
    ByteCountingInputStream iStream = null;
    try {
      iStream = createByteCountingInputStream(http.getRequest().getInputStream());
            try {
                EnumUtils.setHardFailureForThisThread(hardFailEnumDeserialisation);
                root = mapper.readTree(iStream);
                final long bytesRead = iStream.getCount();
                final boolean isBatch = root.isArray();
                if (isBatch) {
                    requests.addAll((List<JsonRpcRequest>)mapper.convertValue(root, BATCH_REQUEST_TYPE));
                } else {
                    JsonRpcRequest rpc = mapper.convertValue(root, SINGLE_REQUEST_TYPE);
                    requests.add(rpc);
                }

                if (requests.isEmpty()) {
                    writeErrorResponse(http, context, new CougarValidationException(ServerFaultCode.NoRequestsFound, "No Requests found in rpc call"));
                } else {
                    final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(context.getRequestTime(), readRawTimeConstraints(http.getRequest()));
                    for (final JsonRpcRequest rpc : requests) {
                        final JsonRpcOperationBinding binding = bindings.get(stripMinorVersionFromUri(rpc.getMethod().toLowerCase()));
                        if (binding!=null) {
                            try {
                                JsonRpcParam [] paramDefs = binding.getJsonRpcParams();
View Full Code Here

  }

    @Override
    public void process(HttpCommand command) {
        incrementCommandsProcessed();
        ExecutionContextWithTokens ctx = null;
        try {
            validateCommand(command);
            final CommandResolver<HttpCommand> resolver = createCommandResolver(command);
            ctx = resolver.resolveExecutionContext();

            final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(ctx.getRequestTime(), readRawTimeConstraints(command.getRequest()));
            final ExecutionContextWithTokens finalCtx = ctx;
            ExecutionCommand resolveCommand = new ExecutionCommand() {
                @Override
                public OperationKey getOperationKey() {
                    return IDENTITY_RESOLUTION_OPDEF.getOperationKey();
                }

                @Override
                public Object[] getArgs() {
                    return new Object[0];
                }

                @Override
                public void onResult(ExecutionResult executionResult) {
                    Iterable<ExecutionCommand> batchCalls = resolver.resolveExecutionCommands();
                    if (executionResult.isFault()) {
                        for (ExecutionCommand exec : batchCalls) {
                            exec.onResult(executionResult);
                        }
                    }
                    // now we have an ExecutionContext that's correctly filled..
                    else {
                        // this has to be an ExecutionContext and not a ExecutionContextWithTokens to ensure that
                        // BaseExecutionVenue doesn't try to re-resolve
                        ExecutionContext context = ExecutionContextFactory.resolveExecutionContext(finalCtx, finalCtx.getIdentity());
                        for (ExecutionCommand exec : resolver.resolveExecutionCommands()) {
                            executeCommand(exec, context);
                        }
                    }
                }
View Full Code Here

        return registry.keySet();
    }

    private ExecutionContext resolveIdentitiesIfRequired(final ExecutionContext ctx) {
        if (ctx instanceof ExecutionContextWithTokens) {
            ExecutionContextWithTokens contextWithTokens = (ExecutionContextWithTokens) ctx;
            if (identityResolver == null) {
                contextWithTokens.setIdentityChain(new IdentityChainImpl(new ArrayList<Identity>()));
                // if there's no identity resolver then it can't tokenise any tokens back to the transport..
                contextWithTokens.getIdentityTokens().clear();
                return contextWithTokens;
            }
            else {
                IdentityChain chain = new IdentityChainImpl();
                try {
                    identityResolver.resolve(chain, contextWithTokens);
                }
                catch (InvalidCredentialsException e) {
                    if (e.getCredentialFaultCode() != null) { // Check if a custom error code should be used
                        ServerFaultCode sfc = ServerFaultCode.getByCredentialFaultCode(e.getCredentialFaultCode());
                        throw new CougarServiceException(sfc, "Credentials supplied were invalid", e);
                    }
                    throw new CougarServiceException(ServerFaultCode.SecurityException, "Credentials supplied were invalid", e);
                }
                // ensure the identity chain set in the context is immutable
                contextWithTokens.setIdentityChain(new IdentityChainImpl(chain.getIdentities()));
                contextWithTokens.getIdentityTokens().clear();
                List<IdentityToken> tokens = identityResolver.tokenise(contextWithTokens.getIdentity());
                if (tokens != null) {
                    contextWithTokens.getIdentityTokens().addAll(tokens);
                }
                return contextWithTokens;
            }
        }
        // might not be in the case of a client, or a batched transport which will have executed a seperate command to resolve identities for e.g.
View Full Code Here

                        transportSecurityStrengthFactor = 0;
                        rpcCommand.getSession().setAttribute(CougarProtocol.TSSF_ATTR_NAME, transportSecurityStrengthFactor);
                    }
                }
                byte protocolVersion = CougarProtocol.getProtocolVersion(command.getSession());
                ExecutionContextWithTokens context = marshaller.readExecutionContext(in, command.getRemoteAddress(), clientCertChain, transportSecurityStrengthFactor, protocolVersion);
                final SocketRequestContextImpl requestContext = new SocketRequestContextImpl(context);
                OperationKey remoteOperationKey = marshaller.readOperationKey(in);
                OperationDefinition opDef = findCompatibleBinding(remoteOperationKey);
                if (opDef == null) {
                    throw new CougarFrameworkException("Can't find operation definition in bindings for operation named '" + remoteOperationKey.getOperationName() + "'");
                }
                final OperationKey operationKey = opDef.getOperationKey(); // safer to read it from locally
                final OperationDefinition operationDefinition = getExecutionVenue().getOperationDefinition(operationKey);
                final Object[] args = marshaller.readArgs(operationDefinition.getParameters(), in);
                TimeConstraints rawTimeConstraints = marshaller.readTimeConstraintsIfPresent(in, protocolVersion);
                final TimeConstraints timeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(context.getRequestTime(), rawTimeConstraints);
                final ExecutionCommand exec = new ExecutionCommand() {

                    @Override
                    public Object[] getArgs() {
                        return args;
View Full Code Here

                        transportSecurityStrengthFactor = 0;
                        rpcCommand.getSession().setAttribute(CougarProtocol.TSSF_ATTR_NAME, transportSecurityStrengthFactor);
                    }
                }
                byte protocolVersion = CougarProtocol.getProtocolVersion(command.getSession());
                ExecutionContextWithTokens context = marshaller.readExecutionContext(in, command.getRemoteAddress(), clientCertChain, transportSecurityStrengthFactor, protocolVersion);
                final SocketRequestContextImpl requestContext = new SocketRequestContextImpl(context);
                OperationKey remoteOperationKey = marshaller.readOperationKey(in);
                OperationDefinition opDef = findCompatibleBinding(remoteOperationKey);
                if (opDef == null) {
                    throw new CougarFrameworkException("Can't find operation definition in bindings for operation named '" + remoteOperationKey.getOperationName() + "'");
                }
                final OperationKey operationKey = opDef.getOperationKey(); // safer to read it from locally
                final OperationDefinition operationDefinition = getExecutionVenue().getOperationDefinition(operationKey);
                final Object[] args = marshaller.readArgs(operationDefinition.getParameters(), in);
                TimeConstraints rawTimeConstraints = marshaller.readTimeConstraintsIfPresent(in, protocolVersion);
                final TimeConstraints timeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(context.getRequestTime(), rawTimeConstraints);
                final ExecutionCommand exec = new ExecutionCommand() {

                    @Override
                    public Object[] getArgs() {
                        return args;
View Full Code Here

   * Processes a TransportCommand.
   * @param command
   */
  public void process(final T command) {
        incrementCommandsProcessed();
    ExecutionContextWithTokens ctx = null;
    try {
            validateCommand(command);
      CommandResolver<T> resolver = createCommandResolver(command);
      ctx = resolver.resolveExecutionContext();
      for (ExecutionCommand exec : resolver.resolveExecutionCommands()) {
View Full Code Here

        return false;
  }
 
  @Override
  protected CommandResolver<HttpCommand> createCommandResolver(final HttpCommand http) {
        final ExecutionContextWithTokens context = resolveExecutionContext(http, http.getRequest(), http.getClientX509CertificateChain(), true);


    final List<JsonRpcRequest> requests = new ArrayList<JsonRpcRequest>();
    final List<ExecutionCommand> commands = new ArrayList<ExecutionCommand>();
    final List<JsonRpcResponse> responses = new ArrayList<JsonRpcResponse>();

    JsonNode root;
    ByteCountingInputStream iStream = null;         
    try {
      iStream = createByteCountingInputStream(http.getRequest().getInputStream());
            try {
                EnumUtils.setHardFailureForThisThread(hardFailEnumDeserialisation);
                root = mapper.readTree(iStream);
                final long bytesRead = iStream.getCount();
                final boolean isBatch = root.isArray();
                if (isBatch) {
                    requests.addAll((List<JsonRpcRequest>)mapper.convertValue(root, BATCH_REQUEST_TYPE));
                } else {
                    JsonRpcRequest rpc = mapper.convertValue(root, SINGLE_REQUEST_TYPE);
                    requests.add(rpc);
                }

                if (requests.isEmpty()) {
                    writeErrorResponse(http, context, new CougarValidationException(ServerFaultCode.NoRequestsFound, "No Requests found in rpc call"));
                } else {
                    final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(context.getRequestTime(), readRawTimeConstraints(http.getRequest()));
                    for (final JsonRpcRequest rpc : requests) {
                        final JsonRpcOperationBinding binding = bindings.get(stripMinorVersionFromUri(rpc.getMethod().toLowerCase()));
                        if (binding!=null) {
                            try {
                                JsonRpcParam [] paramDefs = binding.getJsonRpcParams();
View Full Code Here

  }

    @Override
    public void process(HttpCommand command) {
        incrementCommandsProcessed();
        ExecutionContextWithTokens ctx = null;
        try {
            validateCommand(command);
            final CommandResolver<HttpCommand> resolver = createCommandResolver(command);
            ctx = resolver.resolveExecutionContext();

            final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(ctx.getRequestTime(), readRawTimeConstraints(command.getRequest()));
            final ExecutionContextWithTokens finalCtx = ctx;
            ExecutionCommand resolveCommand = new ExecutionCommand() {
                @Override
                public OperationKey getOperationKey() {
                    return IDENTITY_RESOLUTION_OPDEF.getOperationKey();
                }

                @Override
                public Object[] getArgs() {
                    return new Object[0];
                }

                @Override
                public void onResult(ExecutionResult executionResult) {
                    Iterable<ExecutionCommand> batchCalls = resolver.resolveExecutionCommands();
                    if (executionResult.isFault()) {
                        for (ExecutionCommand exec : batchCalls) {
                            exec.onResult(executionResult);
                        }
                    }
                    // now we have an ExecutionContext that's correctly filled..
                    else {
                        // this has to be an ExecutionContext and not a ExecutionContextWithTokens to ensure that
                        // BaseExecutionVenue doesn't try to re-resolve
                        ExecutionContext context = ExecutionContextFactory.resolveExecutionContext(finalCtx, finalCtx.getIdentity());
                        for (ExecutionCommand exec : resolver.resolveExecutionCommands()) {
                            executeCommand(exec, context);
                        }
                    }
                }
View Full Code Here

    public static ExecutionContextWithTokens resolveExecutionContext(final List<IdentityToken> tokens, final RequestUUID requestUUID, final GeoLocationDetails geoDetails, final Date receivedTime, final boolean traceEnabled, final int transportSecurityStrengthFactor, final Date requestTime, final boolean ignoreSubsequentWritesOfIdentity) {
        if (tokens == null) {
            throw new IllegalArgumentException("Tokens must not be null");
        }

        return new ExecutionContextWithTokens() {

            private IdentityChain identityChain;

            @Override
            public List<IdentityToken> getIdentityTokens() {
View Full Code Here

TOP

Related Classes of com.betfair.cougar.api.ExecutionContextWithTokens

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.