本文整理汇总了Java中org.apache.commons.httpclient.methods.PutMethod.setRequestEntity方法的典型用法代码示例。如果您正苦于以下问题:Java PutMethod.setRequestEntity方法的具体用法?Java PutMethod.setRequestEntity怎么用?Java PutMethod.setRequestEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.PutMethod
的用法示例。
在下文中一共展示了PutMethod.setRequestEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPut
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public String doPut(String url, String charset, String jsonObj) {
String resStr = null;
HttpClient htpClient = new HttpClient();
PutMethod putMethod = new PutMethod(url);
putMethod.getParams().setParameter(
HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
try {
putMethod.setRequestEntity(new StringRequestEntity(jsonObj,
"application/json", charset));
int statusCode = htpClient.executeMethod(putMethod);
if (statusCode != HttpStatus.SC_OK) {
log.error("Method failed: " + putMethod.getStatusLine());
return null;
}
byte[] responseBody = putMethod.getResponseBody();
resStr = new String(responseBody, charset);
} catch (Exception e) {
e.printStackTrace();
} finally {
putMethod.releaseConnection();
}
return resStr;
}
示例2: putBinary
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public HttpResponse putBinary(final RequestContext rq, final String scope, final int version, final String entityCollectionName,
final Object entityId, final String relationCollectionName, final Object relationshipEntityId, final BinaryPayload payload,
final Map<String, String> params) throws IOException
{
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
relationshipEntityId, params);
String url = endpoint.getUrl();
PutMethod req = new PutMethod(url);
if (payload != null)
{
BinaryRequestEntity requestEntity = new BinaryRequestEntity(payload.getFile(), payload.getMimeType(), payload.getCharset());
req.setRequestEntity(requestEntity);
}
return submitRequest(req, rq);
}
示例3: updateAccount
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateAccount() throws HttpException, IOException {
System.out.println("Sent HTTP PUT request to update Account");
File input = new File(testFolder + "Account.xml");
PutMethod put =
new PutMethod(cadURL + "/object/User?_type=xml&externalServiceType=FBMC&externalUsername=8x8webservice&externalPassword=E4qtjWZLYKre");
put.addRequestHeader("Content-Type", "application/xml");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
put.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(put);
System.out.println("Response status code: " + result);
System.out.println("Response body: " + put.getResponseBodyAsString());
} finally {
put.releaseConnection();
}
}
示例4: updateCustomer
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateCustomer() throws HttpException, IOException {
System.out.println("Sent HTTP PUT request to update Customer");
File input = new File(testFolder + "Customer.xml");
PutMethod put = new PutMethod(cadURL + "/object/customer?_type=xml");
put.addRequestHeader("Content-Type", "application/xml");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
put.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
System.out.println("URI: " + put.getURI());
int result = httpclient.executeMethod(put);
System.out.println("Response status code: " + result);
System.out.println("Response body: " + put.getResponseBodyAsString());
} finally {
put.releaseConnection();
}
}
示例5: updateContact
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateContact() throws HttpException, IOException {
System.out.println("Sent HTTP POST request to createContact");
File input = new File(testFolder + "Contact.xml");
PutMethod put = new PutMethod(cadURL + "/object/oltp?_type=xml");
put.addRequestHeader("Content-Type", "application/xml");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
put.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
System.out.println("URI: " + put.getURI());
int result = httpclient.executeMethod(put);
System.out.println("Response status code: " + result);
System.out.println("Response body: " + put.getResponseBodyAsString());
} finally {
put.releaseConnection();
}
}
示例6: updateUser
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateUser() throws HttpException, IOException {
File input = new File(testFolder + "User.xml");
PutMethod put = new PutMethod(cadURL + "/object/user?_type=xml");
put.addRequestHeader("Content-Type", "application/xml");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
put.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
System.out.println("URI: " + put.getURI());
int result = httpclient.executeMethod(put);
System.out.println("Response status code: " + result);
System.out.println("Response body: " + put.getResponseBodyAsString());
} finally {
put.releaseConnection();
}
}
示例7: updateCase
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateCase() throws HttpException, IOException {
File input = new File(testFolder + "Case.xml");
PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
post.addRequestHeader("Content-Type", "application/xml");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
System.out.println("URI: " + post.getURI());
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: " + post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例8: updateFollowup
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateFollowup() throws HttpException, IOException {
File input = new File(testFolder + "Followup.xml");
PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
post.addRequestHeader("Content-Type", "application/xml");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
System.out.println("URI: " + post.getURI());
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: " + post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例9: doPut
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
/**
* 处理Put请求
* @param url
* @param headers
* @param object
* @param property
* @return
*/
public static JSONObject doPut(String url, Map<String, String> headers,String jsonString) {
HttpClient httpClient = new HttpClient();
PutMethod putMethod = new PutMethod(url);
//设置header
setHeaders(putMethod,headers);
//设置put传递的json数据
if(jsonString!=null&&!"".equals(jsonString)){
putMethod.setRequestEntity(new ByteArrayRequestEntity(jsonString.getBytes()));
}
String responseStr = "";
try {
httpClient.executeMethod(putMethod);
responseStr = putMethod.getResponseBodyAsString();
} catch (Exception e) {
log.error(e);
responseStr="{status:0}";
}
return JSONObject.parseObject(responseStr);
}
示例10: testBasicSecurityPutCall
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testBasicSecurityPutCall() throws IOException {
final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8");
final GroupVO vo = new GroupVO();
vo.setName("hello dont put");
vo.setDescription("hello description dont put");
vo.setMinParticipants(new Integer(-1));
vo.setMaxParticipants(new Integer(-1));
final String stringuifiedAuth = stringuified(vo);
final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8");
final String request = "/repo/courses/" + course.getResourceableId() + "/groups";
final PutMethod method = createPut(request, MediaType.APPLICATION_JSON, true);
method.setRequestEntity(entity);
final int code = c.executeMethod(method);
assertEquals(401, code);
}
示例11: testUploadFile
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testUploadFile() throws IOException, URISyntaxException {
final HttpClient c = loginWithCookie("administrator", "olat");
final URI uri = UriBuilder.fromUri(getNodeURI()).path("files").build();
// create single page
final URL fileUrl = RepositoryEntriesITCase.class.getResource("singlepage.html");
assertNotNull(fileUrl);
final File file = new File(fileUrl.toURI());
final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
final Part[] parts = { new FilePart("file", file), new StringPart("filename", file.getName()) };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
final int code = c.executeMethod(method);
assertEquals(code, 200);
final OlatNamedContainerImpl folder = BCCourseNode.getNodeFolderContainer((BCCourseNode) bcNode, course1.getCourseEnvironment());
final VFSItem item = folder.resolve(file.getName());
assertNotNull(item);
}
示例12: executeUpdateObject
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
protected <T> String executeUpdateObject(final T newObject, final String uri,
final Map<String, String> parameters) throws BigSwitchBcfApiException,
IllegalArgumentException{
checkInvariants();
PutMethod pm = (PutMethod)createMethod("put", uri, _port);
setHttpHeader(pm);
try {
pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null));
} catch (UnsupportedEncodingException e) {
throw new BigSwitchBcfApiException("Failed to encode json request body", e);
}
executeMethod(pm);
String hash = checkResponse(pm, "BigSwitch HTTP update failed: ");
pm.releaseConnection();
return hash;
}
示例13: saveStream
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
/**
* Saves a stream into a file in the repository.
*
* @param text
* Stream to be stored.
* @param url
* URL to the file that will be created.
*/
public void saveStream(InputStream stream, String url) throws IOException {
PutMethod putMethod = new PutMethod(url);
putMethod.setRequestEntity(new InputStreamRequestEntity(stream));
try {
client.executeMethod(putMethod);
putMethod.releaseConnection();
} catch (IOException e) {
throw new IOException(e);
}
finally {
stream.close();
}
}
示例14: testRetrieveTextFile
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testRetrieveTextFile() throws HttpException, IOException {
DavHandler dav = new DavHandler(folders);
InputStream stream = new ByteArrayInputStream("some text".getBytes());
PutMethod putMethod = new PutMethod(
"http://localhost:9002/parent/child/textToRetrieve.txt");
putMethod.setRequestEntity(new InputStreamRequestEntity(stream));
HttpClient client = new HttpClient();
client.executeMethod(putMethod);
stream.close();
putMethod.releaseConnection();
String retrieved = dav.retrieveTextFile("http://localhost:9002/parent/child/textToRetrieve.txt");
assertEquals("some text", retrieved);
}
示例15: put
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public HttpResponse put(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, final String body)
throws IOException
{
RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, null);
String url = endpoint.getUrl();
PutMethod req = new PutMethod(url);
if (body != null)
{
StringRequestEntity requestEntity = new StringRequestEntity(body, "application/json", "UTF-8");
req.setRequestEntity(requestEntity);
}
return submitRequest(req, rq);
}