Java 类java.net.CookiePolicy 实例源码

项目:OftenPorter    文件:HttpUtil.java   
private static OkHttpClientImpl _getClient(CookieHandler cookieHandler) {

        OkHttpClientImpl okHttpClient = new OkHttpClientImpl();
        //okHttpClient.setConnectTimeout(SET_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
        //okHttpClient.setReadTimeout(SET_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
        //okHttpClient.setWriteTimeout(SET_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
        if (cookieHandler == null) {
            CookieManager cookieManager = new CookieManager();
            cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
            okHttpClient._setCookieHandler(cookieManager);
        } else {
            okHttpClient._setCookieHandler(cookieHandler);
        }

        return okHttpClient;
    }
项目:HTTP-Load-Generator    文件:HTTPInputGenerator.java   
/**
 * Constructs a new HTTPInputGenerator using a Lua generation script.
 * The Lua script must contain the onInit() and onCall(callnum) functions.
 * onCall(callnum) must return the HTTP request for a specific call with number callnum.
 * callnum begins at 1 (Lua convention) and increments for each call. It resets back to 1
 * if onCall returns nil.
 * @param scriptFile The url generator script.
 * @param randomSeed Seed for Lua random function.
 * @param timeout The http read timeout.
 */
public HTTPInputGenerator(File scriptFile, int randomSeed, int timeout) {
    OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    httpClientBuilder = httpClientBuilder.cookieJar(new JavaNetCookieJar(cookieManager));
    if (timeout > 0) {
        httpClientBuilder = httpClientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS)
            .connectTimeout(timeout, TimeUnit.MILLISECONDS);
    }
    httpClient = httpClientBuilder.build();
    if (scriptFile != null) {
        luaGlobals = JsePlatform.standardGlobals();
        //luaGlobals.get("require").call(LuaValue.valueOf("tools.descartes.httploadgenerator.http.lua.HTML"));
        LuaValue library = new LuaTable();
        library.set("getMatches", new GetMatches(htmlFunctions));
        library.set("extractMatches", new ExtractAllMatches(htmlFunctions));
        luaGlobals.set("html", library);
        luaGlobals.get("math").get("randomseed").call(LuaValue.valueOf(5));
        luaGlobals.get("dofile").call(LuaValue.valueOf(scriptFile.getAbsolutePath()));
    }
}
项目:jdk8u-jdk    文件:CookieHttpsClientTest.java   
void doClientSide() throws Exception {
    // Wait for server to get started.
    while (!serverReady) {
        Thread.sleep(50);
    }

    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }});

    URL url = new URL("https://localhost:" + serverPort +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:jdk8u-jdk    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:openjdk-jdk10    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:Library-Token-Automation    文件:LoginActivity.java   
Call post(Callback callback) throws IOException {
    OkHttpClient client = getUnsafeOkHttpClient();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    client.setCookieHandler(cookieManager);
    RequestBody requestBody = new FormEncodingBuilder()
            .add("user_id", NetId)
            .add("user_password", password)
            .build();
    Request request = new Request.Builder()
            .url("https://studentmaintenance.webapps.snu.edu.in/students/public/studentslist/studentslist/loginauth")
            .post(requestBody)
            .build();
    Call call = client.newCall(request);
    call.enqueue(callback);
    return call;
}
项目:openjdk9    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:beige-software    文件:HttpURLConnectionTest.java   
public void tstGetPost() throws Exception {
  String urlSource = "http://localhost:8080/beige-accounting-web/secure/main.jsp";
  String urlBase = urlSource.substring(0, urlSource.indexOf("secure") - 1);
  assertEquals("http://localhost:8080/beige-accounting-web", urlBase);
  CookieManager cookieManager = new CookieManager();
  cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
  CookieHandler.setDefault(cookieManager);
  URL url = new URL(urlSource);
  Map<String, Object> params = new HashMap<String, Object>();
  params.put("userName", "admin");
  params.put("userPass", "admin");
  params.put("authMethod", "form");
  params.put("urlBase", urlBase);
  params.put("authUrl", urlBase + "/secure/j_security_check");
  params.put("authUserName", "j_username");
  params.put("authUserPass", "j_password");
  params.put("urlSource", urlSource);
  tstAuthGet(url, params, cookieManager); //either Get or Post for test allowed
  urlSource = "http://localhost:8080/beige-accounting-web/secure/sendEntities";
  params.put("urlSource", urlSource);
  //url = new URL(urlSource);
  //tstAuthPost(url, params, cookieManager);
}
项目:ktball    文件:OkHttpClientManager.java   
private OkHttpClientManager()
{
    mOkHttpClient = new OkHttpClient();
    //cookie enabled
    mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
    mDelivery = new Handler(Looper.getMainLooper());
    mGson = new Gson();
    //just for test
    if (false)
    {
        mOkHttpClient.setHostnameVerifier(new HostnameVerifier()
        {
            @Override
            public boolean verify(String hostname, SSLSession session)
            {
                return true;
            }
        });
    }


}
项目:NewsMe    文件:OkHttpUtils.java   
private OkHttpUtils()
{
    mOkHttpClient = new OkHttpClient();
    //cookie enabled
    mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
    mDelivery = new Handler(Looper.getMainLooper());


    if (true)
    {
        mOkHttpClient.setHostnameVerifier(new HostnameVerifier()
        {
            @Override
            public boolean verify(String hostname, SSLSession session)
            {
                return true;
            }
        });
    }


}
项目:EgeYemekhaneMobil    文件:RetrofitManager.java   
private static void setup() {
    baseUrlManager = new BaseUrlManager(UrlConstants.SKS1_BASE);
    okHttpClient = new OkHttpClient();
    cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    okHttpClient.setCookieHandler(cookieManager);
    okHttpClient.setConnectTimeout(5, TimeUnit.SECONDS);
    okHttpClient.setReadTimeout(5, TimeUnit.SECONDS);
    okHttpClient.setWriteTimeout(5, TimeUnit.SECONDS);
    okHttpClient.interceptors().add(new HandlerResponseInterceptor());
    retrofit = new Retrofit.Builder()
            .baseUrl(baseUrlManager)
            .client(okHttpClient)
            .addConverterFactory(new DocumentConverterFactory())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    service = retrofit.create(ConnectionService.class);
}
项目:CodenvyDownload-DEPRECATED    文件:CodenvyClient.java   
public static void apiInit() {
    try {
        CookieManager cookieManager = new CookieManager();
        cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
        .cookieJar(new JavaNetCookieJar(cookieManager))
        .build();

        retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(okHttpClient)
        .addConverterFactory(GsonConverterFactory.create())
        .build();

        // Service setup
        apiService = retrofit.create(CodenvyApiService.class);
        } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:Codementor    文件:CoreServices.java   
public CoreServices(Context context) {
    this.context = context;

    // Storage
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    cookieStore = new PersistentCookieStore(context);

    // General
    userManager = new UserManager(sharedPrefs);
    errorHandler = new ErrorHandler(context);
    localBroadcastManager = LocalBroadcastManager.getInstance(context);

    // Network
    firebaseRef = new Firebase(Constants.FIREBASE_URL);
    okHttpClient = new OkHttpClient();
    okHttpClient.setCookieHandler(new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL));

    // Tasks
    codementorTasks = new CodementorTasks(okHttpClient);
    firebaseTasks = new FirebaseTasks(firebaseRef, codementorTasks, userManager);
}
项目:Avi    文件:NetworkApiFactory.java   
OkHttpClient provideHttpClient() {
    OkHttpClient.Builder builder = new OkHttpClient().newBuilder()
            .connectTimeout(30, TimeUnit.SECONDS);


    builder.addInterceptor(new KinopoiskRequestInterceptor());

    // Log http requests on debug
    if (BuildConfig.DEBUG) {
        //logging interceptor should be last interceptor in chain
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        builder.addInterceptor(loggingInterceptor);
    }

    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    builder.cookieJar(new JavaNetCookieJar(cookieManager));

    return builder.build();
}
项目:OkNet    文件:OkNet.java   
private OkNet() {
    OkHttpClient.Builder builder = client.newBuilder();

    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
    builder.cookieJar(new JavaNetCookieJar(cookieManager));
    builder.hostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    });

    builder.connectTimeout(10, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS);

    client = builder.build();
}
项目:autorest-clientruntime-for-java    文件:RestClient.java   
/**
 * Creates an instance of the builder with a base URL and 2 custom builders.
 *
 * @param httpClientBuilder the builder to build an {@link OkHttpClient}.
 * @param retrofitBuilder the builder to build a {@link Retrofit}.
 */
public Builder(OkHttpClient.Builder httpClientBuilder, Retrofit.Builder retrofitBuilder) {
    if (httpClientBuilder == null) {
        throw new IllegalArgumentException("httpClientBuilder == null");
    }
    if (retrofitBuilder == null) {
        throw new IllegalArgumentException("retrofitBuilder == null");
    }
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    customHeadersInterceptor = new CustomHeadersInterceptor();
    // Set up OkHttp client
    this.httpClientBuilder = httpClientBuilder
            .cookieJar(new JavaNetCookieJar(cookieManager))
            .readTimeout(60, TimeUnit.SECONDS)
            .addInterceptor(new RequestIdHeaderInterceptor())
            .addInterceptor(new BaseUrlHandler());
    this.retrofitBuilder = retrofitBuilder;
    this.loggingInterceptor = new LoggingInterceptor(LogLevel.NONE);
}
项目:jdk8u_jdk    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:Emojier-Andriod    文件:HttpManager.java   
private HttpManager() {
    this.mOkHttpClient = new OkHttpClient();
    //cookie enabled
    mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));

    mDelivery = new Handler(Looper.getMainLooper());
    final int sdk = Build.VERSION.SDK_INT;
    if (sdk >= 23) {
        GsonBuilder gsonBuilder = new GsonBuilder()
                .excludeFieldsWithModifiers(
                        Modifier.FINAL,
                        Modifier.TRANSIENT,
                        Modifier.STATIC);
        mGson = gsonBuilder.create();
    } else {
        mGson = new Gson();
    }

}
项目:lookaside_java-1.8.0-openjdk    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:stayawhile-android    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    android.webkit.CookieManager.getInstance().setAcceptCookie(true);
    CookieManager cookieManager = new CookieManager(new PersistentCookieStore(getApplicationContext()), CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    new APITask(new APICallback() {
        @Override
        public void r(String result) {
            if (result.length() != 0) {
                Intent queueList = new Intent(MainActivity.this, QueueListActivity.class);
                startActivity(queueList);
            } else {
                setContentView(R.layout.activity_main);
                Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
                setSupportActionBar(toolbar);
            }
        }
    }).execute("method", "userData");
}
项目:XKCDownload-deprecated    文件:Main.java   
public static void main(String[] args) {
    AppVars.setAppVars();
    Preferences.load();
    if (Preferences.useSystemLookAndFeel()) {
        useSystemLookAndFeel(true);
    }
    CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
    if (Preferences.useUserProxy()) {
        ComicUtil.setProxy(Preferences.getProxyAddress(), Preferences.getProxyPort(), Preferences.getProxyUsername(), Preferences.getProxyEncryptedPassword());
    }
    ComicUtil.getNewestComic();

    EventQueue.invokeLater(() -> {
        MainFrame frame = new MainFrame("XKCDownload");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    });
}
项目:motu    文件:CookieStoreHolder.java   
public static void initCookieManager() {

        CookieHandler cookieHandler = CookieHandler.getDefault();

        if (cookieHandler == null) {
            // CookieStore cookieStore = CookieStoreHolder.initInMemoryCookieStore();
            // CookieManager cm = new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
            CookieManager cm = new CookieManager();
            cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
            CookieHandler.setDefault(cm);
        }
        // else {
        // CookieStoreHolder.initInMemoryCookieStore();
        // }

    }
项目:V2EX-Android    文件:LoginService.java   
public LoginService() {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    mPersistentCookieStore = new PersistentCookieStore(MyApplication.getContextObject());
    mClient = new OkHttpClient.Builder()
            .cookieJar(new CustomCookieJar(new CookieManager(mPersistentCookieStore, CookiePolicy.ACCEPT_ALL)))
            .readTimeout(12, TimeUnit.SECONDS)
            .addInterceptor(htmlInterceptor)
            .addInterceptor(loggingInterceptor)
            .build();

    mGson = new GsonBuilder()
            .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
            .serializeNulls()
            .create();
}
项目:eid-applet    文件:ControllerTest.java   
@Test
public void controllerKioskMode() throws Exception {
    // setup
    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    // make sure that the session cookies are passed during conversations
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    this.servletHolder.setInitParameter("Kiosk", "true");

    // operate
    controller.run();

    // verify
    LOG.debug("verify...");
}
项目:stack-overflow-android    文件:HttpClientModule.java   
@Provides
@Singleton
OkHttpClient provideOkHttpClient(Context context) {
    OkHttpClient client = new OkHttpClient();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    client.setCookieHandler(cookieManager);

    try {
        Cache cache = new Cache(context.getCacheDir(), 10 * 1024 * 1024); // 10 MiB
        client.setCache(cache);
    } catch (IOException e) {
        Toast.makeText(context, "Cannot create cache for http responses", Toast.LENGTH_SHORT).show();
    }

    return client;
}
项目:AndroidGeek    文件:OkHttpClientManager.java   
private OkHttpClientManager() {
    mOkHttpClient = new OkHttpClient();
    // cookie enabled
    mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
    mDelivery = new Handler(Looper.getMainLooper());
    mGson = new Gson();

    /*just for test !!!*/
    mOkHttpClient.setHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    });

}
项目:Groover    文件:AppController.java   
@Override
public void onCreate() {
    super.onCreate();

    RealmConfiguration configuration = new RealmConfiguration.Builder(this).build();
    Realm.setDefaultConfiguration(configuration);

    sInstance = this;
    context = getApplicationContext();
    cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    client = new OkHttpClient.Builder()
            .cookieJar(new JavaNetCookieJar(cookieManager))
            .connectTimeout(5, TimeUnit.SECONDS)
            .build();

    Stetho.initialize(
            Stetho.newInitializerBuilder(this)
                    .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                    .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
                    .build());
}
项目:OkDownload    文件:OkHttpClientManager.java   
public static OkHttpClient getsInstance() {
    if (sInstance == null) {
        synchronized (OkHttpClientManager.class) {
            if (sInstance == null) {
                sInstance = new com.squareup.okhttp.OkHttpClient();
                // cookie enabled
                sInstance.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
                // timeout reading data from the host
                sInstance.setReadTimeout(15, TimeUnit.SECONDS);
                // timeout connection host
                sInstance.setConnectTimeout(20, TimeUnit.SECONDS);
            }
        }
    }
    return sInstance;
}
项目:snu-data-usage    文件:LoginActivity.java   
Call post(Callback callback) throws IOException {
    OkHttpClient client = getUnsafeOkHttpClient();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    client.setCookieHandler(cookieManager);
    RequestBody requestBody = new FormEncodingBuilder()
            .add("user_id", NetId)
            .add("user_password", password)
            .build();
    Request request = new Request.Builder()
            .url("https://studentmaintenance.webapps.snu.edu.in/students/public/studentslist/studentslist/loginauth")
            .post(requestBody)
            .build();
    Call call = client.newCall(request);
    call.enqueue(callback);
    return call;
}
项目:JPluf    文件:AbstractGeneralServiceTest.java   
@Before
public void init() {
    trash = new ArrayList<T>();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder//
            .setDateFormat("yyyy-MM-dd HH:mm:ss");//
    Gson gson = gsonBuilder.create();

    RestAdapter restAdapter = new RestAdapter.Builder()
            // تعیین مبدل داده
            .setConverter(new GsonConverter(gson))
            // تعیین کنترل کننده خطا
            .setErrorHandler(new PErrorHandler())
            // تعیین آدرس سایت مورد نظر
            .setEndpoint(TestSettings.getApiURL())
            // ایجاد یک نمونه
            .build();
    // ایجاد سرویس‌ها
    this.userService = restAdapter.create(IRUserService.class);
    createTService(restAdapter);
}
项目:JPluf    文件:PProfileAdminTest.java   
@Before
public void createService() {
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder//
            .setDateFormat("yyyy-MM-dd HH:mm:ss");//
    Gson gson = gsonBuilder.create();

    RestAdapter restAdapter = new RestAdapter.Builder()//
            .setConverter(new GsonConverter(gson))//
            // تعیین کنترل کننده خطا
            .setErrorHandler(new PErrorHandler())
            // تعیین آدرس سایت مورد نظر
            .setEndpoint(API_URL)
            // ایجاد یک نمونه
            .build();
    this.profileAdmin = restAdapter.create(IRProfileAdministrator.class);
    this.usr = restAdapter.create(IRUserService.class);
}
项目:JPluf    文件:PUserDaoRetrofitTest.java   
public PUserDaoRetrofitTest() {
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder//
            .setDateFormat("yyyy-MM-dd HH:mm:ss");//
    Gson gson = gsonBuilder.create();

    RestAdapter restAdapter = new RestAdapter.Builder()//
            .setConverter(new GsonConverter(gson))//
            .setErrorHandler(new PErrorHandler())//
            .setEndpoint(API_URL)//
            .build();
    this.userSerivece = restAdapter.create(IRUserService.class);

    userDao = new PUserDaoRetrofit();
    userDao.setUserService(userSerivece);
}
项目:JPluf    文件:ContentServiceTest.java   
@Before
public void init() {
    trash = new ArrayList<PContent>();

    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder//
            .setDateFormat("yyyy-MM-dd HH:mm:ss");//
    Gson gson = gsonBuilder.create();

    RestAdapter restAdapter = new RestAdapter.Builder()
            // تعیین مبدل داده
            .setConverter(new GsonConverter(gson))
            // تعیین کنترل کننده خطا
            .setErrorHandler(new PErrorHandler())
            // تعیین آدرس سایت مورد نظر
            .setEndpoint(TestSettings.getApiURL())
            // ایجاد یک نمونه
            .build();
    // ایجاد سرویس‌ها
    this.userService = restAdapter.create(IRUserService.class);
    this.contentService = restAdapter.create(IContentService.class);
}
项目:infobip-open-jdk-8    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:jdk8u-dev-jdk    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:TuChongAndroid    文件:RequestManager.java   
private static RequestQueue newRequestQueue() {
        VolleyLog.DEBUG = true;
        RequestQueue requestQueue = new RequestQueue(openCache(), new BasicNetwork(new HurlStack()));
        requestQueue.start();
        CookieManager manager = new CookieManager(new SimpleCookieStore(), CookiePolicy.ACCEPT_ORIGINAL_SERVER);
        CookieHandler.setDefault(manager);

//        String userAgent = "volley/0";
//        try {
//            String packageName = BaseApplication.getBaseApplication().getPackageName();
//            PackageInfo info = BaseApplication.getBaseApplication().getPackageManager().getPackageInfo(packageName, 0);
//            userAgent = packageName + "/" + info.versionCode;
//        } catch (PackageManager.NameNotFoundException e) {}
//        android.net.http.AndroidHttpClient  httpClient = AndroidHttpClient.newInstance(userAgent);
//        HttpStack httpStack = new OwnHttpClientStack(httpClient);
//        RequestQueue requestQueue = Volley.newRequestQueue(BaseApplication.getBaseApplication(),
//                httpStack);


        return requestQueue;
    }
项目:BlueBoard    文件:OkHttpClientManager.java   
public static OkHttpClient getsInstance() {
    if (sInstance == null) {
        synchronized (OkHttpClientManager.class) {
            if (sInstance == null) {
                sInstance = new com.squareup.okhttp.OkHttpClient();
                // cookie enabled
                sInstance.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
                // timeout reading data from the host
                sInstance.setReadTimeout(15, TimeUnit.SECONDS);
                // timeout connection host
                sInstance.setConnectTimeout(20, TimeUnit.SECONDS);
            }
        }
    }
    return sInstance;
}
项目:OLD-OpenJDK8    文件:CookieHttpClientTest.java   
CookieHttpClientTest() throws Exception {
    /* start the server */
    ss = new ServerSocket(0);
    (new Thread(this)).start();

    URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
项目:sensable-android    文件:SensableUser.java   
public SensableUser(SharedPreferences sharedPreferences, Context context) {
    this.sharedPreferences = sharedPreferences;
    this.context = context;

    mUser = new User();
    loggedIn = readUserFromPreferences();

    //TODO: Remove this once API doesn't use cookies
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    RestAdapter restAdapter = new RestAdapter.Builder()
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setEndpoint("http://sensable.io")
            .build();
    service = restAdapter.create(SensableService.class);

}
项目:android-rest-example    文件:MyApplication.java   
@Override
public void onCreate() {
    super.onCreate();

    // cookie store
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    // init cache for http responses
    try {
        File httpCacheDir = new File(getApplicationContext().getCacheDir(), "http");
        long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
        HttpResponseCache.install(httpCacheDir, httpCacheSize);
    } catch(IOException e){
        Log.i(TAG, "HTTP response cache installation failed:" + e);
    }
}