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


Java Response.getStatus方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.Response.getStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java Response.getStatus方法的具體用法?Java Response.getStatus怎麽用?Java Response.getStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.Response的用法示例。


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

示例1: talk

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
/**
 * Sends text to pandorabots to be analyzed
 *
 * @param clientName From Pandorabots website: "Identifies your application's end user. You can assign each of your
 *                   end users a unique client_name. This will allow you to set predicates and other variable
 *                   information that is specific to an individual. Format required is 3-64 characters in length
 *                   and only numbers or lower-case letters [0-9][a-z]"
 * @param text       Message to be sent to the bot. This can contain multiple sentences. Currently the limit is 500 characters.
 * @return The response array will contain one element (response) for each sentence you input to the bot.
 * @throws IOException
 */
public ArrayList<String> talk(String clientName, String text) throws IOException {
    Response response = client.target(PANDORA_URL)
            .path("talk")
            .path(appId)
            .path(pandoraBot)
            .queryParam("user_key", userKey)
            .queryParam("client_name", clientName)
            .queryParam("input", text)
            .queryParam("recent", true)
            .request(MediaType.APPLICATION_JSON)
            .post(Entity.entity(null, MediaType.APPLICATION_JSON));

    if (response.getStatus() > 300) {
        String msg = String.format("Pandora.talk: msg: %s, status: %d",
                response.readEntity(String.class),
                response.getStatus());
        Logger.warning(msg);
        throw new IOException(msg);
    }

    return response.readEntity(PandoraResponse.class).responses;
}
 
開發者ID:wireapp,項目名稱:anna-bot,代碼行數:34,代碼來源:Pandora.java

示例2: getUrl

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
/**
 * 
 * @param path the path to the called API command
 * @return the API called result as String
 * @throws IOException When access is failed
 */
private String getUrl(String path) throws IOException {
	Response response = null;
	String targetUrl = url + path;
	try {
		response = client.target(targetUrl).request().get();
	} catch(Exception e) {
		if(response != null) {
			response.close();
		}
		throw new IOException(e.getMessage() + "(" + targetUrl + ")", e);
	}
       if (! (response.getStatus() == Response.Status.OK.getStatusCode() || response.getStatus() == 400)) {
       	String msg = "[" + response.getStatus() + "] " + targetUrl;
       	response.close();
       	throw new IOException(msg);
       }
       String result = response.readEntity(String.class);
       response.close();
       return result;
}
 
開發者ID:Shunshun94,項目名稱:discord-bcdicebot,代碼行數:27,代碼來源:BCDiceClient.java

示例3: postMessage

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
/**
 * curl -H "X-Auth-Token: $TOKEN" -H "X-User-Id: $USER" $HOST/api/v1/chat.postMessage \
 * -d '{ "channel": "#general", "text": "This is a test!" }' -H "Content-type:application/json"
 *
 * @param postMessageRequest json object
 * @return json object
 */
public PostMessageResponse postMessage(PostMessageRequest postMessageRequest) {
    Invocation.Builder invocationBuilder = getInvocationBuilder(webTarget.path("chat.postMessage"));

    Response response = invocationBuilder.post(Entity.json(postMessageRequest));
    LOGGER.debug("Response      : " + response.toString());
    if (Response.Status.OK.equals(response.getStatusInfo())) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    PostMessageResponse postMessageResponse = response.readEntity(PostMessageResponse.class);
    LOGGER.debug("Response Data : " + postMessageResponse);
    if (!postMessageResponse.getSuccess()) {
        throw new RuntimeException("Failed : can't post message: " + postMessageResponse.getMessage());
    }
    return postMessageResponse;
}
 
開發者ID:sscholl,項目名稱:biblebot,代碼行數:24,代碼來源:RocketChatService.java

示例4: registerUser

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
private static void registerUser(String url, MediaType mediaType) {
    System.out.println("Registering user via " + url);
    User user = new User(1L, "larrypage");
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(url);
    Response response = target.request().post(Entity.entity(user, mediaType));

    try {
        if (response.getStatus() != 200) {
            throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
        }
        System.out.println("Successfully got result: " + response.readEntity(String.class));
    } finally {
        response.close();
        client.close();
    }
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:18,代碼來源:RestClient.java

示例5: saveSpan

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
void saveSpan(String parentSpanId, String spanId, String traceId, String spanName, String serviceName, String ipv4, long timestamp, long duration) {
    JsonArray span = createSpans(parentSpanId, spanId, traceId, spanName, serviceName, ipv4, timestamp, duration);
    Response response = this.tut.request().post(Entity.json(span));
    final int status = response.getStatus();
    if (status == 202) {
        this.LOG.log("Successfully sent");
        this.LOG.log("span: " + span);
    } else {
        this.LOG.log("Problem sending span. Status: " + status);
    }
}
 
開發者ID:AdamBien,項目名稱:SpanEE,代碼行數:12,代碼來源:SpanEE.java

示例6: convert

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
@Override
public APIError convert(ClientErrorException exception) {
	Response response = exception.getResponse();

	int status = response.getStatus();

	return new APIErrorImpl(
		exception, "General server error", "client-error", status);
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:10,代碼來源:ClientErrorExceptionConverter.java

示例7: testEndpoint

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
public void testEndpoint(String endpoint, String expectedOutput) {
    String port = System.getProperty("liberty.test.port");
    String war = System.getProperty("war.name");
    String url = "http://localhost:" + port + "/" + war + endpoint;
    System.out.println("Testing " + url);
    Response response = sendRequest(url, "GET");
    int responseCode = response.getStatus();
    assertTrue("Incorrect response code: " + responseCode,
               responseCode == 200);
    
    String responseString = response.readEntity(String.class);
    response.close();
    assertTrue("Incorrect response, response is " + responseString, responseString.contains(expectedOutput));
}
 
開發者ID:technologyfa,項目名稱:fa-Istio-Service-Mesh-on-Kubernetes-1,代碼行數:15,代碼來源:EndpointTest.java

示例8: handleWebApplicationException

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
private Response handleWebApplicationException(final WebApplicationException webappException) {
    Response res = webappException.getResponse();
    if (HttpStatus.SC_METHOD_NOT_ALLOWED == res.getStatus()) {
        return this.handlePersoniumCoreException(PersoniumCoreException.Misc.METHOD_NOT_ALLOWED);
    } else if (HttpStatus.SC_NOT_FOUND == res.getStatus()) {
        return this.handlePersoniumCoreException(PersoniumCoreException.Misc.NOT_FOUND);
    }
    return res;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:10,代碼來源:PersoniumCoreExceptionMapper.java

示例9: should_return_forbiden_headers_without_authorization_header

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
@Test
@Ignore // missing MVC template injection
public void should_return_forbiden_headers_without_authorization_header() {
    Response response = target(path).request().get();
    int status = response.getStatus();
    assertEquals(FORBIDDEN.getStatusCode(), status);
}
 
開發者ID:maugern,項目名稱:jersey-skeleton,代碼行數:8,代碼來源:SecureResourceByAnnotationTest.java

示例10: getUser

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
private static void getUser(String url) {
    System.out.println("Getting user via " + url);
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(url);
    Response response = target.request().get();
    try {
        if (response.getStatus() != 200) {
            throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
        }
        System.out.println("Successfully got result: " + response.readEntity(String.class));
    } finally {
        response.close();
        client.close();
    }
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:16,代碼來源:RestClient.java

示例11: check

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
public Result<String> check(String endpoint) {
	Response response = resource("endpoint").options();
	if (response.getStatus() == 200) {
		return Result.accept(response.getStatus(), "accepted");
	}
	return Result.reject(response.getStatus(), null, resolve(response));
}
 
開發者ID:PatternFM,項目名稱:tokamak,代碼行數:8,代碼來源:PreFlightClient.java

示例12: getRelationshipTypes

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
private Collection<RelationshipType> getRelationshipTypes(String parentType) throws OEClientException {
	logger.info("getRelationshipTypes entry: {}", parentType);

	Map<String, String> queryParameters = new HashMap<String, String>();
	queryParameters.put("properties", "rdfs:label,owl:inverseOf,rdfs:subPropertyOf,owl:inverseOf/rdfs:label,owl:inverseOf/rdfs:subPropertyOf");
	Invocation.Builder invocationBuilder = getInvocationBuilder(getModelURL() + "/" + parentType +"/meta:transitiveSubProperty", queryParameters);

	Date startDate = new Date();
	logger.info("getRelationshipTypes making call  : {}", startDate.getTime());
	Response response = invocationBuilder.get();
	logger.info("getRelationshipTypes call complete: {}", startDate.getTime());

	logger.info("getRelationshipTypes - status: {}", response.getStatus());
	if (response.getStatus() == 200) {
		String stringResponse = response.readEntity(String.class);
		if (logger.isInfoEnabled()) logger.info("getConceptClasses: jsonResponse {}", stringResponse);
		JsonObject jsonResponse = JSON.parse(stringResponse);
		JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
		Collection<RelationshipType> relationshipTypes = new HashSet<RelationshipType>();
		Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
		while (jsonValueIterator.hasNext()) {
			relationshipTypes.add(new RelationshipType(this, jsonValueIterator.next().getAsObject()));
		}
		return relationshipTypes;
	} else {
		throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
	}
}
 
開發者ID:Smartlogic-Semaphore-Limited,項目名稱:Java-APIs,代碼行數:29,代碼來源:OEClientReadOnly.java

示例13: evalSCCPMessage

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
/**
 * Evaluate SCCP message towards IDS server.
 * 
 * @param sccp_raw SCCP hex raw payload of message
 * @return true if message is valid and false if message should be filtered
 */
public boolean evalSCCPMessage(String sccp_raw) {
    int attempts = serverList.size();
    
    Response response = null;
    String output = "1";
    
    int i = randomGenerator.nextInt(serverList.size());
    
    do {
        if (serverBackoffAttempts.get(i) == null || serverBackoffAttempts.get(i).intValue() <= 0) {
            try {
                WebTarget webResourceWithQueryParam = serverTargetsList.get(i).matrixParam("sccp_raw", sccp_raw);
                response = webResourceWithQueryParam.request("text/plain").get();
                if (response.getStatus() == 200) {
                    output = response.readEntity(String.class);
                    logger.debug("evalSCCPMessage " + webResourceWithQueryParam + " Response: " + output);
                    break;
                } else {
                    logger.warn("Connection failed for IDS API: HTTP error code : " + response.getStatus() + " for " + serverTargetsList.get(i));
                }
            } catch (Exception e) {
                serverBackoffAttempts.put(i, SERVER_BACKOFFATTEMPTS);
                logger.warn("Connection failed for IDS API: " + serverTargetsList.get(i) + " " + e.toString());
            }
        } else {
            if (serverBackoffAttempts.get(i) != null) {
                serverBackoffAttempts.put(i, serverBackoffAttempts.get(i).intValue() - 1);
            }
            i = randomGenerator.nextInt(serverList.size());
        }
        attempts--;
    } while (attempts > 0);

    
    return output.equals("1");
}
 
開發者ID:P1sec,項目名稱:SigFW,代碼行數:43,代碼來源:ConnectorIDSModuleRest.java

示例14: confirm

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
@Override
public boolean confirm(String switchId) {
	WebTarget webTarget = webTargetFactory.create();
	
	Response response = webTarget.path("confirm/").path(switchId).request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).get();
	if (response.getStatus() !=  Response.Status.OK.getStatusCode()) {
		logger.error("OFS response from confirmation " + response);
		return false;
	}
	
	Confirmation confirmation = response.readEntity(Confirmation.class);
	return confirmation.isConfirmed();
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:14,代碼來源:WebTargetConfirmer.java

示例15: isJBossUpAndRunning

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
public static boolean isJBossUpAndRunning() {

        /*
            This is doing a REST HTTP call to query if Wildfly is up and running
         */

        try {
            WebTarget target = getClient().target("http://localhost:9990/management").queryParam("operation", "attribute").queryParam("name", "server-state");
            Response response = target.request(MediaType.APPLICATION_JSON).get();
            return response.getStatus() == Response.Status.OK.getStatusCode() && response.readEntity(String.class).contains("running");
        } catch (Exception e){
            return false;
        }
    }
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:15,代碼來源:JBossUtil.java


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