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


Java ContentResponse类代码示例

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


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

示例1: parseSendirResponse

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
private void parseSendirResponse(final ContentResponse response) {

        final String responseContent = response.getContentAsString();

        if ((responseContent == null) || responseContent.isEmpty()) {
            throw new CommunicationException("Empty response received!");
        }

        if (responseContent.startsWith(SENDIR_SUCCESS)) {
            return;
        }

        if (responseContent.startsWith(SENDIR_BUSY)) {
            throw new DeviceBusyException("Device is busy!");
        }

        if ((response.getStatus() != HttpStatus.OK_200) || responseContent.startsWith(SENDIR_ERROR)) {
            throw new CommunicationException(String.format("Failed to send IR code: %s", responseContent));
        }
    }
 
开发者ID:alexmaret,项目名称:openhab-binding-zmote,代码行数:21,代码来源:ZMoteV2Client.java

示例2: decodeException

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
@Override
public RpcCallException decodeException(ContentResponse response) throws RpcCallException {
    try {
        if (response != null) {
            byte[] data = response.getContent();
            ProtobufRpcResponse pbResponse = new ProtobufRpcResponse(data);
            String error = pbResponse.getErrorMessage();
            if (error != null) {
                return RpcCallException.fromJson(error);
            }
        }
    } catch (Exception ex) {
        logger.warn("Caught exception decoding protobuf response exception", ex);
        throw new RpcCallException(RpcCallException.Category.InternalServerError,
                RpcCallExceptionDecoder.exceptionToString(ex));
    }
    return null;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:19,代码来源:ProtobufRpcCallExceptionDecoder.java

示例3: decodeException

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
@Override
public RpcCallException decodeException(ContentResponse response) throws RpcCallException {
    try {
        if (response != null) {
            JsonObject json = (JsonObject) new JsonParser().parse(response.getContentAsString());
            JsonElement error = json.get("error");
            if (error != null) {
                return RpcCallException.fromJson(error.toString());
            }
        }
    } catch (Exception ex) {
        logger.warn("Caught exception decoding protobuf response exception", ex);
        throw new RpcCallException(RpcCallException.Category.InternalServerError,
                RpcCallExceptionDecoder.exceptionToString(ex));
    }
    return null;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:18,代码来源:JsonRpcCallExceptionDecoder.java

示例4: callSynchronous

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
public String callSynchronous(JsonArray params, OrangeContext orangeContext)
        throws RpcCallException {
    HttpClientWrapper clientWrapper = loadBalancer.getHttpClientWrapper();
    HttpRequestWrapper balancedPost = clientWrapper.createHttpPost(this);

    //set custom headers
    if (orangeContext != null) {
        orangeContext.getProperties().forEach(balancedPost::setHeader);
    }

    balancedPost.setHeader("Content-type", TYPE_JSON);
    //TODO: fix: Temporary workaround below until go services are more http compliant
    balancedPost.setHeader("Connection", "close");
    JsonRpcRequest jsonRequest = new JsonRpcRequest(null, methodName, params);
    String json = jsonRequest.toString();
    balancedPost.setContentProvider(new StringContentProvider(json));

    logger.debug("Sending request of size {}", json.length());
    ContentResponse rpcResponse = clientWrapper.execute(balancedPost,
            new JsonRpcCallExceptionDecoder(), orangeContext);
    String rawResponse = rpcResponse.getContentAsString();
    logger.debug("Json response from the service: {}", rawResponse);

    return JsonRpcResponse.fromString(rawResponse).getResult().getAsString();
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:26,代码来源:RpcClient.java

示例5: initialize

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
private void initialize() {
    httpResponse = mock(ContentResponse.class);
    when(httpResponse.getHeaders()).thenReturn(new HttpFields());
    when(httpResponse.getStatus()).thenReturn(200);
    try {
        RpcEnvelope.Response.Builder responseBuilder = RpcEnvelope.Response.newBuilder();
        responseBuilder.setServiceMethod("Test.test");
        if (requestsFail) {
            RpcCallException callException = new RpcCallException(
                    RpcCallException.Category.InternalServerError, "requests fail!");
            responseBuilder.setError(callException.toJson().toString());
        }
        RpcEnvelope.Response rpcResponse = responseBuilder.build();
        byte[] responseHeader = rpcResponse.toByteArray();
        byte[] payload = FrameworkTest.Foobar.newBuilder().build().toByteArray();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        out.write(Ints.toByteArray(responseHeader.length));
        out.write(responseHeader);
        out.write(Ints.toByteArray(payload.length));
        out.write(payload);
        out.flush();
        when(httpResponse.getContent()).thenReturn(out.toByteArray());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:27,代码来源:RpcClientIntegrationTest.java

示例6: setup

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    HttpClient httpClient = mock(HttpClient.class);
    response = mock(ContentResponse.class);
    when(response.getStatus()).thenReturn(200);
    when(response.getContentAsString()).thenReturn(healthInfo);
    HttpFields headers = new HttpFields();
    headers.add(CONSUL_INDEX, "42");
    when(response.getHeaders()).thenReturn(headers);
    Request request = mock(Request.class);
    when(httpClient.newRequest(anyString())).thenReturn(request);
    when(request.send()).thenReturn(response);
    props = new ServiceProperties();
    props.addProperty(ServiceProperties.REGISTRY_SERVER_KEY, "localhost:1234");
    worker = new RegistrationMonitorWorker(httpClient, props);
    worker.setServiceName("foobar");
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:18,代码来源:RegistrationMonitorWorkerIntegrationTest.java

示例7: getQRCode

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
/**
 * 获取二维码
 *
 * @return 二维码图片的内容
 * @throws InterruptedException
 *             if send thread is interrupted
 * @throws ExecutionException
 *             if execution fails
 * @throws TimeoutException
 *             if send times out
 */
// 登录流程1:获取二维码
public byte[] getQRCode() throws InterruptedException, ExecutionException, TimeoutException {
	LOGGER.debug("开始获取二维码");

	ContentResponse response = httpClient.newRequest(ApiURL.GET_QR_CODE.getUrl()).timeout(10, TimeUnit.SECONDS)
			.method(HttpMethod.GET).agent(ApiURL.USER_AGENT).send();
	byte[] imageBytes = response.getContent();
	List<HttpCookie> httpCookieList = httpClient.getCookieStore().get(response.getRequest().getURI());
	for (HttpCookie httpCookie : httpCookieList) {
		if ("qrsig".equals(httpCookie.getName())) {
			this.qrsig = httpCookie.getValue();
			break;
		}
	}

	LOGGER.debug("二维码已获取");

	return imageBytes;
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:31,代码来源:SmartQQClient.java

示例8: verifyQRCode

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
private String verifyQRCode() throws InterruptedException, ExecutionException, TimeoutException {
	LOGGER.debug("等待扫描二维码");

	// 阻塞直到确认二维码认证成功
	while (true) {
		sleep(1);
		ContentResponse response = get(ApiURL.VERIFY_QR_CODE, hash33(qrsig));
		String result = response.getContentAsString();
		if (result.contains("成功")) {
			for (String content : result.split("','")) {
				if (content.startsWith("http")) {
					LOGGER.info("正在登录,请稍后");

					return content;
				}
			}
		} else if (result.contains("已失效")) {
			LOGGER.info("二维码已失效");
			return null;
		}
	}
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:23,代码来源:SmartQQClient.java

示例9: sendMessageToGroup

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
/**
 * 发送群消息
 *
 * @param groupId
 *            群id
 * @param messageContentElements
 *            消息内容
 * @param font
 *            消息字体
 * @throws InterruptedException
 *             if send thread is interrupted
 * @throws ExecutionException
 *             if execution fails
 * @throws TimeoutException
 *             if send times out
 */
public void sendMessageToGroup(long groupId, List<MessageContentElement> messageContentElements, Font font)
		throws InterruptedException, ExecutionException, TimeoutException {
	LOGGER.debug("开始发送群消息");

	JsonObject r = new JsonObject();
	r.addProperty("group_uin", groupId);
	r.addProperty("content", MessageContentElementUtil.toContentJson(messageContentElements, font)); // 注意这里虽然格式是Json,但是实际是String
	r.addProperty("face", 573);
	r.addProperty("clientid", Client_ID);
	r.addProperty("msg_id", MESSAGE_ID++);
	r.addProperty("psessionid", psessionid);

	ContentResponse response = postWithRetry(
			httpsChatMessage ? ApiURL.SEND_MESSAGE_TO_GROUP_HTTPS : ApiURL.SEND_MESSAGE_TO_GROUP, r);
	checkSendMsgResult(response);
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:33,代码来源:SmartQQClient.java

示例10: sendMessageToDiscuss

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
/**
 * 发送讨论组消息
 *
 * @param discussId
 *            讨论组id
 * @param messageContentElements
 *            消息内容
 * @param font
 *            消息字体
 * @throws InterruptedException
 *             if send thread is interrupted
 * @throws ExecutionException
 *             if execution fails
 * @throws TimeoutException
 *             if send times out
 */
public void sendMessageToDiscuss(long discussId, List<MessageContentElement> messageContentElements, Font font)
		throws InterruptedException, ExecutionException, TimeoutException {
	LOGGER.debug("开始发送讨论组消息");

	JsonObject r = new JsonObject();
	r.addProperty("did", discussId);
	r.addProperty("content", MessageContentElementUtil.toContentJson(messageContentElements, font)); // 注意这里虽然格式是Json,但是实际是String
	r.addProperty("face", 573);
	r.addProperty("clientid", Client_ID);
	r.addProperty("msg_id", MESSAGE_ID++);
	r.addProperty("psessionid", psessionid);

	ContentResponse response = postWithRetry(
			httpsChatMessage ? ApiURL.SEND_MESSAGE_TO_DISCUSS_HTTPS : ApiURL.SEND_MESSAGE_TO_DISCUSS, r);
	checkSendMsgResult(response);
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:33,代码来源:SmartQQClient.java

示例11: sendMessageToFriend

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
/**
 * 发送消息
 *
 * @param friendId
 *            好友id
 * @param messageContentElements
 *            消息内容
 * @param font
 *            消息字体
 * @throws InterruptedException
 *             if send thread is interrupted
 * @throws ExecutionException
 *             if execution fails
 * @throws TimeoutException
 *             if send times out
 */
public void sendMessageToFriend(long friendId, List<MessageContentElement> messageContentElements, Font font)
		throws InterruptedException, ExecutionException, TimeoutException {
	LOGGER.debug("开始发送消息");

	JsonObject r = new JsonObject();
	r.addProperty("to", friendId);
	r.addProperty("content", MessageContentElementUtil.toContentJson(messageContentElements, font)); // 注意这里虽然格式是Json,但是实际是String
	r.addProperty("face", 573);
	r.addProperty("clientid", Client_ID);
	r.addProperty("msg_id", MESSAGE_ID++);
	r.addProperty("psessionid", psessionid);

	ContentResponse response = postWithRetry(
			httpsChatMessage ? ApiURL.SEND_MESSAGE_TO_FRIEND_HTTPS : ApiURL.SEND_MESSAGE_TO_FRIEND, r);
	checkSendMsgResult(response);
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:33,代码来源:SmartQQClient.java

示例12: getResponseJson

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
private static JsonElement getResponseJson(ContentResponse response) {
	if (response.getStatus() != 200) {
		throw new ResponseException(response.getStatus());
	}
	JsonElement json = GsonUtil.jsonParser.parse(response.getContentAsString());
	Integer retCode = json.getAsJsonObject().get("retcode").getAsInt();
	if (retCode == null || retCode != 0) {
		if (retCode != null && retCode == 103) {
			LOGGER.error("请求失败,Api返回码[103]。你需要进入http://w.qq.com,检查是否能正常接收消息。如果可以的话点击[设置]->[退出登录]后查看是否恢复正常");
			throw new ApiException(
					"请求失败,Api返回码[103]。你需要进入http://w.qq.com,检查是否能正常接收消息。如果可以的话点击[设置]->[退出登录]后查看是否恢复正常");
		} else {
			throw new ApiException(retCode);
		}
	}
	return json;
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:18,代码来源:SmartQQClient.java

示例13: getBalance

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
public Balance getBalance(String accountId)
{
  Balance balance = null;
  try
  {
    ContentResponse response = httpClient.POST(BurstcoinFaucetProperties.getWalletServer() + "/burst?requestType=getBalance&account=" + accountId)
      .timeout(BurstcoinFaucetProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
      .send();

    if(!response.getContentAsString().contains("errorDescription"))
    {
      balance = objectMapper.readValue(response.getContentAsString(), Balance.class);
      LOG.info("received balance from accountId: '" + accountId + "' in '" + balance.getRequestProcessingTime() + "' ms");
    }
    else
    {
      LOG.error("Error: " + response.getContentAsString());
    }
  }
  catch(Exception e)
  {
    LOG.warn("Error: Failed to 'getBalance' for accountId '" + accountId + "' : " + e.getMessage(), e);
  }
  return balance;
}
 
开发者ID:de-luxe,项目名称:burstcoin-faucet,代码行数:26,代码来源:NetworkComponent.java

示例14: getTime

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
public Timestamp getTime()
{
  Timestamp timestamp = null;
  try
  {
    ContentResponse response = httpClient.POST(BurstcoinFaucetProperties.getWalletServer() + "/burst?requestType=getTime")
      .timeout(BurstcoinFaucetProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
      .send();

    if(!response.getContentAsString().contains("errorDescription"))
    {
      timestamp = objectMapper.readValue(response.getContentAsString(), Timestamp.class);
      LOG.info("received timestamp: '" + timestamp.getTime() + "' in '" + timestamp.getRequestProcessingTime() + "' ms");
    }
    else
    {
      LOG.error("Error: " + response.getContentAsString());
    }
  }
  catch(Exception e)
  {
    LOG.warn("Error: Failed to 'getTime':" + e.getMessage(), e);
  }
  return timestamp;
}
 
开发者ID:de-luxe,项目名称:burstcoin-faucet,代码行数:26,代码来源:NetworkComponent.java

示例15: getMiningInfo

import org.eclipse.jetty.client.api.ContentResponse; //导入依赖的package包/类
public MiningInfo getMiningInfo()
{
  MiningInfo result = null;
  try
  {
    ContentResponse response;
    response = httpClient.newRequest(BurstcoinFaucetProperties.getWalletServer() + "/burst?requestType=getMiningInfo")
      .timeout(BurstcoinFaucetProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
      .send();

    result = objectMapper.readValue(response.getContentAsString(), MiningInfo.class);
  }
  catch(TimeoutException timeoutException)
  {
    LOG.warn("Unable to get mining info caused by connectionTimeout, currently '" + (BurstcoinFaucetProperties.getConnectionTimeout() / 1000)
             + " sec.' try increasing it!");
  }
  catch(Exception e)
  {
    LOG.trace("Unable to get mining info from wallet: " + e.getMessage());
  }
  return result;
}
 
开发者ID:de-luxe,项目名称:burstcoin-faucet,代码行数:24,代码来源:NetworkComponent.java


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