retrofit.client.ApacheClient Java Examples

The following examples show how to use retrofit.client.ApacheClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoSvcClientApiTest.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * This test creates a Video and attempts to add it to the video service
 * without logging in. The test checks to make sure that the request is
 * denied and the client redirected to the login page.
 * 
 * @throws Exception
 */
@Test
public void testRedirectToLoginWithoutAuth() throws Exception {
	ErrorRecorder error = new ErrorRecorder();

	VideoSvcApi videoService = new RestAdapter.Builder()
			.setClient(
					new ApacheClient(UnsafeHttpsClient.createUnsafeClient()))
			.setEndpoint(TEST_URL).setLogLevel(LogLevel.FULL)
			.setErrorHandler(error).build().create(VideoSvcApi.class);
	try {
		// This should fail because we haven't logged in!
		videoService.addVideo(video);

		fail("Yikes, the security setup is horribly broken and didn't require the user to login!!");

	} catch (Exception e) {
		// Ok, our security may have worked, ensure that
		// we got redirected to the login page
		assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, error.getError()
				.getResponse().getStatus());
	}
}
 
Example #2
Source File: VideoSvcClientApiTest.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * This test creates a Video and attempts to add it to the video service
 * without logging in. The test checks to make sure that the request is
 * denied and the client redirected to the login page.
 * 
 * @throws Exception
 */
@Test
public void testDenyVideoAddWithoutLogin() throws Exception {
	ErrorRecorder error = new ErrorRecorder();

	VideoSvcApi videoService = new RestAdapter.Builder()
			.setClient(
					new ApacheClient(UnsafeHttpsClient.createUnsafeClient()))
			.setEndpoint(TEST_URL).setLogLevel(LogLevel.FULL)
			.setErrorHandler(error).build().create(VideoSvcApi.class);
	try {
		// This should fail because we haven't logged in!
		videoService.addVideo(video);

		fail("Yikes, the security setup is horribly broken and didn't require the user to login!!");

	} catch (Exception e) {
		// Ok, our security may have worked, ensure that
		// we got redirected to the login page
		assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, error.getError()
				.getResponse().getStatus());
	}

	// Now, let's login and ensure that the Video wasn't added
	videoService.login("coursera", "changeit");
	
	// We should NOT get back the video that we added above!
	Collection<Video> videos = videoService.getVideoList();
	assertFalse(videos.contains(video));
}
 
Example #3
Source File: VideoSvc.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
public static synchronized VideoSvcApi init(String server, String user,
		String pass) {

	videoSvc_ = new SecuredRestBuilder()
			.setLoginEndpoint(server + VideoSvcApi.TOKEN_PATH)
			.setUsername(user)
			.setPassword(pass)
			.setClientId(CLIENT_ID)
			.setClient(
					new ApacheClient(new EasyHttpClient()))
			.setEndpoint(server).setLogLevel(LogLevel.FULL).build()
			.create(VideoSvcApi.class);

	return videoSvc_;
}
 
Example #4
Source File: RetrofitApacheClientBuilder.java    From hello-pinnedcerts with MIT License 5 votes vote down vote up
public Client.Provider build() {

        return new Client.Provider() {

            public Client get() {
                return new ApacheClient(httpClientBuilder.build());
            }
        };
    }
 
Example #5
Source File: BiliWallpaperSource.java    From muzei-bilibili with Apache License 2.0 4 votes vote down vote up
@Override
protected void onTryUpdate(int reason) throws RetryException {

    RestAdapter adapter = new RestAdapter.Builder()
            .setEndpoint("http://h.bilibili.com")
            .setExecutors(mExecutor, mMainExecutor)
            .setClient(new ApacheClient(mClient))
            .build();

    BiliWallpaperService service = adapter.create(BiliWallpaperService.class);
    List<Wallpaper> wallpapers = getWallpapers(service);
    if (wallpapers == null) {
        throw new RetryException();
    }
    if (wallpapers.isEmpty()) {
        Log.w(TAG, "No wallpapers returned from API.");
        scheduleUpdate(System.currentTimeMillis() + UPDATE_TIME_MILLIS);
        return;
    }
    wallpapers.remove(0); // first item is banner place holder
    final Wallpaper wallpaper = selectWallpaper(wallpapers);
    final Wallpaper selectedPaper = getDetail(service, wallpaper);
    if (selectedPaper == null) {
        Log.w(TAG, "No details returned for selected paper from API. id=" + wallpaper.il_id);
        throw new RetryException();
    }
    WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
    int minimumHeight = manager.getDesiredMinimumHeight();
    final Resolution pic = selectResolution(selectedPaper, minimumHeight);

    publishArtwork(new Artwork.Builder()
            .imageUri((Uri.parse(pic.il_file.replaceFirst("_m\\.", "_l\\."))))
            .title(pic.title)
            .token(String.valueOf(wallpaper.il_id))
            .byline(wallpaper.author_name + ", "
                    + DateFormat.format("yyyy-MM-dd", wallpaper.posttime * 1000)
                    + "\n" + wallpaper.type)
            .viewIntent(new Intent(Intent.ACTION_VIEW,
                    Uri.parse(wallpaper.author_url)))
            .build());
    scheduleUpdate(System.currentTimeMillis() + UPDATE_TIME_MILLIS);
}