Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ public class DefaultClient implements IClient, IHttpConstants{
private IAuthorizationStrategy strategy;
private IAuthorizationClient authClient;

@Deprecated
public DefaultClient(URL baseUrl, ISSLCertificateCallback sslCertCallback){
this(baseUrl, null, sslCertCallback);
this(baseUrl, null, sslCertCallback, null);
}

/*
* Testing constructor
*/
DefaultClient(URL baseUrl, IHttpClient httpClient, ISSLCertificateCallback sslCertCallback){
public DefaultClient(URL baseUrl, IHttpClient httpClient, ISSLCertificateCallback sslCertCallback, IResourceFactory factory){
this.baseUrl = baseUrl;
client = httpClient != null ? httpClient : newIHttpClient(sslCertCallback);
factory = new ResourceFactory(this);
this.factory = factory;
if(this.factory != null) {
this.factory.setClient(this);
}
openShiftVersion = System.getProperty(SYSTEM_PROP_OPENSHIFT_API_VERSION, null);
kubernetesVersion = System.getProperty(SYSTEM_PROP_K8E_API_VERSION, null);
authClient = new AuthorizationClientFactory().create(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public <T extends IResource> T stub(String kind, String name) {
return stub(kind, name, null);
}

@Override
public void setClient(IClient client) {
this.client = client;
}



}
59 changes: 59 additions & 0 deletions src/main/java/com/openshift/restclient/ClientBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.openshift.restclient;

import java.net.MalformedURLException;
import java.net.URL;

import com.openshift.internal.restclient.DefaultClient;
import com.openshift.internal.restclient.ResourceFactory;

/**
* Builder to create IClient instances.
* @author jeff.cantrill
*
*/
public class ClientBuilder {

private String baseUrl;
private ISSLCertificateCallback sslCertificateCallback;
private IResourceFactory resourceFactory;

public ClientBuilder(String baseUrl) {
this.baseUrl = baseUrl;
}

public ClientBuilder sslCertificateCallback(ISSLCertificateCallback callback) {
this.sslCertificateCallback = callback;
return this;
}

public ClientBuilder resourceFactory(IResourceFactory factory) {
this.resourceFactory = factory;
return this;
}

public IClient build() {
try {
ISSLCertificateCallback sslCallback = defaultIfNull(this.sslCertificateCallback, new NoopSSLCertificateCallback());
IResourceFactory factory = defaultIfNull(resourceFactory, new ResourceFactory(null));
return new DefaultClient(new URL(this.baseUrl), null, sslCallback, factory);
} catch (MalformedURLException e) {
throw new OpenShiftException(e, "");
}
}

private <T> T defaultIfNull(T value, T aDefault) {
if(value != null)
return value;
return aDefault;
}
}
13 changes: 4 additions & 9 deletions src/main/java/com/openshift/restclient/ClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
******************************************************************************/
package com.openshift.restclient;

import java.net.MalformedURLException;
import java.net.URL;

import com.openshift.internal.restclient.DefaultClient;

/**
* Factory class for creating clients to an OpenShift server
*
* @author Jeff Cantrill
*/
@Deprecated
public final class ClientFactory {

/**
Expand All @@ -32,10 +29,8 @@ public final class ClientFactory {
* if the baseURL is malformed
*/
public final IClient create(String baseUrl, ISSLCertificateCallback sslCertCallback){
try {
return new DefaultClient(new URL(baseUrl), sslCertCallback);
} catch (MalformedURLException e) {
throw new OpenShiftException(e, "Malformed URL '%s'", baseUrl);
}
return new ClientBuilder(baseUrl)
.sslCertificateCallback(sslCertCallback)
.build();
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/openshift/restclient/IResourceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface IResourceFactory {
*/
<T extends IResource> T create(String response) ;

@Deprecated
IResource create(String response, boolean strict) ;

/**
Expand All @@ -50,6 +51,7 @@ public interface IResourceFactory {
*/
<T extends IResource> T create(InputStream input) ;

@Deprecated
IResource create(InputStream input, boolean strict) ;

/**
Expand All @@ -60,6 +62,7 @@ public interface IResourceFactory {
*/
<T extends IResource> T create(String version, String kind);

@Deprecated
IResource create(String version, String kind, boolean strict);

/**
Expand All @@ -70,6 +73,19 @@ public interface IResourceFactory {
*/
<T extends IResource> T stub(String kind, String name);

/**
* Stub out the given resource kind using a version determined by the factory
* @param kind
* @param name
* @param namespace
* @return
*/
<T extends IResource> T stub(String kind, String name, String namespace);

/**
* The client given to resources when they are created
* @param client
*/
void setClient(IClient client);

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public void setUp() throws Exception{

private void givenAClient() throws MalformedURLException{
httpClient = mock(IHttpClient.class);
client = new DefaultClient(baseUrl, httpClient, null);
factory = new ResourceFactory(client);
factory = new ResourceFactory(null);
client = new DefaultClient(baseUrl, httpClient, null, factory);
}

private void givenAPodList(){
Expand Down