当前位置: 首页>>代码示例>>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;未经允许,请勿转载。