本文整理汇总了Java中com.sun.jersey.api.client.ClientResponse.getStatus方法的典型用法代码示例。如果您正苦于以下问题:Java ClientResponse.getStatus方法的具体用法?Java ClientResponse.getStatus怎么用?Java ClientResponse.getStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.api.client.ClientResponse
的用法示例。
在下文中一共展示了ClientResponse.getStatus方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postRest
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
/**
* Performs a REST POST operation of a json string on the base
* XOS REST URI with an optional additional URI suffix.
*
* @param uri URI suffix to append to base URI
* @param json JSON string to post
*/
public void postRest(String uri, String json) {
WebResource.Builder builder = getClientBuilder(uri);
ClientResponse response;
try {
response = builder.post(ClientResponse.class, json);
} catch (ClientHandlerException e) {
log.warn("Unable to contact REST server: {}", e.getMessage());
return;
}
if (response.getStatus() != HTTP_CREATED) {
log.info("REST POST request returned error code {}",
response.getStatus());
}
}
示例2: putRest
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
/**
* Performs a REST PUT operation on the base XOS REST URI with
* an optional additional URI.
*
* @param uri URI suffix to append to base URI
* @return JSON string returned by the PUT operation
*/
public String putRest(String uri) {
WebResource.Builder builder = getClientBuilder(uri);
ClientResponse response;
try {
response = builder.put(ClientResponse.class);
} catch (ClientHandlerException e) {
log.warn("Unable to contact REST server: {}", e.getMessage());
return "";
}
if (response.getStatus() != HTTP_OK) {
log.info("REST PUT request returned error code {}",
response.getStatus());
}
return response.getEntity(String.class);
}
示例3: getStudent
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
public Student getStudent(){
ClientResponse clientResponse= this.client
.resource(API_NOTITAS)
.path("student")
.header("Authorization", "Bearer " + this.bearerToken)
.accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
if(clientResponse.getStatus()==200){
clientResponse.bufferEntity();
String jsonString = clientResponse.getEntity(String.class);
Student student = new Gson().fromJson(jsonString, Student.class);
return student;
}
return new Student();
}
示例4: doRoleCommand
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
private void doRoleCommand(String serviceName, String roleName, RoleCommand roleCommand) {
URI uri = UriBuilder.fromUri(serverHostname)
.path("api")
.path(API_VERSION)
.path("clusters")
.path(clusterName)
.path("services")
.path(serviceName)
.path("roleCommands")
.path(roleCommand.toString())
.build();
String body = "{ \"items\": [ \"" + roleName + "\" ] }";
LOG.info("Executing POST against " + uri + " with body " + body + "...");
ClientResponse response = client.resource(uri)
.type(MediaType.APPLICATION_JSON)
.post(ClientResponse.class, body);
int statusCode = response.getStatus();
if (statusCode != Response.Status.OK.getStatusCode()) {
throw new HTTPException(statusCode);
}
}
示例5: main
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
public static void main(String [] args) {
System.out.println("Simple Java test for calling Hello Word service");
try {
// Get the endpoint for Hello World API
String endpoint = args[0];
// Create the client and call the API
Client client = Client.create();
WebResource webResource = client
.resource(endpoint+"helloworld/");
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
// Process the result
if (response.getStatus() != 200) {
throw new RuntimeException("Called failed to HelloWorld : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Response: ");
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: getABFMapper
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
public static ImmutableBiMap<String,String> getABFMapper() {
String serviceURL = null;
ImmutableBiMap<String,String> ABFMAPPER = null;
try {
serviceURL = System.getenv("authcode.service.URL");
if (serviceURL == null)
serviceURL = System.getProperty("authcode.service.URL","http://localhost:9876/references");
LOG.info("Initializing ABF Reference with remote service URL: "+ serviceURL);
Client client = Client.create();
WebResource webResource = client.resource(serviceURL);
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
String output = response.getEntity(String.class);
if (response.getStatus() == 200 && output != null && !output.isEmpty()) {
Map<String, String> mapResponse = OBJECT_MAPPER.readValue(output, new TypeReference<Map<String, String>>() {});
ABFMAPPER = ImmutableBiMap.copyOf(Collections.unmodifiableMap(mapResponse));
LOG.info("Success on getting ABF Reference map from "+ serviceURL);
} else {
ABFMAPPER = ImmutableBiMap.copyOf(Collections.unmodifiableMap(ABFCodeMap.defaultABFMapper()));
}
}catch(Exception ex){
ABFMAPPER = ImmutableBiMap.copyOf(Collections.unmodifiableMap(ABFCodeMap.defaultABFMapper()));
LOG.warn("ABF Mapper initialization failed");
}
return ABFMAPPER;
}
示例7: getRest
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
/**
* Performs a REST GET operation on the base XOS REST URI with
* an optional additional URI.
*
* @param uri URI suffix to append to base URI
* @return JSON string fetched by the GET operation
*/
public String getRest(String uri) {
WebResource.Builder builder = getClientBuilder(uri);
ClientResponse response = builder.get(ClientResponse.class);
if (response.getStatus() != HTTP_OK) {
log.info("REST GET request returned error code {}",
response.getStatus());
}
return response.getEntity(String.class);
}
示例8: deleteRest
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
/**
* Performs a REST DELETE operation on the base
* XOS REST URI with an optional additional URI.
*
* @param uri URI suffix to append to base URI
*/
public void deleteRest(String uri) {
WebResource.Builder builder = getClientBuilder(uri);
ClientResponse response = builder.delete(ClientResponse.class);
if (response.getStatus() != HTTP_NO_CONTENT) {
log.info("REST DELETE request returned error code {}",
response.getStatus());
}
}
示例9: getJsonNodeFromURIGet
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
private JsonNode getJsonNodeFromURIGet(URI uri) throws IOException {
LOG.info("Executing GET against " + uri + "...");
ClientResponse response = client.resource(uri)
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(ClientResponse.class);
int statusCode = response.getStatus();
if (statusCode != Response.Status.OK.getStatusCode()) {
throw new HTTPException(statusCode);
}
// This API folds information as the value to an "items" attribute.
return new ObjectMapper().readTree(response.getEntity(String.class)).get("items");
}
示例10: uploadFile
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
public ClientResponse uploadFile(VirtualFile source, String branch) {
if (source == null) {
return null;
}
if (this.projectIdentifier == null || "".equals(this.projectIdentifier)) {
return null;
}
if (this.projectKey == null || "".equals(this.projectKey)) {
return null;
}
ClientResponse clientResponse = null;
Credentials credentials = new Credentials(baseUrl, projectIdentifier, projectKey, null);
CrowdinApiParametersBuilder crowdinApiParametersBuilder = new CrowdinApiParametersBuilder();
CrowdinApiClient crowdinApiClient = new Crwdn();
crowdinApiParametersBuilder.json()
.headers(HttpHeaders.USER_AGENT, USER_AGENT_ANDROID_STUDIO_PLUGIN)
.files(source.getCanonicalPath())
.exportPatterns(source.getName(), "/values-%android_code%/%original_file_name%");
String createdBranch = this.createBranch(branch);
if (createdBranch != null) {
crowdinApiParametersBuilder.branch(createdBranch);
}
try {
clientResponse = crowdinApiClient.addFile(credentials, crowdinApiParametersBuilder);
if (clientResponse != null && clientResponse.getStatus() == 200) {
Utils.showInformationMessage("File '" + source.getName() + "' added to Crowdin");
}
//LOGGER.info("Crowdin: add file '" + source.getName() + "': " + clientResponse.getStatus() + " " + clientResponse.getStatusInfo());
System.out.println("Crowdin: add file '" + source.getName() + "': " + clientResponse.getStatus() + " " + clientResponse.getStatusInfo());
if (clientResponse != null && clientResponse.getStatus() == 400) {
clientResponse = crowdinApiClient.updateFile(credentials, crowdinApiParametersBuilder);
if (clientResponse != null && clientResponse.getStatus() == 200) {
Utils.showInformationMessage("File '" + source.getName() + "' updated in Crowdin");
}
//LOGGER.info("Crowdin: update file '" + source.getName() + "': " + clientResponse.getStatus() + " " + clientResponse.getStatusInfo());
System.out.println("Crowdin: update file '" + source.getName() + "': " + clientResponse.getStatus() + " " + clientResponse.getStatusInfo());
}
if (clientResponse != null && clientResponse.getStatus() != 200 && clientResponse.getStatus() != 400) {
Utils.showInformationMessage("File '" + source.getName() + "' isn't uploaded in Crowdin");
}
} catch (Exception e) {
e.printStackTrace();
}
return clientResponse;
}
示例11: main
import com.sun.jersey.api.client.ClientResponse; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/LogIn");
String input = "{\"email\":\"myk22\",\"password\":\"qweasd\"}";
ClientResponse response = webResource.type("application/json")
.post(ClientResponse.class, input);
if (response.getStatus() != 200) {
System.out.println("error");
}
System.out.println("Output from Server .... \n"+response.getStatus());
String output = response.getEntity(String.class);
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}