Package com.betfair.cougar.transport.api.protocol.http.rescript

Examples of com.betfair.cougar.transport.api.protocol.http.rescript.RescriptBody


  public Object[] resolveArgs(HttpServletRequest request, InputStream inputStream, MediaType mediaType, String encoding) {
        Object[] args = new Object[paramBindings.length];

        String format = mediaType == null || mediaType.getSubtype() == null ? "unknown" : mediaType.getSubtype();
        RescriptBody body = null;
        if (bindingDescriptor.containsBodyData()) {
            //If the request contains body data, then it must be a post request
            if (!request.getMethod().equals("POST")) {
                throw CougarMarshallingException.unmarshallingException(format, "Bad body data", false);
            }
            body = resolveBody(inputStream, mediaType, encoding);
        }

        // jetty 9 handily gives back null when you specify a header with no value, whereas jetty 7 treated this as an empty string.. which we rely on
        // so, we're going to list all the header names, and for each on if the value is null, add them to a set so we can query later..
        Set<String> headersWithNullValues = new HashSet<>();
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String header = headerNames.nextElement();
            if (request.getHeader(header) == null) {
                headersWithNullValues.add(header.toLowerCase());
            }
        }
        try {
            for (int i = 0; i < args.length; ++i) {
                RescriptParamBindingDescriptor descriptor = paramBindings[i];
                Parameter param = operationDefinition.getParameters()[i];
                switch (descriptor.getSource()) {
                    case HEADER :
                        String key = descriptor.getName();
                        args[i] = resolveArgument(headersWithNullValues.contains(key.toLowerCase()) ? "" : request.getHeader(key), param, descriptor, format);
                        break;
                    case QUERY :
                        args[i] = resolveArgument(request.getParameter(descriptor.getName()), param, descriptor, format);
                        break;
                    case BODY :
                        if (body != null) {
                            args[i] = body.getValue(descriptor.getName());
                            // non-null enums get stored as their raw string value so need converting to the true enum value
                            if (param.getParameterType().getType() == ParameterType.Type.ENUM) {
                                if (args[i] != null) {
                                    args[i] = EnumUtils.readEnum(param.getParameterType().getImplementationClass(), (String) args[i]);
                                }
View Full Code Here


  }

  public Object[] resolveArgs(HttpServletRequest request, InputStream inputStream, MediaType mediaType, String encoding) {
        Object[] args = new Object[paramBindings.length];

        RescriptBody body = null;
        if (bindingDescriptor.containsBodyData()) {
            //If the request contains body data, then it must be a post request
            if (!request.getMethod().equals("POST")) {
                throw new CougarValidationException(ServerFaultCode.RescriptDeserialisationFailure, "Bad body data");
            }
            body = resolveBody(inputStream, mediaType, encoding);
        }

        // jetty 9 handily gives back null when you specify a header with no value, whereas jetty 7 treated this as an empty string.. which we rely on
        // so, we're going to list all the header names, and for each on if the value is null, add them to a set so we can query later..
        Set<String> headersWithNullValues = new HashSet<>();
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String header = headerNames.nextElement();
            if (request.getHeader(header) == null) {
                headersWithNullValues.add(header.toLowerCase());
            }
        }
        for (int i = 0; i < args.length; ++i) {
            RescriptParamBindingDescriptor descriptor = paramBindings[i];
            Parameter param = operationDefinition.getParameters()[i];
            switch (descriptor.getSource()) {
                case HEADER :
                    String key = descriptor.getName();
                    args[i] = resolveArgument(headersWithNullValues.contains(key.toLowerCase()) ? "" : request.getHeader(key), param, descriptor);
                    break;
                case QUERY :
                    args[i] = resolveArgument(request.getParameter(descriptor.getName()), param, descriptor);
                    break;
                case BODY :
                    if (body != null) {
                        args[i] = body.getValue(descriptor.getName());
                        // non-null enums get stored as their raw string value so need converting to the true enum value
                        if (param.getParameterType().getType() == ParameterType.Type.ENUM) {
                            if (args[i] != null) {
                                args[i] = EnumUtils.readEnum(param.getParameterType().getImplementationClass(), (String) args[i]);
                            }
View Full Code Here

TOP

Related Classes of com.betfair.cougar.transport.api.protocol.http.rescript.RescriptBody

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.