本文整理汇总了Java中org.eclipse.jetty.client.ContentExchange.setURL方法的典型用法代码示例。如果您正苦于以下问题:Java ContentExchange.setURL方法的具体用法?Java ContentExchange.setURL怎么用?Java ContentExchange.setURL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.ContentExchange
的用法示例。
在下文中一共展示了ContentExchange.setURL方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sentRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static int sentRequest(final String url, final String method, final String content) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(method);
contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
contentExchange.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setURL(url);
httpClient.send(contentExchange);
contentExchange.waitForDone();
return contentExchange.getResponseStatus();
} finally {
httpClient.stop();
}
}
示例2: 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();
}
}
示例3: sentRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
private static ContentExchange sentRequest(final String content) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange result = new ContentExchange();
result.setMethod("POST");
result.setRequestContentType(MediaType.APPLICATION_JSON);
result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
result.setURL(URL);
httpClient.send(result);
result.waitForDone();
return result;
} finally {
httpClient.stop();
}
}
示例4: postData
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static InvokeResult postData(String url, String params) {
if (StringUtils.isBlank(url) || StringUtils.isBlank(params)) {
return InvokeResult.errorResult;
}
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(HttpMethod.POST.getValue());
contentExchange.setURL(url);
try {
AbstractBuffer content = new ByteArrayBuffer(params.getBytes(InvokerMsg.CHARSET_UTF8));
contentExchange.setRequestContent(content);
return invoke(contentExchange);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
return InvokeResult.errorResult;
}
示例5: putData
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static InvokeResult putData(String url, String params) {
if (StringUtils.isBlank(url) || StringUtils.isBlank(params)) {
return InvokeResult.errorResult;
}
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(HttpMethod.PUT.getValue());
contentExchange.setURL(url);
try {
AbstractBuffer content = new ByteArrayBuffer(params.getBytes(InvokerMsg.CHARSET_UTF8));
contentExchange.setRequestContent(content);
return invoke(contentExchange);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
return InvokeResult.errorResult;
}
示例6: sendRequestWithHeaders
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
private ContentExchange sendRequestWithHeaders(String url, Map<String, List<String>> headers, String method, String payload) throws IOException, InterruptedException {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(url);
if (null != method) {
exchange.setMethod(method);
}
if (null != payload) {
exchange.setRequestContentSource(new ByteArrayInputStream(payload.getBytes()));
}
for (Entry<String, List<String>> e : headers.entrySet()) {
for (String val : e.getValue()) {
exchange.addRequestHeader(e.getKey(), val);
}
}
client.send(exchange);
exchange.waitForDone();
return exchange;
}
示例7: getAllBooks
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Override
public Book[] getAllBooks() {
try {
ContentExchange contentExchange = new ContentExchange(true);
contentExchange.setMethod("GET");
contentExchange.setURL("http://" + host + ":" + port + "/get_books");
httpClient.send(contentExchange);
if (contentExchange.waitForDone() == HttpExchange.STATUS_COMPLETED) {
return objectMapper.readValue(contentExchange.getResponseContent(), Book[].class);
} else {
throw new RuntimeException("Exception making request to retrieve all books");
}
} catch (Exception e) {
throw new RuntimeException("Exception making request to retrieve all books", e);
}
}
示例8: getBook
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Override
public Book getBook(String id) {
try {
ContentExchange contentExchange = new ContentExchange(true);
contentExchange.setMethod("GET");
contentExchange.setURL("http://" + host + ":" + port + "/get_book" + "?id=" + id);
httpClient.send(contentExchange);
if (contentExchange.waitForDone() == HttpExchange.STATUS_COMPLETED) {
return objectMapper.readValue(contentExchange.getResponseContent(), Book.class);
} else {
throw new RuntimeException("Exception making request to retrieve all books");
}
} catch (Exception e) {
throw new RuntimeException("Exception making request to retrieve a book with id [" + id + "]", e);
}
}
示例9: getData
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static InvokeResult getData(String url) {
if (StringUtils.isBlank(url)) {
return InvokeResult.errorResult;
}
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(HttpMethod.GET.getValue());
logger.info(url);
contentExchange.setURL(url);
return invoke(contentExchange);
}
示例10: deleteData
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static InvokeResult deleteData(String url) {
if (StringUtils.isBlank(url)) {
return InvokeResult.errorResult;
}
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(HttpMethod.DELETE.getValue());
contentExchange.setURL(url);
return invoke(contentExchange);
}
示例11: sendRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
/**
* Helper method to send an HTTP request.
*/
protected ContentExchange sendRequest(String url) throws Exception {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(url);
client.send(exchange);
exchange.waitForDone();
return exchange;
}
示例12: createRequestForSign
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
static Tuple2<String, ContentExchange> createRequestForSign(String sign, HttpClient client) throws Exception {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL("http://new73s.herokuapp.com/qsos/" + sign + ".json");
client.send(exchange);
return new Tuple2(sign, exchange);
}
示例13: 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()};
}