本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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();
}
}
示例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));
}
示例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()));
}
}
示例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");
}
示例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();
}
示例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;
}
}