本文整理汇总了Java中org.apache.commons.httpclient.methods.PutMethod.getResponseBodyAsStream方法的典型用法代码示例。如果您正苦于以下问题:Java PutMethod.getResponseBodyAsStream方法的具体用法?Java PutMethod.getResponseBodyAsStream怎么用?Java PutMethod.getResponseBodyAsStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.PutMethod
的用法示例。
在下文中一共展示了PutMethod.getResponseBodyAsStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPutParameterInURI
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testPutParameterInURI() throws Exception {
HttpClient client = new HttpClient();
PutMethod put = new PutMethod("http://localhost:" + port1 + "/parameter?request=PutParameter&others=bloggs");
StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8");
put.setRequestEntity(entity);
client.executeMethod(put);
InputStream response = put.getResponseBodyAsStream();
String out = context.getTypeConverter().convertTo(String.class, response);
assertEquals("Get a wrong output ", "PutParameter", out);
}
示例2: sendXML
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public String sendXML(String xml, String service) throws Exception
{
byte[] content = xml.getBytes(Const.XML_ENCODING);
PutMethod put = getSendByteArrayMethod(content, service);
// Get HTTP client
//
HttpClient client = new HttpClient();
addCredentials(client);
// Execute request
//
try
{
int result = client.executeMethod(put);
// The status code
log.logDebug(toString(), Messages.getString("SlaveServer.DEBUG_ResponseStatus", Integer.toString(result))); //$NON-NLS-1$
// the response
InputStream inputStream = new BufferedInputStream(put.getResponseBodyAsStream(), 1000);
StringBuffer bodyBuffer = new StringBuffer();
int c;
while ( (c=inputStream.read())!=-1) bodyBuffer.append((char)c);
inputStream.close();
String bodyTmp = bodyBuffer.toString();
switch(result)
{
case 401: // Security problem: authentication required
// Non-internationalized message
String message = "Authentication failed"+Const.DOSCR+Const.DOSCR+bodyTmp; //$NON-NLS-1$
WebResult webResult = new WebResult(WebResult.STRING_ERROR, message);
bodyBuffer.setLength(0);
bodyBuffer.append(webResult.getXML());
break;
}
String body = bodyBuffer.toString();
// String body = post.getResponseBodyAsString();
log.logDebug(toString(), Messages.getString("SlaveServer.DEBUG_ResponseBody",body)); //$NON-NLS-1$
return body;
}
finally
{
// Release current connection to the connection pool once you are done
put.releaseConnection();
log.logDetailed(toString(), Messages.getString("SlaveServer.DETAILED_SentXmlToService", service, environmentSubstitute(hostname))); //$NON-NLS-1$
}
}
示例3: sendExport
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
/**
* Send an exported archive over to this slave server
* @param filename The archive to send
* @param type The type of file to add to the slave server (AddExportServlet.TYPE_*)
* @param load The filename to load in the archive (the .kjb or .ktr)
* @return the XML of the web result
* @throws Exception in case something goes awry
*/
public String sendExport(String filename, String type, String load) throws Exception
{
String serviceUrl=AddExportServlet.CONTEXT_PATH;
if (type!=null && load!=null) {
serviceUrl = serviceUrl+= "/?"+AddExportServlet.PARAMETER_TYPE+"="+type+"&"+AddExportServlet.PARAMETER_LOAD+"="+URLEncoder.encode(load, "UTF-8");
}
String urlString = constructUrl(serviceUrl);
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
//
FileObject fileObject = KettleVFS.getFileObject(filename);
RequestEntity entity = new InputStreamRequestEntity(KettleVFS.getInputStream(fileObject));
putMethod.setRequestEntity(entity);
putMethod.setDoAuthentication(true);
putMethod.addRequestHeader(new Header("Content-Type", "binary/zip"));
// Get HTTP client
//
HttpClient client = new HttpClient();
addCredentials(client);
// Execute request
//
try
{
int result = client.executeMethod(putMethod);
// The status code
log.logDebug(toString(), Messages.getString("SlaveServer.DEBUG_ResponseStatus", Integer.toString(result))); //$NON-NLS-1$
// the response
InputStream inputStream = new BufferedInputStream(putMethod.getResponseBodyAsStream(), 1000);
StringBuffer bodyBuffer = new StringBuffer();
int c;
while ( (c=inputStream.read())!=-1) bodyBuffer.append((char)c);
inputStream.close();
String bodyTmp = bodyBuffer.toString();
switch(result)
{
case 401: // Security problem: authentication required
// Non-internationalized message
String message = "Authentication failed"+Const.DOSCR+Const.DOSCR+bodyTmp; //$NON-NLS-1$
WebResult webResult = new WebResult(WebResult.STRING_ERROR, message);
bodyBuffer.setLength(0);
bodyBuffer.append(webResult.getXML());
break;
}
String body = bodyBuffer.toString();
// String body = post.getResponseBodyAsString();
log.logDebug(toString(), Messages.getString("SlaveServer.DEBUG_ResponseBody",body)); //$NON-NLS-1$
return body;
}
finally
{
// Release current connection to the connection pool once you are done
putMethod.releaseConnection();
log.logDetailed(toString(), Messages.getString("SlaveServer.DETAILED_SentExportToService", AddExportServlet.CONTEXT_PATH, environmentSubstitute(hostname))); //$NON-NLS-1$
}
}