{"id":22462464,"url":"https://github.com/commonjava/jhttpc","last_synced_at":"2025-08-02T05:31:40.798Z","repository":{"id":2198519,"uuid":"45161599","full_name":"Commonjava/jhttpc","owner":"Commonjava","description":"httpclient wrapper that handles per-site SSL configuration, flexible storage of various site-related passwords, and connection handling ","archived":false,"fork":false,"pushed_at":"2024-08-15T02:48:38.000Z","size":232,"stargazers_count":0,"open_issues_count":2,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-15T12:53:47.013Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Commonjava.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-29T05:09:19.000Z","updated_at":"2024-08-15T02:48:41.000Z","dependencies_parsed_at":"2024-08-09T13:30:35.404Z","dependency_job_id":null,"html_url":"https://github.com/Commonjava/jhttpc","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commonjava%2Fjhttpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commonjava%2Fjhttpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commonjava%2Fjhttpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Commonjava%2Fjhttpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Commonjava","download_url":"https://codeload.github.com/Commonjava/jhttpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228439518,"owners_count":17920025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T09:09:49.348Z","updated_at":"2024-12-06T09:10:44.139Z","avatar_url":"https://github.com/Commonjava.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"#jHTTPc - A Httpclient Wrapper\n\njHTTPc is a wrapper around Apache HttpClient that simplifies use cases related to server-side embedding, such as PEM-oriented SSL configuration. Using jHTTPc, you don't have to work directly with KeyStores, and you can specify an independent SSL configuration for each host to which your server connects. You can use PEM files on the system, or even PEM-encoded strings stored by some other mechanism. This also makes it easier to support user-driven configuration of these hosts via a server UI (or even REST), since keystore management happens behind the scenes. \n\n* [Basics](#basics)\n* [Proxies](#proxies)\n* [Basic Authentication](#basic_auth)\n* [Other Goodies](#etc)\n* [Custom Authenticators](#authenticators)\n\n##Basics\n\u003ca name=\"basics\"\u003e\u003c/a\u003e\n\nIt's very easy to start using:\n\n```\nSiteConfigBuilder siteBuilder = new SiteConfigBuilder( \"test\", \"http://www.somesite.com\" )\n                  .withKeyCertPem( FileUtils.readFileToString( \"/path/to/client.pem\" ) )\n                  .withServerCertPem( FileUtils.readFileToString( \"/path/to/my-server.pem\" ) );\n\nSiteConfig site = siteBuilder.build();\n\nMemoryPasswordManager passwords = new MemoryPasswordManager();\npasswords.bind( \"my K3y password!\", site, PasswordType.KEY );\n\nHttpFactory factory = new HttpFactory( passwords );\n\nHttpClient client = factory.createClient( site );\n[...]\n```\n\n##Proxies\n\u003ca name=\"proxies\"\u003e\u003c/a\u003e\n\nIf you need to use a proxy server (with authentication), you can add the following:\n\n```\nsiteBuilder.withProxyHost( \"some.proxy.host\" ).withProxyPort( 8080 ).withProxyUser( \"someuser\" );\n\nSiteConfig site = siteBuilder.build();\n\npasswords.bind( \"somepassword\", siteConfig, PasswordType.PROXY );\n```\n\n##Basic Authentication\n\u003ca name=\"basic_auth\"\u003e\u003c/a\u003e\n\nIf you need good old basic authentication (in addition to client SSL?!), you can specify that as well:\n\n```\nsiteBuilder.withUser( \"someuser\" );\n\nSiteConfig site = siteBuilder.build();\n\npasswords.bind( \"somepassword\", siteConfig, PasswordType.USER );\n```\n\n##Other Goodies\n\u003ca name=\"etc\"\u003e\u003c/a\u003e\n\nThere are other configurations you can specify on a per-site basis as well:\n\n```\nsiteBuilder.withMaxConnections( 20 )\n           .withRequestTimeoutSeconds( 30 )\n           .withTrustType( ServerTrustType.TRUST_SELF_SIGNED );\n```\n\n##Custom Authenticators\n\u003ca name=\"authenticators\"\u003e\u003c/a\u003e\n\nIf you need some other authentication mechanism, you can implement that by extending `ClientAuthenticator` and passing in your own authenticator instance via the `HttpFactory(ClientAuthenticator)` constructor. For instance, a simple OAuth bearer token authenticator might look like this:\n\n```\npublic class OAuth20BearerTokenAuthenticator\n        extends ClientAuthenticator\n{\n\n    private static final String AUTHORIZATION_HEADER = \"Authorization\";\n\n    private static final String BEARER_FORMAT = \"Bearer %s\";\n\n    private final String token;\n\n    public OAuth20BearerTokenAuthenticator( final String token )\n    {\n        this.token = token;\n    }\n\n    @Override\n    public HttpClientBuilder decorateClientBuilder( final HttpClientBuilder builder )\n            throws JHttpCException\n    {\n        final Header header = new BasicHeader( AUTHORIZATION_HEADER, String.format( BEARER_FORMAT, token ) );\n        return builder.setDefaultHeaders( Collections.\u003cHeader\u003e singleton( header ) );\n    }\n\n}\n\n```\n\nThen, simply construct the `HttpFactory` using the new authenticator:\n\n```\nHttpFactory factory = new HttpFactory( new OAuth20BearerTokenAuthenticator( token ) );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonjava%2Fjhttpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommonjava%2Fjhttpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonjava%2Fjhttpc/lists"}