当前位置: 首页>>代码示例>>Java>>正文


Java ContentExchange.setMethod方法代码示例

本文整理汇总了Java中org.eclipse.jetty.client.ContentExchange.setMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ContentExchange.setMethod方法的具体用法?Java ContentExchange.setMethod怎么用?Java ContentExchange.setMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.client.ContentExchange的用法示例。


在下文中一共展示了ContentExchange.setMethod方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
    }
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:18,代码来源:RestfulTestsUtil.java

示例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();
    }
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:17,代码来源:RestfulTestsUtil.java

示例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();
    }
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:18,代码来源:RestfulServerTest.java

示例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;
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:17,代码来源:JettyHttpClientUtil.java

示例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;
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:17,代码来源:JettyHttpClientUtil.java

示例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;
}
 
开发者ID:teiid,项目名称:oreva,代码行数:21,代码来源:ContextTest.java

示例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);
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:18,代码来源:BookServiceJettyHttpClient.java

示例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);
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:19,代码来源:BookServiceJettyHttpClient.java

示例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);
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:11,代码来源:JettyHttpClientUtil.java

示例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);
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:10,代码来源:JettyHttpClientUtil.java

示例11: 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()};
}
 
开发者ID:AlgeFramework,项目名称:alge-core,代码行数:45,代码来源:SoapLoginUtil.java


注:本文中的org.eclipse.jetty.client.ContentExchange.setMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。