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


Java ContentExchange类代码示例

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


ContentExchange类属于org.eclipse.jetty.client包,在下文中一共展示了ContentExchange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: compareHeaders

import org.eclipse.jetty.client.ContentExchange; //导入依赖的package包/类
private void compareHeaders(HttpExchange httpConn, String checkHeaders) throws Exception {
    ContentExchange exch = (ContentExchange) httpConn;

    String[] headerList = checkHeaders.split(Strings.NL);
    for (String header : headerList) {
        String[] nameValue = header.split(":", 2);

        if (nameValue[0].equals("responseCode")) {
            if (Integer.parseInt(nameValue[1].trim()) != exch.getResponseStatus()) {
                error("Incorrect Response Status",
                        String.format("%d expected %s", exch.getResponseStatus(), nameValue[1]));
            }
        } else {
            if (!nameValue[1].trim().equals(exch.getResponseFields().getStringField(nameValue[0]))) {
                error("Incorrect Response Header", String.format("%s expected %s", exch.getResponseFields()
                        .getStringField(nameValue[0]), nameValue[1].trim()));
            }
        }
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:21,代码来源:RestServiceScriptsIT.java

示例8: compareHeaders

import org.eclipse.jetty.client.ContentExchange; //导入依赖的package包/类
private void compareHeaders (HttpExchange httpConn, String checkHeaders) throws Exception {
    ContentExchange exch = (ContentExchange)httpConn;
    
    String[] headerList = checkHeaders.split("\n");
    for (String header : headerList) {
        String[] nameValue = header.split(":", 2);
        
        if (nameValue[0].equals("responseCode")) {
            assertEquals ("Headers Response", Integer.parseInt(nameValue[1].trim()), 
                    exch.getResponseStatus());
        } else {
            assertEquals ("Headers check", nameValue[1].trim(),
                    exch.getResponseFields().getStringField(nameValue[0]));
        }
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:17,代码来源:RestServiceFilesIT.java

示例9: 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

示例10: 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

示例11: assertCallSuccess

import org.eclipse.jetty.client.ContentExchange; //导入依赖的package包/类
@Test
public void assertCallSuccess() throws Exception {
    ContentExchange actual = sentRequest("{\"string\":\"test\",\"integer\":1}");
    Assert.assertThat(actual.getResponseStatus(), Is.is(200));
    Assert.assertThat(actual.getResponseContent(), Is.is("{\"string\":\"test_processed\",\"integer\":\"1_processed\"}"));
    Mockito.verify(caller).call("test");
    Mockito.verify(caller).call(1);
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:9,代码来源:RestfulServerTest.java

示例12: assertCallFailure

import org.eclipse.jetty.client.ContentExchange; //导入依赖的package包/类
@Test
public void assertCallFailure() throws Exception {
    ContentExchange actual = sentRequest("{\"string\":\"test\",\"integer\":\"invalid_number\"}");
    Assert.assertThat(actual.getResponseStatus(), Is.is(500));
    Assert.assertThat(actual.getResponseContent(), StringStartsWith.startsWith("java.lang.NumberFormatException"));
    Mockito.verify(caller).call("test");
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:8,代码来源:RestfulServerTest.java

示例13: 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

示例14: 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

示例15: stringProperty

import org.eclipse.jetty.client.ContentExchange; //导入依赖的package包/类
@Test
public void stringProperty() throws Exception {
  ContentExchange exchange = sendRequest("Persons(1)/Name", format);
  if (format.equals(JSONVERBOSE))
    assertThat(exchange.getResponseContent(), containsString("\"Susan Summer\""));
  else
    assertThat(exchange.getResponseContent(), containsString(">Susan Summer<"));
}
 
开发者ID:teiid,项目名称:oreva,代码行数:9,代码来源:AddressBookJettyHttpClientTest.java


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