Package com.google.appengine.api.urlfetch

Examples of com.google.appengine.api.urlfetch.HTTPResponse


    {
      keyword = keyword + msgarr[i] + " ";
    }
    keyword = keyword.substring(0,keyword.length()-1);
   
    HTTPResponse response;
    try {
      response = api.search_public_timeline(fromJID, keyword);
      Common.StatusShowResp(fromJID, response,8,null,keyword);
    } catch (SocketTimeoutException e) {
      Common.sendMessage(fromJID, "连接饭否API超时,请重试");
View Full Code Here


    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    int msgarr_len = msgarr.length;
    if(msgarr_len == 1)
    {
      response = api.statuses_user_timeline(fromJID);
      Common.StatusShowResp(fromJID, response,6);
View Full Code Here

    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    if(msgarr.length == 1)                          //-u
    {
      response = api.account_verify_credentials(fromJID);
    }
    else if(msgarr.length == 2)                        //-u id
    {
      response = api.users_show(fromJID, msgarr[1]);
    }
    else
    {
      doHelp(fromJID,"u");
      return;
    }
   
    if(response.getResponseCode() == 200)
    {
      UserJSON jsonUser = new UserJSON(new String(response.getContent()));
      String message = null;
      message = jsonUser.getScreenName() + " (" + jsonUser.getId() + ") 的信息\n"
          + "头像地址: " + jsonUser.getProfileImageUrl()
          + "\n性别: " + jsonUser.getGender()
          + "\n自述: " + jsonUser.getDescription()
          + "\n地址: " + jsonUser.getLocation()
          + "\nTA关注的人数: " + String.valueOf(jsonUser.getFriendsCount())
          + "\n关注TA的人数: " + String.valueOf(jsonUser.getFollowersCount())
          + "\n收藏消息数: " + String.valueOf(jsonUser.getFavouritesCount())
          + "\n已发消息数: " + String.valueOf(jsonUser.getStatusesCount());
      if(jsonUser.getIsFollowing())
      {
        message = message + "\n\n您已经关注了" + jsonUser.getId();
      }
      else
      {
        message = message + "\n\n您没有关注" + jsonUser.getId();
      }
      Common.sendMessage(fromJID,message);
    }
    else if(response.getResponseCode() == 403)
    {
      Common.sendMessage(fromJID,"你没有通过这个用户的验证,无法查看TA的信息");
    }
    else if(response.getResponseCode() == 404)
    {
      Common.sendMessage(fromJID,"id所指定的用户不存在");
    }
    else
    {
      Common.sendMessage(fromJID,Common.getError(new String(response.getContent())));
      Common.log.info(Common.getStrJID(fromJID) + "-u: " + new String(response.getContent()));
    }
  }
View Full Code Here

            URL url = new URL(urlAsString);
            if (url.getHost() == null) {
                throw new FavIconException("The URL must at least contain a host");
            }
            try {
                HTTPResponse response = urlFetchService.fetch(url);
                if (response != null) {
                    URL finalUrl = url;
                    if (response.getFinalUrl() != null) {
                        finalUrl = response.getFinalUrl();
                    }
                    InputSource inputSource =
                        new InputSource(new ByteArrayInputStream(response.getContent()));
                    String iconUrl = favIconFinder.findFavIcon(inputSource, finalUrl);
                    if (iconUrl != null) {
                        return iconUrl;
                    }
                }
                try {
                    URI baseUri = url.toURI();
                    URI defaultFavIconUri = baseUri.resolve("/favicon.ico");
                    response = urlFetchService.fetch(defaultFavIconUri.toURL());
                    if (response == null || response.getResponseCode() != HttpServletResponse.SC_OK) {
                        return null;
                    }
                    else {
                        return defaultFavIconUri.toString();
                    }
View Full Code Here

     */
    private void imageUpload(UserModel userModel, String msg, String imagePath) throws Exception {

        URLFetchService fetchService =
                URLFetchServiceFactory.getURLFetchService();
        HTTPResponse fetchResponse = fetchService.fetch(new URL(imagePath));

        InputStream inputStream = new ByteArrayInputStream(fetchResponse.getContent());

        // 承認情報の生成
        ConfigurationBuilder cb = getConfigurationBuilder(userModel);

        Configuration conf = cb.setMediaProvider(MediaProvider.TWITTER.name()).build();
View Full Code Here

    private Media getPhotoMedia(String imageUrl) throws MalformedURLException, IOException {

        URLFetchService fetchService =
                URLFetchServiceFactory.getURLFetchService();
        HTTPResponse fetchResponse = fetchService.fetch(new URL(imageUrl));

        InputStream inputStream = new ByteArrayInputStream(fetchResponse.getContent());

        return new Media("photo by plucial", inputStream);

    }
View Full Code Here

    public void testReadResponseHeaders() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("test", "abc"));
        request.addHeader(new HTTPHeader("content-type", "text/plain"));
        HTTPResponse response = service.fetch(request);
        binding.readResponseHeaders(endpoint, exchange, response);
        assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
        assertEquals("abc", exchange.getOut().getHeader("test"));
        assertEquals("text/plain", exchange.getOut().getHeader("content-type"));
    }
View Full Code Here

    @Test
    public void testReadResponseBody() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl(), HTTPMethod.POST);
        request.setPayload("abc".getBytes());
        HTTPResponse response = service.fetch(request);
        binding.readResponseBody(null, exchange, response);
        assertEquals("abc", exchange.getOut().getBody(String.class));
    }
View Full Code Here

    @Test(expected = GHttpException.class)
    public void testFailureException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("code", "500"));
        HTTPResponse response = service.fetch(request);
        binding.readResponse(endpoint, exchange, response);
    }
View Full Code Here

    @Test
    public void testFailureNoException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test?throwExceptionOnFailure=false");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("code", "500"));
        HTTPResponse response = service.fetch(request);
        binding.readResponse(endpoint, exchange, response);
        assertEquals(500, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.urlfetch.HTTPResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.