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


Java WebResourceFactory类代码示例

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


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

示例1: getRegistryClient

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
private RegistryEndpoints getRegistryClient(ImageRef imageRef) {
	if (!proxyClients.containsKey(imageRef.getRegistryUrl())) {

		ObjectMapper mapper = new ObjectMapper();
		mapper.registerModule(new JavaTimeModule());

		Client client = ClientBuilder.newClient()
				.register(new JacksonJaxbJsonProvider(mapper, new Annotations[] {Annotations.JACKSON}))
				.register(JacksonFeature.class);
		String auth = config.getAuthFor(imageRef.getRegistryName());
		if (auth != null) {
			String[] credentials = new String(Base64.getDecoder().decode(auth), StandardCharsets.UTF_8).split(":");
			client.register(HttpAuthenticationFeature.basicBuilder().credentials(credentials[0], credentials[1]));
		}
		WebTarget webTarget = client.target(imageRef.getRegistryUrl());
		proxyClients.put(imageRef.getRegistryUrl(), WebResourceFactory.newResource(RegistryEndpoints.class, webTarget));
	}
	return proxyClients.get(imageRef.getRegistryUrl());
}
 
开发者ID:swissquote,项目名称:carnotzet,代码行数:20,代码来源:DockerRegistry.java

示例2: generateClient

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
public <T> T generateClient(Class<T> resource) {
    Client clientToUse = client != null
            ? client
            : ClientBuilder.newClient();

    MultivaluedMap<String, Object> headerArg = new MultivaluedHashMap<>(headers);

    WebTarget webTarget = clientToUse.target(uri);
    if (apiPath != null) {
        webTarget = webTarget.path(apiPath);
    }
    if(throwExceptionForErrors) {
        webTarget.register(ClientErrorResponseFilter.class);
    }
    webTarget.register(RequestIdClientFilter.class);
    webTarget.register(ClientNameFilter.class);
    if (logging) {
        webTarget.register(ClientLogFilter.class);
    }

    return WebResourceFactory.newResource(resource, webTarget, false, headerArg, cookies, new Form());
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:23,代码来源:StubGenerator.java

示例3: createClient

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的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

示例4: grantToken

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
public AccessTokenResponse grantToken(){
    WebTarget target = client.target(config.getServerUrl());

    Form form = new Form()
            .param("grant_type", "password")
            .param("username", config.getUsername())
            .param("password", config.getPassword());

    if (config.isPublicClient()) {
        form.param("client_id", config.getClientId());
    } else {
        target.register(new BasicAuthFilter(config.getClientId(), config.getClientSecret()));
    }

    TokenService tokenService = WebResourceFactory.newResource(TokenService.class, target);

    AccessTokenResponse response = tokenService.grantToken(config.getRealm(), form.asMap());

    defineCurrentToken(response);
    return response;
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:22,代码来源:TokenManager.java

示例5: refreshToken

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
public AccessTokenResponse refreshToken(){
	WebTarget target = client.target(config.getServerUrl());

    Form form = new Form()
            .param("grant_type", "refresh_token")
            .param("refresh_token", currentToken.getRefreshToken());

    if (config.isPublicClient()) {
        form.param("client_id", config.getClientId());
    } else {
        target.register(new BasicAuthFilter(config.getClientId(), config.getClientSecret()));
    }

    TokenService tokenService = WebResourceFactory.newResource(TokenService.class, target);

    try {
        AccessTokenResponse response = tokenService.refreshToken(config.getRealm(), form.asMap());
        defineCurrentToken(response);
        return response;
    } catch (BadRequestException e) {
        return grantToken();
    }
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:24,代码来源:TokenManager.java

示例6: createProxies

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
private void createProxies(String url) {
    WebTarget target = client.target(url);
    playerResource = WebResourceFactory.newResource(PlayerResource.class, target);
    metadataResource = WebResourceFactory.newResource(MetadataResource.class, target);
    technologyResource = WebResourceFactory.newResource(TechnologyResource.class, target);
    buildingResource = WebResourceFactory.newResource(BuildingResource.class, target);
    planetResource = WebResourceFactory.newResource(PlanetResource.class, target);
    constructionSiteResource = WebResourceFactory.newResource(ConstructionSiteResource.class, target);
    flightResource = WebResourceFactory.newResource(FlightResource.class, target);
    researchResource = WebResourceFactory.newResource(ResearchResource.class, target);
    shipResource = WebResourceFactory.newResource(ShipResource.class, target);
    shipInConstructionResource = WebResourceFactory.newResource(ShipInConstructionResource.class, target);
    systemResource = WebResourceFactory.newResource(SystemResource.class, target);
    telescopeResource = WebResourceFactory.newResource(TelescopeResource.class, target);
    eventResource = WebResourceFactory.newResource(EventResource.class, target);
    fightResource = WebResourceFactory.newResource(FightResource.class, target);
    rootResource = WebResourceFactory.newResource(RootResource.class, target);
    websocketResource = WebResourceFactory.newResource(WebsocketResource.class, target);
}
 
开发者ID:phxql,项目名称:restwars,代码行数:20,代码来源:RestWarsClient.java

示例7: createStub

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
@Override
public <T> T createStub(Class<T> interfaceClass) {
	ServiceUrlProvider serviceUrlProvider = context.getServiceUrlProvider();
	String serviceUrl = serviceUrlProvider.getUrl();

	WebTarget target = client.target(serviceUrl);
	return WebResourceFactory.newResource(interfaceClass, target);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:9,代码来源:JerseyActionStubFactory.java

示例8: setUp

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
@Before
public void setUp() {
    repo.deleteAll();

    String baseUrl = "http://localhost:" + port;
    WebTarget webTarget = JerseyClientBuilder.newClient().target(baseUrl);
    smurfResource = WebResourceFactory.newResource(SmurfResource.class, webTarget);
}
 
开发者ID:cegeka,项目名称:ng2boot,代码行数:9,代码来源:SmurfResourceBaseIntegrationTest.java

示例9: htmlProxy

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
@GET
@Path("v1/legacy/tenant/{tenantName}/application/{applicationName}/environment/{environmentName}/region/{regionName}/instance/{instanceName}/service/{serviceIdentifier}/{apiParams: .*}")
@Produces(MediaType.TEXT_HTML)
public String htmlProxy(@PathParam("tenantName") String tenantName,
        @PathParam("applicationName") String applicationName,
        @PathParam("environmentName") String environmentName,
        @PathParam("regionName") String regionName,
        @PathParam("instanceName") String instanceName,
        @PathParam("serviceIdentifier") String identifier,
        @PathParam("apiParams") String apiParams) {
    ServiceModel model = new ServiceModel(getModelConfig(tenantName, applicationName, environmentName, regionName, instanceName));
    Service s = model.getService(identifier);
    int requestedPort = s.matchIdentifierWithPort(identifier);
    Client client = ClientBuilder.newClient();
    try {
        final StringBuilder uriBuffer = new StringBuilder("http://").append(s.host).append(':').append(requestedPort).append('/')
                .append(apiParams);
        addQuery(uriBuffer);
        String uri = uriBuffer.toString();
        WebTarget target = client.target(uri);
        HtmlProxyHack resource = WebResourceFactory.newResource(HtmlProxyHack.class, target);
        return resource.proxy();
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:29,代码来源:StateResource.java

示例10: getModelConfig

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
protected ModelResponse getModelConfig(String tenant, String application, String environment, String region, String instance) {
    Client client = ClientBuilder.newClient();
    try {
        WebTarget target = client.target("http://" + host + ":" + restApiPort + "/");

        ConfigClient resource = WebResourceFactory.newResource(ConfigClient.class, target);

        return resource.getServiceModel(tenant, application, environment, region, instance);
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:15,代码来源:StateResource.java

示例11: getHealthClient

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
protected HealthClient getHealthClient(String apiParams, Service s, int requestedPort, Client client) {
    final StringBuilder uriBuffer = new StringBuilder("http://").append(s.host).append(':').append(requestedPort).append('/')
            .append(apiParams);
    addQuery(uriBuffer);
    WebTarget target = client.target(uriBuffer.toString());
    return WebResourceFactory.newResource(HealthClient.class, target);
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:8,代码来源:StateResource.java

示例12: testNormalJerseyProxy

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
@Test
public void testNormalJerseyProxy()
{
    WebTarget webTarget = getWebTarget();

    final Hello hello = WebResourceFactory.newResource(Hello.class, webTarget);
    assertNotNull(hello.getHome());
}
 
开发者ID:orbit,项目名称:orbit-rest-client,代码行数:9,代码来源:RestClientTest.java

示例13: getUserToken

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
public String getUserToken(String reefssid) throws Exception {
    WebTarget target = client.target(IElementsUserApi.CLOUD_URL);

    // create a new client proxy for the BooksResource
    IElementsUserApi elementsCloud = WebResourceFactory.newResource(IElementsUserApi.class, target);

    Response response = elementsCloud.connect("gigaset", reefssid);
    Cookie usercookie = response.getCookies().get("usertoken");
    return usercookie.getValue();
}
 
开发者ID:hkuhn42,项目名称:openhab2.elements,代码行数:11,代码来源:ElementsClient.java

示例14: setMode

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
public void setMode(String baseId, String mode, String usertoken) {
    WebTarget target = client.target(IElementsUserApi.CLOUD_URL);
    IElementsUserApi elementsCloud = WebResourceFactory.newResource(IElementsUserApi.class, target);
    IntrusionSettings settings = new IntrusionSettings();
    settings.setActiveMode(mode.toLowerCase());

    BaseConfig config = new BaseConfig();
    config.setIntrusionSettings(settings);

    elementsCloud.setIntrusionSettings(baseId, usertoken, config);
}
 
开发者ID:hkuhn42,项目名称:openhab2.elements,代码行数:12,代码来源:ElementsClient.java

示例15: createKraken

import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入依赖的package包/类
/**
 * Creates a Jersey client proxy for the Kraken API.
 */
@Provides
public Kraken createKraken(TwitchApiSettings settings) {
  return WebResourceFactory.newResource(Kraken.class,
      JerseyClientBuilder.newClient().target(settings.getTwitchApiRoot())
          .queryParam("client_id", settings.getTwitchClientId()));
}
 
开发者ID:OsuCelebrity,项目名称:OsuCelebrity,代码行数:10,代码来源:OsuCelebrityModule.java


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