本文整理汇总了Java中org.glassfish.jersey.client.proxy.WebResourceFactory.newResource方法的典型用法代码示例。如果您正苦于以下问题:Java WebResourceFactory.newResource方法的具体用法?Java WebResourceFactory.newResource怎么用?Java WebResourceFactory.newResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.jersey.client.proxy.WebResourceFactory
的用法示例。
在下文中一共展示了WebResourceFactory.newResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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);
}
示例3: 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;
}
示例4: 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();
}
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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();
}
}
}
示例9: 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();
}
}
}
示例10: 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);
}
示例11: 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());
}
示例12: 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();
}
示例13: 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);
}
示例14: 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()));
}
示例15: messagesApi
import org.glassfish.jersey.client.proxy.WebResourceFactory; //导入方法依赖的package包/类
public MessagesService messagesApi() {
return WebResourceFactory.newResource(MessagesService.class, target);
}