/** * Sets the given header on the give service instance. * * @param <T> any service class * @param service service class instance * @param key HTTP header key * @param values HTTP header values * @return given service instance, with given header set */ public <T> T header(final T service, final String key, final Object... values) { WebClient.client(service).header(key, values); return service; }
/** * Sets the given header on the give service instance. * * @param <T> any service class * @param service service class instance * @param key HTTP header key * @param values HTTP header values * @return given service instance, with given header set */ public <T> T header(final T service, final String key, final Object... values) { WebClient.client(service).header(key, values); return service; }
private void loadCookies(Exchange exchange, Client client, CookieHandler cookieHandler) throws IOException { if (cookieHandler != null) { for (Map.Entry<String, List<String>> cookie : cookieHandler.loadCookies(exchange, client.getCurrentURI()).entrySet()) { if (cookie.getValue().size() > 0) { client.header(cookie.getKey(), cookie.getValue()); } } } }
protected <T>T getService(Class<T> clazz, String endpoint) { if(services.containsKey(clazz)) return (T)services.get(clazz); if(restUrl == null) new IllegalStateException("GeoFence URL not set"); synchronized(services) { // T proxy = JAXRSClientFactory.create(restUrl, clazz, username, password, null); T proxy = JAXRSClientFactory.create(restUrl+"/"+endpoint, clazz); String authorizationHeader = "Basic " + Base64Utility.encode((username+":"+password).getBytes()); WebClient.client(proxy).header("Authorization", authorizationHeader); // WebClient.client(proxy).accept("text/xml"); services.put(clazz, proxy); return proxy; } }
/** * HTTP Basic Authentication configuration over CXF {@link ClientConfiguration}. * * @see <a href= "http://cxf.apache.org/docs/jax-rs-client-api.html#JAX-RSClientAPI-ClientsandAuthentication">CXF Clients and Authentication</a> */ @Override public void configureAuthentication(Object api) { if (isCredentialsSet()) { final String authorizationHeader = String.format("Basic %s", Base64Utility.encode(String.format("%s:%s", this.username, this.password).getBytes())); LOGGER.info("Credentials set for user {}", username); WebClient.client(api).header("Authorization", authorizationHeader); } else { LOGGER.warn("Credentials not set because username or password are empty."); } }
@Override protected void applyHeaders(ServiceContext<?> context, Object serviceClient) { Collection<String> headerNames = context.getHeaderNames(); if (!headerNames.isEmpty()) { Client webClient = WebClient.client(serviceClient); for (String headerName : headerNames) { webClient.header(headerName, context.getHeader(headerName)); } } }
@Override protected void applyHeaders(ServiceContext<?> context, Object serviceClient) { Collection<String> headerNames = context.getHeaderNames(); if (!headerNames.isEmpty()) { Client webClient = WebClient.client(serviceClient); for (String headerName : headerNames) { webClient.header(headerName, context.getHeader(headerName)); } } }
@Test(expected = BadRequestException.class) public void testJwsJwkPlainTextHMacHttpHeadersModified() throws Exception { String address = "https://localhost:" + PORT + "/jwsjwkhmacHttpHeaders"; BookStore bs = createJwsBookStore(address, null, true, true); WebClient.client(bs).header("Modify", "true"); bs.echoText("book"); } @Test
protected ProxyConnectorService getProxyConnectorService() { ProxyConnectorService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", ProxyConnectorService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Authorization", authorizationHeader ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); return service; }
public void doTestAddCollectionOfBooksWithProxy(boolean addHeader) { String address = "http://localhost:" + PORT; MultipartStore client = JAXRSClientFactory.create(address, MultipartStore.class); if (addHeader) { WebClient.client(client).header("Content-Type", "multipart/mixed;type=application/xml"); } List<Book> books = new ArrayList<>(); books.add(new Book("CXF 1", 1L)); books.add(new Book("CXF 2", 2L)); List<Book> books2 = addHeader ? client.addBooks(books) : client.addBooksWithoutHeader(books); assertNotSame(books, books2); assertEquals(2, books2.size()); assertEquals(books.get(0).getId(), books2.get(0).getId()); assertEquals(books.get(1).getId(), books2.get(1).getId()); }
protected RemoteRepositoriesService getRemoteRepositoriesService() { RemoteRepositoriesService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", RemoteRepositoriesService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Authorization", authorizationHeader ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); return service; }
protected UserService getUserService( String authzHeader ) { UserService service = JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/redbackServices/", UserService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); // for debuging purpose WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 3000000L ); if ( authzHeader != null ) { WebClient.client( service ).header( "Authorization", authzHeader ); } return service; }
protected ManagedRepositoriesService getManagedRepositoriesService() { ManagedRepositoriesService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", ManagedRepositoriesService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Authorization", authorizationHeader ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); return service; }
protected RepositoriesService getRepositoriesService() { RepositoriesService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", RepositoriesService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Authorization", authorizationHeader ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); return service; }
protected RepositoryGroupService getRepositoryGroupService() { RepositoryGroupService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", RepositoryGroupService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Authorization", authorizationHeader ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); return service; }
protected SearchService getSearchService() { SearchService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", SearchService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Authorization", authorizationHeader ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); return service; }
protected RoleManagementService getRoleManagementService( String authzHeader ) { RoleManagementService service = JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/redbackServices/", RoleManagementService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client( service ).header( "Referer", "http://localhost:" + port ); // for debuging purpose WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 3000000L ); if ( authzHeader != null ) { WebClient.client( service ).header( "Authorization", authzHeader ); } return service; }
@Test public void checkRemoteConnectivityFail() throws Exception { RemoteRepositoriesService service = getRemoteRepositoriesService(); WebClient.client( service ).header( "Authorization", authorizationHeader ); try { RemoteRepository repo = getRemoteRepository(); repo.setUrl( "http://localhost:8956" ); service.addRemoteRepository( repo ); assertThat( service.checkRemoteConnectivity( repo.getId() ) ).isFalse(); } finally { service.deleteRemoteRepository( "id-new" ); } }
@Test public void runtimeInfoService() throws Exception { RuntimeInfoService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaUiServices/", RuntimeInfoService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); WebClient.client(service).header("Referer","http://localhost"); ApplicationRuntimeInfo applicationRuntimeInfo = service.getApplicationRuntimeInfo( "en" ); assertEquals( System.getProperty( "expectedVersion" ), applicationRuntimeInfo.getVersion() ); assertFalse( applicationRuntimeInfo.isJavascriptLog() ); assertTrue( applicationRuntimeInfo.isLogMissingI18n() ); } }
private void doTestSubresource(BookStoreJaxrsJaxws proxy) throws Exception { BookSubresource bs = proxy.getBookSubresource("378"); Book b = bs.getTheBook2("CXF ", "in ", "Acti", "on ", "- 3", "7", "8"); assertEquals(378, b.getId()); assertEquals("CXF in Action - 378", b.getName()); WebClient.client(bs).reset().header("N4", "- 4"); b = bs.getTheBook2("CXF ", "in ", "Acti", "on ", null, "7", "8"); assertEquals(378, b.getId()); assertEquals("CXF in Action - 478", b.getName()); }