本文整理汇总了Java中org.apache.commons.httpclient.methods.PutMethod.addRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java PutMethod.addRequestHeader方法的具体用法?Java PutMethod.addRequestHeader怎么用?Java PutMethod.addRequestHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.PutMethod
的用法示例。
在下文中一共展示了PutMethod.addRequestHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: 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();
}
}
示例7: 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);
}
示例8: getSendByteArrayMethod
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public PutMethod getSendByteArrayMethod(byte[] content, String service) throws Exception {
// Prepare HTTP put
//
String urlString = constructUrl(service);
log.logDebug(toString(), Messages.getString("SlaveServer.DEBUG_ConnectingTo", urlString)); //$NON-NLS-1$
PutMethod putMethod = new PutMethod(urlString);
// Request content will be retrieved directly from the input stream
//
RequestEntity entity = new ByteArrayRequestEntity(content);
putMethod.setRequestEntity(entity);
putMethod.setDoAuthentication(true);
putMethod.addRequestHeader(new Header("Content-Type", "text/xml;charset=" + Const.XML_ENCODING));
return putMethod;
}
示例9: httpPut
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
protected static PutMethod httpPut(String path, String body) throws IOException {
LOG.info("Connecting to {}", url + path);
HttpClient httpClient = new HttpClient();
PutMethod putMethod = new PutMethod(url + path);
putMethod.addRequestHeader("Origin", url);
RequestEntity entity = new ByteArrayRequestEntity(body.getBytes("UTF-8"));
putMethod.setRequestEntity(entity);
httpClient.executeMethod(putMethod);
LOG.info("{} - {}", putMethod.getStatusCode(), putMethod.getStatusText());
return putMethod;
}
示例10: httpPut
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
protected static PutMethod httpPut(String path, String body, String user, String pwd) throws IOException {
LOG.info("Connecting to {}", url + path);
HttpClient httpClient = new HttpClient();
PutMethod putMethod = new PutMethod(url + path);
putMethod.addRequestHeader("Origin", url);
RequestEntity entity = new ByteArrayRequestEntity(body.getBytes("UTF-8"));
putMethod.setRequestEntity(entity);
if (userAndPasswordAreNotBlank(user, pwd)) {
putMethod.setRequestHeader("Cookie", "JSESSIONID="+ getCookie(user, pwd));
}
httpClient.executeMethod(putMethod);
LOG.info("{} - {}", putMethod.getStatusCode(), putMethod.getStatusText());
return putMethod;
}
示例11: testInvalidRequest
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testInvalidRequest() throws IOException {
String jsonInvalidRequestEntityNull = "{\"entity\" : null, \"username\" : \"test\", \"password\" : \"testpass\"}";
String jsonInvalidRequestNameNull = "{\"entity\" : \"test\", \"username\" : null, \"password\" : \"testpass\"}";
String jsonInvalidRequestPasswordNull = "{\"entity\" : \"test\", \"username\" : \"test\", \"password\" : null}";
String jsonInvalidRequestAllNull = "{\"entity\" : null, \"username\" : null, \"password\" : null}";
PutMethod entityNullPut = httpPut("/credential", jsonInvalidRequestEntityNull);
entityNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(entityNullPut, isBadRequest());
entityNullPut.releaseConnection();
PutMethod nameNullPut = httpPut("/credential", jsonInvalidRequestNameNull);
nameNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(nameNullPut, isBadRequest());
nameNullPut.releaseConnection();
PutMethod passwordNullPut = httpPut("/credential", jsonInvalidRequestPasswordNull);
passwordNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(passwordNullPut, isBadRequest());
passwordNullPut.releaseConnection();
PutMethod allNullPut = httpPut("/credential", jsonInvalidRequestAllNull);
allNullPut.addRequestHeader("Origin", "http://localhost");
assertThat(allNullPut, isBadRequest());
allNullPut.releaseConnection();
}
示例12: createPut
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public PutMethod createPut(final URI requestURI, final String accept, final boolean cookie) {
final PutMethod method = new PutMethod(requestURI.toString());
if (cookie) {
method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
}
if (StringHelper.containsNonWhitespace(accept)) {
method.addRequestHeader("Accept", accept);
}
method.addRequestHeader("Accept-Language", "en");
return method;
}
示例13: testImportCp
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testImportCp() throws HttpException, IOException, URISyntaxException {
final URL cpUrl = RepositoryEntriesITCase.class.getResource("cp-demo.zip");
assertNotNull(cpUrl);
final File cp = new File(cpUrl.toURI());
final HttpClient c = loginWithCookie("administrator", "olat");
final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "cp-demo.zip"), new StringPart("resourcename", "CP demo"),
new StringPart("displayname", "CP demo") };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
final int code = c.executeMethod(method);
assertTrue(code == 200 || code == 201);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class);
assertNotNull(vo);
final Long key = vo.getKey();
final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key);
assertNotNull(re);
assertNotNull(re.getOwnerGroup());
assertNotNull(re.getOlatResource());
assertEquals("CP demo", re.getDisplayname());
}
示例14: testPutCatalogEntryJson
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testPutCatalogEntryJson() throws IOException {
final RepositoryEntry re = createRepository("put-cat-entry-json", 6458438l);
final HttpClient c = loginWithCookie("administrator", "olat");
final CatalogEntryVO subEntry = new CatalogEntryVO();
subEntry.setName("Sub-entry-1");
subEntry.setDescription("Sub-entry-description-1");
subEntry.setType(CatalogEntry.TYPE_NODE);
subEntry.setRepositoryEntryKey(re.getKey());
final String entity = stringuified(subEntry);
final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.APPLICATION_JSON);
final RequestEntity requestEntity = new StringRequestEntity(entity, MediaType.APPLICATION_JSON, "UTF-8");
method.setRequestEntity(requestEntity);
final int code = c.executeMethod(method);
assertEquals(200, code);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
assertNotNull(vo);
final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
CatalogEntry ce = null;
for (final CatalogEntry child : children) {
if (vo.getKey().equals(child.getKey())) {
ce = child;
break;
}
}
assertNotNull(ce);
assertNotNull(ce.getRepositoryEntry());
assertEquals(re.getKey(), ce.getRepositoryEntry().getKey());
}
示例15: testImportQuestionnaire
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testImportQuestionnaire() throws HttpException, IOException, URISyntaxException {
final URL cpUrl = RepositoryEntriesITCase.class.getResource("questionnaire-demo.zip");
assertNotNull(cpUrl);
final File cp = new File(cpUrl.toURI());
final HttpClient c = loginWithCookie("administrator", "olat");
final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "questionnaire-demo.zip"), new StringPart("resourcename", "Questionnaire demo"),
new StringPart("displayname", "Questionnaire demo") };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
final int code = c.executeMethod(method);
assertTrue(code == 200 || code == 201);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class);
assertNotNull(vo);
final Long key = vo.getKey();
final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key);
assertNotNull(re);
assertNotNull(re.getOwnerGroup());
assertNotNull(re.getOlatResource());
assertEquals("Questionnaire demo", re.getDisplayname());
log.info(re.getOlatResource().getResourceableTypeName());
}