當前位置: 首頁>>代碼示例>>Java>>正文


Java UnirestException類代碼示例

本文整理匯總了Java中com.mashape.unirest.http.exceptions.UnirestException的典型用法代碼示例。如果您正苦於以下問題:Java UnirestException類的具體用法?Java UnirestException怎麽用?Java UnirestException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UnirestException類屬於com.mashape.unirest.http.exceptions包,在下文中一共展示了UnirestException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mediaBookSubmit

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
@PostMapping("/result_book")
public String mediaBookSubmit(@ModelAttribute Media media, Model model, HttpServletRequest request ) {
    //System.out.println(media.getISBN());
    LinkedList<BookInfo> a = null;
    String maxResult= media.getMaxResult();
    if (maxResult.equals("")) maxResult="10";
    if (media.getTitle().trim().equals("") && media.getISBN().trim().equals("")) return "media_book";
    else if (media.getTitle().equals("") && media.getISBN().length()!=13) return "media_book";
    try {
        a = APIOperations.bookGetInfo(media.getTitle().trim(), media.getISBN().trim(), maxResult, media.getOrderBy());
    } catch (UnirestException e) {
        e.printStackTrace();
        return String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR);

    }
    RabbitSend.sendMediaRequest(media.getTitle(),"Book",request);
    if (a.size()==0) return "no_result";
    model.addAttribute("mediaList", a);
    return "result_book";
}
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:21,代碼來源:MainController.java

示例2: getAsJSONArray

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
/**
 * @return The json array get by performing request.
 */
public JSONArray getAsJSONArray() {
    JSONArray json;
    try {
        HttpResponse<JsonNode> response = request.asJson();
        checkRateLimit(response);
        handleErrorCode(response);
        JsonNode node = response.getBody();

        if (!node.isArray()) {
            handleErrorResponse(node.getObject());
            throw new UnirestException("The request returns a JSON Object. Json: "+node.getObject().toString(4));
        } else {
            json = node.getArray();
        }
    } catch (UnirestException e) {
        throw new JSONException("Error Occurred while getting JSON Array: "+e.getLocalizedMessage());
    }
    return json;
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:23,代碼來源:Requester.java

示例3: deleteTransform

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public JSONObject deleteTransform(int transformID) {
    JSONObject transform = new JSONObject();

    try {
        transform =
                Unirest.delete(MessageFormat.format("http://{0}:{1}/deployment/{2}/model/{3}", host, port, deploymentID, transformID))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .asJson()
                        .getBody().getObject();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return transform;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:17,代碼來源:Transform.java

示例4: deleteModel

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public JSONObject deleteModel(int modelID) {
    JSONObject model = new JSONObject();

    try {
        model =
                Unirest.delete(MessageFormat.format("http://{0}:{1}/deployment/{2}/model/{3}", host, port, deploymentID, modelID))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .asJson()
                        .getBody().getObject();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return model;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:17,代碼來源:Model.java

示例5: retrieveAllFiles

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public static List<String> retrieveAllFiles(String auth, String folder) throws IOException, UnirestException {
    List<String> lis= new LinkedList<String>();
    HttpResponse<JsonNode> jsonResponse = Unirest.get("https://www.googleapis.com/drive/v2/files/root/children?q=title='"+folder+"'").header("Authorization","Bearer "+auth).asJson();
    JSONObject jsonObject= new JSONObject(jsonResponse.getBody());
    JSONArray array = jsonObject.getJSONArray("array");
    for(int i=0;i<array.length();i++){
        JSONArray jarray=array.getJSONObject(i).getJSONArray("items");
        int j=jarray.length();
        while(j>0){
            String id=jarray.getJSONObject(0).getString("id");
            auxRetrieveAllFiles(lis,auth,"https://www.googleapis.com/drive/v2/files?includeTeamDriveItems=false&pageSize=500&q='"+id+"'%20in%20parents"+"&key="+ MISConfig.getGoogle_api(),id);
            j--;
        }

    }
    return lis;
}
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:18,代碼來源:GDrvAPIOp.java

示例6: setTransformState

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public JSONObject setTransformState(int transformID, String state) {
    JSONObject transform = new JSONObject();

    try {
        transform =
                Unirest.delete(MessageFormat.format("http://{0}:{1}/deployment/{2}/model/{3}/state", host, port, deploymentID, transformID))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .body(new JSONObject()
                                .put("name", state)
                                .toString())
                        .asJson()
                        .getBody().getObject();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return transform;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:20,代碼來源:Transform.java

示例7: getAuthToken

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public String getAuthToken(String userId, String password) {
    String authToken = null;

    try {
        authToken =
                Unirest.post(MessageFormat.format("http://{0}:{1}/login", host, port))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .body(new JSONObject() //Using this because the field functions couldn't get translated to an acceptable json
                                .put("userId", userId)
                                .put("password", password)
                                .toString())
                        .asJson()
                        .getBody().getObject().getString("token");
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return authToken;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:21,代碼來源:Authorization.java

示例8: getIdentifier

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
    HttpResponse<JsonNode> me = Unirest.get("https://oauth.reddit.com/api/v1/me")
            .header("Authorization", "bearer " + token)
            .header("User-Agent", "pxls.space")
            .asJson();
    JSONObject json = me.getBody().getObject();
    if (json.has("error")) {
        return null;
    } else {
        long accountAgeSeconds = (System.currentTimeMillis() / 1000 - json.getLong("created"));
        long minAgeSeconds = App.getConfig().getDuration("oauth.reddit.minAge", TimeUnit.SECONDS);
        if (accountAgeSeconds < minAgeSeconds){
            long days = minAgeSeconds / 86400;
            throw new InvalidAccountException("Account too young");
        } else if (!json.getBoolean("has_verified_email")) {
            throw new InvalidAccountException("Account must have a verified e-mail");
        }
        return json.getString("name");
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:21,代碼來源:RedditAuthService.java

示例9: setModelState

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public JSONObject setModelState(int modelID, String state) {
    JSONObject model = new JSONObject();

    try {
        model =
                Unirest.delete(MessageFormat.format("http://{0}:{1}/deployment/{2}/model/{3}/state", host, port, deploymentID, modelID))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .body(new JSONObject()
                                .put("name", state)
                                .toString())
                        .asJson()
                        .getBody().getObject();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return model;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:20,代碼來源:Model.java

示例10: deleteKNN

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public JSONObject deleteKNN(int knnID) {
    JSONObject knn = new JSONObject();

    try {
        knn =
                Unirest.delete(MessageFormat.format("http://{0}:{1}/deployment/{2}/model/{3}", host, port, deploymentID, knnID))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .asJson()
                        .getBody().getObject();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return knn;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:17,代碼來源:KNN.java

示例11: getIdentifier

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public String getIdentifier(String token) throws UnirestException, InvalidAccountException {
    HttpResponse<JsonNode> me = Unirest.get("https://api.vk.com/method/users.get?access_token=" + token)
            .header("User-Agent", "pxls.space")
            .asJson();
    JSONObject json = me.getBody().getObject();

    if (json.has("error")) {
        return null;
    } else {
        try {
            return Integer.toString(json.getJSONArray("response").getJSONObject(0).getInt("uid"));
        } catch (JSONException e) {
            return null;
        }
    }
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:17,代碼來源:VKAuthService.java

示例12: methodSetUp

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
@Before
public void methodSetUp() throws IOException, UnirestException {
    // one commit with four decisions is always available and we have the same decisions as eadls
    // in our code repo
    seRepoTestServer.createRepository();
    seRepoTestServer.createCommit(getBasicDecisionsAsSeItemsWithContent(), CommitMode.ADD_UPDATE);

    DecisionSourceMapping.clear();
    Path code = codeBase.getRoot().toPath();
    codeRepoMock = new CodeRepoMock(code);
    codeRepoMock.createClassesForEadls(getBasicDecisionsAsEadl());

    commander.parse(InitCommand.NAME, "-u", seRepoTestServer.LOCALHOST_SEREPO, "-p", TEST_REPO,
            "-s", code.toString());
    INIT_COMMAND.initialize();
}
 
開發者ID:adr,項目名稱:eadlsync,代碼行數:17,代碼來源:CommandTest.java

示例13: auxRetrieveAllFiles

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
private static void auxRetrieveAllFiles(List<String> lis,String auth, String link, String parents) throws IOException, UnirestException {
    HttpResponse<JsonNode> jsonResponse = Unirest.get(link).header("Authorization","Bearer "+auth).asJson();
    JSONObject jsonObject = new JSONObject(jsonResponse.getBody());
    JSONArray array = jsonObject.getJSONArray("array");
    for (int j=0;j<array.length();j++){
        JSONArray jarray=array.getJSONObject(j).getJSONArray("items");
        for(int i = 0; i < jarray.length(); i++)
        {
            if(jarray.getJSONObject(i).has("mimeType") && !jarray.getJSONObject(i).get("mimeType").equals("application/vnd.google-apps.folder")){
                String name= jarray.getJSONObject(i).getString("title");
                lis.add(jarray.getJSONObject(i).getString("title"));
            }
            else {
                if(jarray.getJSONObject(i).has("id")){
                    auxRetrieveAllFiles(lis,auth,"https://www.googleapis.com/drive/v2/files?includeTeamDriveItems=false&pageSize=500&q='"+jarray.getJSONObject(i).get("id")+"'%20in%20parents"+"&key="+ MISConfig.getGoogle_api(),parents);
                }
            }
        }
        if(array.getJSONObject(j).has("nextLink")){
            String next=array.getJSONObject(j).getString("nextLink");
            auxRetrieveAllFiles(lis,auth,next,parents);
        }
    }


}
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:27,代碼來源:GDrvAPIOp.java

示例14: getAllDeployments

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
public JSONArray getAllDeployments() {
    JSONArray deployments = new JSONArray();

    try {
        deployments =
                Unirest.get(MessageFormat.format("http://{0}:{1}/deployments", host, port))
                        .header("accept", "application/json")
                        .header("Content-Type", "application/json")
                        .asJson()
                        .getBody().getArray();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    return deployments;
}
 
開發者ID:SkymindIO,項目名稱:SKIL_Examples,代碼行數:17,代碼來源:Deployment.java

示例15: finish

import com.mashape.unirest.http.exceptions.UnirestException; //導入依賴的package包/類
@Override
public void finish() {
	String title = (String) super.getResponses().get(0);
	if(title.length() > 400) {
		super.sendMessage("Error: Title length cannot be greater than 400 characters");
		super.exit();
	}
	boolean multi = (boolean) super.getResponses().get(1);
	String[] options = super.getResponses().subList(2, super.getResponses().size())
			.toArray(new String[super.getResponses().size() - 2]);
	if(options.length < 2 || options.length > 30) {
		super.sendMessage("Error: You must have between 2 and 30 options (inclusive)");
		super.exit();
	}
	StrawpollObject poll = new StrawpollObject(title, multi, options);
	try {
		super.sendMessage("http://www.strawpoll.me/" + poll.createPoll());
	} catch (UnirestException e) {
		super.sendMessage("Sorry, something went wrong creating your Strawpoll - Might be over my limits!");
		e.printStackTrace();
	}
	super.exit();
}
 
開發者ID:paul-io,項目名稱:momo-2,代碼行數:24,代碼來源:Strawpoll.java


注:本文中的com.mashape.unirest.http.exceptions.UnirestException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。