当前位置: 首页>>代码示例>>Java>>正文


Java Resource.post方法代码示例

本文整理汇总了Java中org.apache.wink.client.Resource.post方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.post方法的具体用法?Java Resource.post怎么用?Java Resource.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.wink.client.Resource的用法示例。


在下文中一共展示了Resource.post方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: post

import org.apache.wink.client.Resource; //导入方法依赖的package包/类
public XMLWrapper post(Object payload) throws Exception {
	System.out.println("post "+url);
	//Thread.dumpStack();
   	Resource resource = createResource();
   	
   	ClientResponse clientResponse = resource.post(payload);

   	if(clientResponse.getStatusCode() != HttpStatus.OK.getCode()){
   		throw new Exception(clientResponse.getMessage());
   	}
   	
   	return new XMLWrapper(clientResponse.getEntity(String.class));
}
 
开发者ID:angarg12,项目名称:cloudcompaas-common,代码行数:14,代码来源:RESTComm.java

示例2: connect

import org.apache.wink.client.Resource; //导入方法依赖的package包/类
/**
 * link http
 * 
 * @param server
 * @param port
 * @param url
 * @param method
 * @param data
 * @return
 */

public RetRpc connect(String server, int port, String url, String method,
		String data, String protocal, String userName, String password) {

	RetRpc ret = new RetRpc();
	String address;
	address = protocal + "://" + server + ":" + port + url;

	ClientConfig config = new ClientConfig();
	config.connectTimeout(600000);
	if (null != userName && userName.length() > 0 && null != password
			&& password.length() > 0) {
		OpsAuthSecurityHandler opsAuthHandler = new OpsAuthSecurityHandler();
		opsAuthHandler.setUserName(userName);
		opsAuthHandler.setPassword(password);
		config.handlers(opsAuthHandler);
	}
 
	// create the rest client instance
	OpsRestClient client = new OpsRestClient(config);
	// create the resource instance to interact with
	Resource resource = client.resource(address);
	 
	// issue the request
	ClientResponse response = null;

	try {
		if (ACTION_POST.equals(method)) {
			response = resource.post(data);
		} else if (ACTION_PUT.equals(method)) {
			response = resource.put(data);

		} else if (ACTION_DELETE.equals(method)) {
			response = resource.delete();

		} else {
			response = resource.get();
		}
	} catch (Exception ex) {
		
		ex.printStackTrace();
		ret.setStatusCode(500);
		ret.setMsg(ex.getMessage());
		ret.setStatus("connected failed .");
		
		return ret;
	}  
	
	int code = response.getStatusCode();
	String msg = response.getMessage();
	ret.setStatusCode(code);
	ret.setMsg(msg);

	// deserialize response
	ret.setContent(response.getEntity(String.class));

	return ret;
}
 
开发者ID:HuaweiSNC,项目名称:OpsDev,代码行数:69,代码来源:OpsRestCaller.java


注:本文中的org.apache.wink.client.Resource.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。