当前位置: 首页>>代码示例>>Java>>正文


Java HttpUrlConnectorProvider类代码示例

本文整理汇总了Java中org.glassfish.jersey.client.HttpUrlConnectorProvider的典型用法代码示例。如果您正苦于以下问题:Java HttpUrlConnectorProvider类的具体用法?Java HttpUrlConnectorProvider怎么用?Java HttpUrlConnectorProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpUrlConnectorProvider类属于org.glassfish.jersey.client包,在下文中一共展示了HttpUrlConnectorProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ParaClient

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
/**
 * Default constructor.
 * @param accessKey app access key
 * @param secretKey app secret key
 */
public ParaClient(String accessKey, String secretKey) {
	this.accessKey = accessKey;
	this.secretKey = secretKey;
	if (StringUtils.length(secretKey) < 6) {
		logger.warn("Secret key appears to be invalid. Make sure you call 'signIn()' first.");
	}
	ClientConfig clientConfig = new ClientConfig();
	clientConfig.register(GenericExceptionMapper.class);
	clientConfig.register(new JacksonJsonProvider(ParaObjectUtils.getJsonMapper()));
	clientConfig.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround());
	SSLContext sslContext = SslConfigurator.newInstance().securityProtocol("TLSv1").createSSLContext();
	System.setProperty("https.protocols", "TLSv1");
	apiClient = ClientBuilder.newBuilder().
			sslContext(sslContext).
			withConfig(clientConfig).build();
}
 
开发者ID:Erudika,项目名称:para,代码行数:22,代码来源:ParaClient.java

示例2: patchTodoItem

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Test
public void patchTodoItem() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   final TodoItem expectedTodoItem = new TodoItem(1, "update titles", false);
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenReturn(expectedTodoItem);

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());   // 200 OK
   assertThat(response.readEntity(TodoItem.class)).isEqualTo(expectedTodoItem);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:23,代码来源:TodoItemResourceTest.java

示例3: patchTodoItemWithoutAuthentication

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Test
public void patchTodoItemWithoutAuthentication() {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.UNAUTHORIZED.getStatusCode());   // 401 Unauthorized
   verifyZeroInteractions(oaccBasicAuthenticator);
   verifyZeroInteractions(todoItemService);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:17,代码来源:TodoItemResourceTest.java

示例4: patchTodoItemWithoutAuthorization

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Test
public void patchTodoItemWithoutAuthorization() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new NotAuthorizedException("not authorized"));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.FORBIDDEN.getStatusCode());   // 403 Forbidden
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:21,代码来源:TodoItemResourceTest.java

示例5: patchTodoItemThatDoesNotExist

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Test
public void patchTodoItemThatDoesNotExist() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Resource " + todoItemId + " not found!"));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());   // 404 Not Found
   verifyZeroInteractions(oacc);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:22,代码来源:TodoItemResourceTest.java

示例6: patchTodoItemThatFailsValidation

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Test
public void patchTodoItemThatFailsValidation() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String blankTodoItem = fixture("fixtures/todoItem_blank.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Either title or completed (or both) is required."));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(blankTodoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(422);   // 422 Unprocessable Entity
   verifyZeroInteractions(oacc);
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:22,代码来源:TodoItemResourceTest.java

示例7: createClient

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
/**
 * Contains some workarounds for HTTP/JAX-RS/Jersey issues. See:
 *   https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/ClientProperties.html#SUPPRESS_HTTP_COMPLIANCE_VALIDATION
 *   https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/HttpUrlConnectorProvider.html#SET_METHOD_WORKAROUND
 */
@Override
public <T> T createClient(final Class<T> apiClass, final HostName hostName, final int port, final String pathPrefix, String scheme) {
    final UriBuilder uriBuilder = UriBuilder.fromPath(pathPrefix).host(hostName.s()).port(port).scheme(scheme);
    ClientBuilder builder = ClientBuilder.newBuilder()
            .property(ClientProperties.CONNECT_TIMEOUT, connectTimeoutMs)
            .property(ClientProperties.READ_TIMEOUT, readTimeoutMs)
            .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) // Allow empty PUT. TODO: Fix API.
            .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // Allow e.g. PATCH method.
            .property(ClientProperties.FOLLOW_REDIRECTS, true);
    if (sslContext != null) {
        builder.sslContext(sslContext);
    }
    if (hostnameVerifier != null) {
        builder.hostnameVerifier(hostnameVerifier);
    }
    if (userAgent != null) {
        builder.register((ClientRequestFilter) context ->
                context.getHeaders().put(HttpHeaders.USER_AGENT, Collections.singletonList(userAgent)));
    }
    final WebTarget target = builder.build().target(uriBuilder);
    // TODO: Check if this fills up non-heap memory with loaded classes.
    return WebResourceFactory.newResource(apiClass, target);
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:29,代码来源:JerseyJaxRsClientFactory.java

示例8: BaseRestClient

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
/**
     * 
     * @param serviceUrl
     */
    public BaseRestClient(String serviceUrl, final String proxyServer, final Integer proxyPort) {
        setBaseUrl(serviceUrl);
        if (StringUtils.isNotEmpty(proxyServer)) {
        	ConnectorProvider connectorprovider = new HttpUrlConnectorProvider() {
                private Proxy proxy;

                private void initializeProxy() {
                    int port = proxyPort != null ? proxyPort : 80;
                    proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, port));
                }

                public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
                    initializeProxy();
                    return (HttpURLConnection) url.openConnection(proxy);
                }
            };
            client = ClientBuilder.newBuilder().register(connectorprovider).build();
        } else {
            client = ClientBuilder.newClient();
        }
//        client.setConnectTimeout(5000);
//        client.setFollowRedirects(true);
        LOG.info("client for url " + baseUrl + ": proxy="
                + (proxyServer != null ? proxyServer + ":" + proxyPort : "none"));
    }
 
开发者ID:intuit,项目名称:Tank,代码行数:30,代码来源:BaseRestClient.java

示例9: getInvocationBuilder

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
protected Builder getInvocationBuilder(String url, Map<String, String> queryParameters) {
		ClientConfig clientConfig = new ClientConfig();
		if (getProxyAddress() != null) {
			clientConfig.connectorProvider(new ApacheConnectorProvider());
			clientConfig.property(ClientProperties.PROXY_URI, getProxyAddress());
		}
		Client client = ClientBuilder.newClient(clientConfig);
		client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
		WebTarget webTarget = client.target(url);

		if (queryParameters != null) {
			for (Map.Entry<String, String> queryParameter: queryParameters.entrySet())
//				webTarget = webTarget.queryParam(queryParameter.getKey(), queryParameter.getValue().replace("_", "_1").replace("%",  "_0"));
				webTarget = webTarget.queryParam(queryParameter.getKey(), queryParameter.getValue());
		}

		
		return webTarget.request(MediaType.APPLICATION_JSON).accept("application/ld+json").header("Authorization", getCloudTokenValue());
	}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:20,代码来源:OEClientReadOnly.java

示例10: makeHttpRequest

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Override
public HttpResponse makeHttpRequest(Entity entity, long startTime) {
    String method = request.getMethod();
    if ("PATCH".equals(method)) { // http://danofhisword.com/dev/2015/09/04/Jersey-Client-Http-Patch.html
        builder.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
    }
    Response resp;
    if (entity != null) {
        resp = builder.method(method, entity);
    } else {
        resp = builder.method(method);
    }
    byte[] bytes = resp.readEntity(byte[].class);
    long responseTime = getResponseTime(startTime);
    HttpResponse response = new HttpResponse(responseTime);
    response.setUri(getRequestUri());
    response.setBody(bytes);
    response.setStatus(resp.getStatus());
    for (NewCookie c : resp.getCookies().values()) {
        com.intuit.karate.http.Cookie cookie = new com.intuit.karate.http.Cookie(c.getName(), c.getValue());
        cookie.put(DOMAIN, c.getDomain());
        cookie.put(PATH, c.getPath());
        if (c.getExpiry() != null) {
            cookie.put(EXPIRES, c.getExpiry().getTime() + "");
        }
        cookie.put(SECURE, c.isSecure() + "");
        cookie.put(HTTP_ONLY, c.isHttpOnly() + "");
        cookie.put(MAX_AGE, c.getMaxAge() + "");
        response.addCookie(cookie);
    }
    for (Entry<String, List<Object>> entry : resp.getHeaders().entrySet()) {
        response.putHeader(entry.getKey(), entry.getValue());
    }
    return response;
}
 
开发者ID:intuit,项目名称:karate,代码行数:36,代码来源:JerseyHttpClient.java

示例11: config

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
private static ClientConfig config() {
	ClientConfig clientConfig = new ClientConfig();
	clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
	if (JwtClientProperties.isLoggingEnabled()) {
		clientConfig.register(new LoggingFilter(Logger.getAnonymousLogger(), true));
	}
	clientConfig.register(JacksonFeature.class);
	clientConfig.register(MultiPartFeature.class);
	return clientConfig;
}
 
开发者ID:PatternFM,项目名称:tokamak,代码行数:11,代码来源:RestClient.java

示例12: config

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
private static ClientConfig config() {
	ClientConfig clientConfig = new ClientConfig();
	clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
	clientConfig.register(HttpAuthenticationFeature.basicBuilder().build());
	clientConfig.register(JacksonFeature.class);
	if (JwtClientProperties.isLoggingEnabled()) {
		clientConfig.register(new LoggingFilter(Logger.getAnonymousLogger(), true));
	}
	return clientConfig;
}
 
开发者ID:PatternFM,项目名称:tokamak,代码行数:11,代码来源:TokensClient.java

示例13: containerStart

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Before
public void containerStart() throws Exception {
    String root = getWebappRoot();
    tomcat = new Tomcat();
    tomcat.setPort(8070);

    tomcat.setBaseDir(".");

    String contextPath = getWebappContext();;

    File rootF = new File(root);
    if (!rootF.exists()) {
        rootF = new File(".");
    }
    if (!rootF.exists()) {
        System.err.println("Can't find root app: " + root);
        System.exit(1);
    }

    tomcat.addWebapp(contextPath,  rootF.getAbsolutePath());
    tomcat.start();

    // Allow arbitrary HTTP methods so we can use PATCH
    c = ClientBuilder.newClient();
    c.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);

    checkLive(200);
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:29,代码来源:TomcatTestBase.java

示例14: setup

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@BeforeClass
public static void setup() {
	ClientConfig config = new ClientConfig();
	config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
	httpClient = ClientBuilder.newClient(config);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:7,代码来源:JsonApiResponseFilterTestBase.java

示例15: configureClient

import org.glassfish.jersey.client.HttpUrlConnectorProvider; //导入依赖的package包/类
@Override
protected void configureClient(final ClientConfig config) {
    config.getConfiguration().property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:5,代码来源:HttpPatchTest.java


注:本文中的org.glassfish.jersey.client.HttpUrlConnectorProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。