Package com.wordnik.swagger.runtime.exception

Examples of com.wordnik.swagger.runtime.exception.APIException



        //check for app server values
        if(getApiServer() == null || getApiServer().length() == 0) {
          String[] args = {getApiServer()};
          throw new APIException(APIExceptionCodes.API_SERVER_NOT_VALID, args);
        }

        //make the communication
    resourceURL = getApiServer() + resourceURL;
    if(queryParams.keySet().size() > 0){
      int i=0;
      for(String paramName : queryParams.keySet()){
        String symbol = "&";
        if(i==0){
          symbol = "?";
        }
        resourceURL = resourceURL + symbol + paramName + "=" + queryParams.get(paramName);
        i++;
      }
    }
        Map<String, String> headerMap = new HashMap<String, String>();
        if(securityHandler != null){
            securityHandler.populateSecurityInfo(resourceURL, headerMap);
        }
        WebResource aResource = apiClient.resource(resourceURL);


        //set the required HTTP headers
        Builder builder = aResource.type("application/json");
        for(String key : headerMap.keySet()){
            builder.header(key, headerMap.get(key));
        }
        if(headerParams != null){
            for(String key : headerParams.keySet()){
                builder.header(key, headerParams.get(key));
            }
        }

        ClientResponse clientResponse = null;
        if(method.equals(GET)) {
          clientResponse =  builder.get(ClientResponse.class);
        }else if (method.equals(POST)) {
          clientResponse =  builder.post(ClientResponse.class, serialize(postData));
        }else if (method.equals(PUT)) {
          clientResponse =  builder.put(ClientResponse.class, serialize(postData));
        }else if (method.equals(DELETE)) {
          clientResponse =  builder.delete(ClientResponse.class);
        }
       
        //process the response
        if(clientResponse.getClientResponseStatus() == ClientResponse.Status.OK) {
          String response = clientResponse.getEntity(String.class);
      return response;
        }else{
          int responseCode = clientResponse.getClientResponseStatus().getStatusCode() ;
          throw new APIException(responseCode, clientResponse.getEntity(String.class));
        }
  }
View Full Code Here


                Object responseObject = mapper.readValue(response, inputClassName);
                return responseObject;
            }
        } catch (IOException ioe) {
          String[] args = new String[]{response, inputClassName.toString()};
            throw new APIException(APIExceptionCodes.ERROR_CONVERTING_JSON_TO_JAVA, args, "Error in coversting response json value to java object : " + ioe.getMessage(), ioe);
        }
  }
View Full Code Here

              return mapper.writeValueAsString(input);
          }else{
            return "";
          }
        } catch (IOException ioe) {
            throw new APIException(APIExceptionCodes.ERROR_CONVERTING_JAVA_TO_JSON, "Error in coverting input java to json : " + ioe.getMessage(), ioe);
        }
  }
View Full Code Here

TOP

Related Classes of com.wordnik.swagger.runtime.exception.APIException

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.