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
6 changes: 1 addition & 5 deletions src/main/java/com/openshift/client/IUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ public interface IUser extends IOpenShiftResource {
public String getPassword();

public String getServer();

public String getAuthKey();

public String getAuthIV();


public IOpenShiftConnection getConnection();

public IDomain createDomain(String id) throws OpenShiftException;
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/openshift/internal/client/UserResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ public int getConsumedGears() {
return consumedGears;
}

public String getAuthKey() {
// TODO Auto-generated method stub
return null;
}

public String getAuthIV() {
// TODO Auto-generated method stub
return null;
}

public IDomain createDomain(String id) throws OpenShiftException {
Assert.notNull(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
******************************************************************************/
package com.openshift.internal.client.httpclient;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
Expand All @@ -22,7 +21,6 @@
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.MessageFormat;
import java.util.Map;

import javax.net.ssl.HostnameVerifier;
Expand Down Expand Up @@ -101,10 +99,6 @@ public String get(URL url) throws HttpClientException, SocketTimeoutException {
connection = createConnection(username, password, authKey, authIV, userAgent, url);

return StreamUtils.readToString(connection.getInputStream());
} catch (FileNotFoundException e) {
e.printStackTrace();
throw new NotFoundException(
MessageFormat.format("Could not find resource \"{0}\"", url.toString()), e);
} catch (IOException e) {
throw createException(e, connection);
} finally {
Expand Down Expand Up @@ -168,9 +162,6 @@ protected String write(String data, String requestMethod, URL url)
StreamUtils.writeTo(data.getBytes(), connection.getOutputStream());
}
return StreamUtils.readToString(connection.getInputStream());
} catch (FileNotFoundException e) {
throw new NotFoundException(
MessageFormat.format("Could not find resource {0}", url.toString()), e);
} catch (IOException e) {
throw createException(e, connection);
} finally {
Expand All @@ -189,7 +180,7 @@ private HttpClientException createException(IOException ioe, HttpURLConnection c
throws SocketTimeoutException {
try {
int responseCode = connection.getResponseCode();
String errorMessage = StreamUtils.readToString(connection.getErrorStream());
String errorMessage = createErrorMessage(connection);
switch (responseCode) {
case STATUS_INTERNAL_SERVER_ERROR:
return new InternalServerErrorException(errorMessage, ioe);
Expand All @@ -209,6 +200,20 @@ private HttpClientException createException(IOException ioe, HttpURLConnection c
}
}

protected String createErrorMessage(HttpURLConnection connection) throws IOException {
StringBuilder builder = new StringBuilder("Connection to ")
.append(connection.getURL());
String reason = connection.getResponseMessage();
if (!StringUtils.isEmpty(reason)) {
builder.append(": ").append(reason);
}
String errorMessage = StreamUtils.readToString(connection.getErrorStream());
if (!StringUtils.isEmpty(errorMessage)) {
builder.append(", ").append(errorMessage);
}
return builder.toString();
}


private boolean isHttps(URL url) {
return "https".equals(url.getProtocol());
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/openshift/client/fakes/HttpServerFake.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class HttpServerFake {

public static final int DEFAULT_PORT = 1234;
private static final String DEFAULT_STATUSLINE = "HTTP/1.1 200 OK\n\n";
private static final String DEFAULT_STATUSLINE = "HTTP/1.1 200 OK\n";

private ExecutorService executor;
private int port;
Expand Down Expand Up @@ -134,6 +134,7 @@ public void run() {

protected void writeResponseHeader(OutputStream outputStream) throws IOException {
outputStream.write(statusLine.getBytes());
outputStream.write("\n".getBytes());
}

/**
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/openshift/internal/client/HttpClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ public void shouldReasonPhraseIsOptional() throws IOException {
}
}

@Test
public void shouldHaveURLInExceptionMessage() throws IOException {
HttpServerFake server = null;
try {
// precondition
this.serverFake.stop();
// RFC 1945 6.1.1 / Reason Phrase is optional
server = startHttServerFake("HTTP/1.0 404 Not Found");

// operation
httpClient.get(server.getUrl());
fail("Expected NotFoundException not thrown");
} catch(NotFoundException e) {
assertTrue(e.getMessage().contains(server.getUrl().toString()));
} finally {
server.stop();
}
}

protected HttpServerFake startHttServerFake(String statusLine) throws IOException {
int port = new Random().nextInt(9 * 1024) + 1024;
HttpServerFake serverFake = null;
Expand Down