Jersey(1.19.1) - Client API, Proxy Configuration

为 Jersey Client 设置代理,可以使用带有 ClientHandler 参数的构造方法创建 Client 实例。

public static void main(String[] args) {
    final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080));
    Client client = new Client(new URLConnectionClientHandler(new HttpURLConnectionFactory() {
        public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
            return (HttpURLConnection) url.openConnection(proxy);
        }
    }));

    WebResource resource = client.resource("http://example.com");
    ClientResponse response = resource.get(ClientResponse.class);
    System.out.println(String.format("%s %s",
            response.getStatusInfo().getStatusCode(),
            response.getStatusInfo().getReasonPhrase()));
}
时间: 2024-08-08 01:28:09

Jersey(1.19.1) - Client API, Proxy Configuration的相关文章

HBase Client API使用入门(二)---查询及过滤器

相关知识 创建表插入数据删除等见:http://www.cnblogs.com/wishyouhappy/p/3735077.html HBase API简介见:http://www.cnblogs.com/wishyouhappy/p/3753347.html 按行.列簇等查询 package wish.hbase; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org

Jersey(1.19.1) - Security with Http(s)URLConnection

With Http(s)URLConnection The support for security, specifically HTTP authentication and/or cookie management with Http(s)URLConnection is limited due to constraints in the API. There are currently no specific features or properties on the Client cla

Jersey(1.19.1) - Using filters

Filtering requests and responses can provide useful functionality that is hidden from the application layer of building and sending requests, and processing responses. Filters can read/modify the request URI, headers and entity or read/modify the res

ecshop /api/client/api.php、/api/client/includes/lib_api.php SQL Injection Vul

catalog 1. 漏洞描述 2. 漏洞触发条件 3. 漏洞影响范围 4. 漏洞代码分析 5. 防御方法 6. 攻防思考 1. 漏洞描述 ECShop存在一个盲注漏洞,问题存在于/api/client/api.php文件中,提交特制的恶意POST请求可进行SQL注入攻击,可获得敏感信息或操作数据库 http://sebug.net/vuldb/ssvid-21007 2. 漏洞触发条件 1. /api/client/api.php存在未过滤漏洞 2. 服务器magic_quote_gpc =

Jersey(1.19.1) - Uniform Interface Constraint

The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. It makes it very easy to interoperate with RESTful Web services and enables a developer to concisely and efficiently implement a reusable client-side s

Jersey(1.19.1) - XML Support

As you probably already know, Jersey uses MessageBodyWriters and MessageBodyReaders to parse incoming request and create outgoing responses. Every user can create its own representation but... this is not recommended way how to do things. XML is prov

Jersey(1.19.1) - Ease of use and reusing JAX-RS artifacts

Since a resource is represented as a Java type it makes it easy to configure, pass around and inject in ways that is not so intuitive or possible with other client-side APIs. The Jersey Client API reuses many aspects of the JAX-RS and the Jersey impl

mqtt client api: 阻塞API

fusesource版本:mqtt-client-1.11.jar下载地址:https://github.com/fusesource/mqtt-client fusesource提供三种mqtt client api: 阻塞API,基于Futur的API和回调API.其中,回调API是最复杂的也是性能最好的,另外两种均是对回调API的封装. 我们下面就简单介绍一下回调API的使用方法. 1 import org.fusesource.hawtbuf.Buffer; 2 import org.f

Memcached Java Client API详解

针对Memcached官方网站提供的java_memcached-release_2.0.1版本进行阅读分析,Memcached Java客户端lib库主要提供的调用类是SockIOPool和MemCachedClient?,关键类及方法整理说明如下. SockIOPool 这个类用来创建管理客户端和服务器通讯连接池,客户端主要的工作包括数据通讯.服务器定位.hash码生成等都是由这个类完成的. public static SockIOPool getInstance() 获得连接池的单态方法.