本文整理汇总了Java中org.eclipse.jetty.client.ContentExchange.getResponseContent方法的典型用法代码示例。如果您正苦于以下问题:Java ContentExchange.getResponseContent方法的具体用法?Java ContentExchange.getResponseContent怎么用?Java ContentExchange.getResponseContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.ContentExchange
的用法示例。
在下文中一共展示了ContentExchange.getResponseContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sentGetRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static String sentGetRequest(final String url) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod("GET");
contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setURL(url);
httpClient.send(contentExchange);
contentExchange.waitForDone();
return contentExchange.getResponseContent();
} finally {
httpClient.stop();
}
}
示例2: readExchangeCallLog
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
static CallLog[] readExchangeCallLog(ObjectMapper mapper, ContentExchange exchange) {
try {
exchange.waitForDone();
String responseJson = exchange.getResponseContent();
return mapper.readValue(responseJson, CallLog[].class);
} catch (Exception e) {
return new CallLog[0];
}
}
示例3: login
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static String[] login(String username, String password, String url)
throws Exception, InterruptedException, SAXException,
ParserConfigurationException {
HttpClient client = new HttpClient();
client.setTimeout(10000);
client.setConnectTimeout(5000);
client.start();
ContentExchange exchange = new ContentExchange();
exchange.setMethod("POST");
exchange.setURL(new URL(url + getSoapUri()).toExternalForm());
exchange.setRequestContentSource(new ByteArrayInputStream(soapXmlForLogin(
username, password)));
exchange.setRequestHeader("Content-Type", "text/xml");
exchange.setRequestHeader("SOAPAction", "''");
exchange.setRequestHeader("PrettyPrint", "Yes");
client.send(exchange);
exchange.waitForDone();
String response = exchange.getResponseContent();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SAXParser saxParser = spf.newSAXParser();
LoginResponseParser parser = new LoginResponseParser();
saxParser.parse(new ByteArrayInputStream(
response.getBytes("UTF-8")), parser);
if (parser.sessionId == null || parser.serverUrl == null) {
System.out.println("Login Failed!\n" + response);
return null;
}
URL soapEndpoint = new URL(parser.serverUrl);
StringBuilder endpoint = new StringBuilder()
.append(soapEndpoint.getProtocol())
.append("://")
.append(soapEndpoint.getHost());
if (soapEndpoint.getPort() > 0) endpoint.append(":")
.append(soapEndpoint.getPort());
return new String[]{parser.sessionId, endpoint.toString()};
}