本文整理匯總了Java中org.apache.commons.httpclient.methods.PutMethod.setRequestHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java PutMethod.setRequestHeader方法的具體用法?Java PutMethod.setRequestHeader怎麽用?Java PutMethod.setRequestHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.methods.PutMethod
的用法示例。
在下文中一共展示了PutMethod.setRequestHeader方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: putFile
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
public static void putFile(HttpClient client,
HttpURL url,
InputStream is,
String contentType,
String lockToken)
throws IOException, HttpException
{
PutMethod put = new PutMethod(url.getURI());
generateIfHeader(put, lockToken);
put.setRequestHeader("Content-Type", contentType);
put.setRequestBody(is);
put.setFollowRedirects(true);
int status = client.executeMethod(put);
switch (status) {
case WebdavStatus.SC_OK:
case WebdavStatus.SC_CREATED:
case WebdavStatus.SC_NO_CONTENT:
return;
default:
HttpException ex = new HttpException();
ex.setReason(put.getStatusText());
ex.setReasonCode(status);
throw ex;
}
}
示例2: putMethod
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
/**
* Execute the PUT method for the given path.
*
* @param path the server relative path to put the data
* @param data The byte array.
* @return true if the method is succeeded.
* @exception HttpException
* @exception IOException
*/
public boolean putMethod(String path, byte[] data)
throws HttpException, IOException {
setClient();
PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
generateIfHeader(method);
if (getGetContentType() != null && !getGetContentType().equals(""))
method.setRequestHeader("Content-Type", getGetContentType());
method.setRequestHeader("Content-Length", String.valueOf(data.length));
method.setRequestBody(new ByteArrayInputStream(data));
generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
return (statusCode >= 200 && statusCode < 300) ? true : false;
}
示例3: getMethod
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
private PutMethod getMethod(Resource resource, String path, String encoding) {
PutMethod method = new PutMethod(this.csp.getUrl() + this.csp.getVersion() + path + resource.getId());
ComplienceUtils.configureMethod(method);
method.setRequestHeader(new Header("Accept", "application/" + encoding));
if (resource.getMeta() != null && !resource.getMeta().getVersion().isEmpty()) {
method.setRequestHeader(new Header("If-Match", resource.getMeta().getVersion()));
}
return method;
}
示例4: postModel
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
private String postModel(String openScoringUrl, String pmml) throws HttpException, IOException {
id.set(UUID.randomUUID().toString());
StringBuilder urlBuilder = new StringBuilder(openScoringUrl).append("/model/").append(id);
String url = urlBuilder.toString();
PutMethod put = new PutMethod(url);
getLogger().warn(String.format("Posting model to %s", url));
put.setRequestHeader("Content-Type", "text/xml");
RequestEntity requestEntity = new StringRequestEntity(pmml, "text/xml", "utf-8");
put.setRequestEntity(requestEntity);
httpClient.executeMethod(put);
return id.get();
}
示例5: callPutFileApi
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
private void callPutFileApi(String fileType, String url, String filePath, String oui, String prodClass, String version) throws HttpException, IOException, HitDMException {
org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
PutMethod putMethod = new PutMethod(url);
File input = new File(filePath);
RequestEntity entity = new FileRequestEntity(input, "Content-Length: 1431");
putMethod.setRequestEntity(entity);
putMethod.setRequestHeader("fileType", fileType);
putMethod.setRequestHeader("oui", oui);
putMethod.setRequestHeader("productClass", prodClass);
putMethod.setRequestHeader("version", version);
client.executeMethod(putMethod);
if (putMethod.getStatusCode() != 200) {
String debugStr = "DM Server return:"+ putMethod.getStatusCode();
byte[] body;
try {
body = putMethod.getResponseBody();
if (body != null) {
debugStr += "\r\nBody:"+new String(body);
}
} catch (Exception e) {
debugStr += e.getMessage();
}
throw new HitDMException(putMethod.getStatusCode(), debugStr);
}
}
示例6: getPut
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
public static PutMethod getPut(String url, String host, String auth, String contentType) {
PutMethod put = new PutMethod(url);
put.setRequestHeader("Authorization", "Basic " + auth);
put.setRequestHeader("Content-Type", contentType);
put.setRequestHeader("X-App-Token", appToken);
put.setRequestHeader("X-Socrata-Host", host);
put.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(2, false));
return put;
}
示例7: 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;
}
示例8: updateMachine
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
public void updateMachine(int executionId, int machineId, MachineNode machine) throws Exception {
PutMethod method = new PutMethod(baseUri + "executions/" + executionId + "/machines/" + machineId);
method.setRequestHeader(new Header("Content-Type", "application/json"));
final ObjectMapper mapper = new ObjectMapper();
final String json = mapper.writeValueAsString(machine);
final RequestEntity entity = new StringRequestEntity(json,"application/json","UTF-8");
method.setRequestEntity(entity);
int responseCode = client.executeMethod(method);
handleResponseCode(method, responseCode);
}
示例9: put
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
public void put(IdProof assertion, String path, BdbResourceHandle handle) throws ServiceException {
try {
PutMethod method = new PutMethod(baseUrl + "/" + path);
method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion));
method.setRequestEntity(new InputStreamRequestEntity(handle.read()));
int result = httpClient.executeMethod(method);
if (result != 200) {
throw new ServiceException(result);
}
}
catch (IOException ex) {
throw new ServiceFailure(ex);
}
}
示例10: endExecution
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
public void endExecution(int executionId) throws Exception {
final PutMethod method = new PutMethod(baseUri + "executions/" + executionId + "?active=false");
method.setRequestHeader(new Header("Content-Type", "text/plain"));
final int responseCode = client.executeMethod(method);
handleResponseCode(method, responseCode);
}
示例11: doTheWork
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
protected boolean doTheWork(String registrationData, String url, String version) {
String registrationKey = propertyService.getStringProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY);
boolean regStatus = false;
if (StringHelper.containsNonWhitespace(registrationData)) {
// only send when there is something to send
final HttpClient client = HttpClientFactory.getHttpClientInstance();
client.getParams().setParameter("http.useragent", "OLAT Registration Agent ; " + version);
log.info("URL:" + url, null);
final PutMethod method = new PutMethod(url);
if (registrationKey != null) {
// updating
method.setRequestHeader("Authorization", registrationKey);
if (log.isDebugEnabled()) {
log.debug("Authorization: " + registrationKey, null);
} else {
log.debug("Authorization: EXISTS", null);
}
} else {
log.info("Authorization: NONE", null);
}
method.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
try {
method.setRequestEntity(new StringRequestEntity(registrationData, "application/xml", "UTF8"));
client.executeMethod(method);
final int status = method.getStatusCode();
if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
log.info("Successfully registered OLAT installation on olat.org server, thank you for your support!", null);
registrationKey = method.getResponseBodyAsString();
propertyService.setProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY, registrationKey);
regStatus = true;
} else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
log.error("File could be created not on registration server::" + method.getStatusLine().toString(), null);
regStatus = false;
} else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
log.info(method.getResponseBodyAsString() + method.getStatusText());
regStatus = false;
} else {
log.error("Unexpected HTTP Status::" + method.getStatusLine().toString() + " during registration call", null);
regStatus = false;
}
} catch (final Exception e) {
log.error("Unexpected exception during registration call", e);
regStatus = false;
}
} else {
log.warn(
"****************************************************************************************************************************************************************************",
null);
log.warn(
"* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *",
null);
log.warn(
"****************************************************************************************************************************************************************************",
null);
}
return regStatus;
}
示例12: sendViaPut
import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
/**
* Used to send a request via HTTP Put Method
*
* @param msgContext - The MessageContext of the message
* @param url - The target URL
* @param soapActionString - The soapAction string of the request
* @throws AxisFault - Thrown in case an exception occurs
*/
private void sendViaPut(MessageContext msgContext, URL url,
String soapActionString) throws AxisFault {
HttpClient httpClient = getHttpClient(msgContext);
/* Same deal - this value never gets used, why is it here? --Glen
String charEncoding =
(String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
if (charEncoding == null) {
charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
*/
PutMethod putMethod = new PutMethod();
MessageFormatter messageFormatter =
populateCommonProperties(msgContext, url, putMethod, httpClient, soapActionString);
putMethod.setRequestEntity(new AxisRequestEntity(messageFormatter,
msgContext, format, soapActionString,
chunked, isAllowedRetry));
if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
putMethod.setContentChunked(true);
}
String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString);
if (soapAction != null && !msgContext.isDoingREST()) {
putMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
}
/*
* main excecution takes place..
*/
try {
executeMethod(httpClient, msgContext, url, putMethod);
handleResponse(msgContext, putMethod);
} catch (IOException e) {
log.info("Unable to sendViaPut to url[" + url + "]", e);
throw AxisFault.makeFault(e);
} finally {
cleanup(msgContext, putMethod);
}
}