Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
Release 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jrichard committed Oct 6, 2016
1 parent 401ec0b commit aa5f9a7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>phone-home-api</artifactId>
<version>1.1.7-SNAPSHOT</version>
<version>1.1.7</version>
<packaging>jar</packaging>

<name>Phone Home API</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@
import org.apache.commons.codec.digest.MessageDigestAlgorithms;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.restlet.Context;
import org.restlet.data.Reference;
import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.ClientResource;
import org.restlet.resource.ResourceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.blackducksoftware.integration.phone.home.client.PhoneHomeClientApi;
import com.blackducksoftware.integration.phone.home.enums.BlackDuckName;
import com.blackducksoftware.integration.phone.home.enums.PhoneHomeSource;
import com.blackducksoftware.integration.phone.home.enums.ThirdPartyName;
import com.blackducksoftware.integration.phone.home.exception.PhoneHomeException;
import com.blackducksoftware.integration.phone.home.exception.PropertiesLoaderException;
import com.blackducksoftware.integration.phone.home.util.AuthenticatorUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
* @author nrowles
Expand Down Expand Up @@ -115,24 +117,36 @@ public void setProxyProperties(final String proxyHost, final int proxyPort, fina
* This method posts to the specified 'targetUrl' the
* information contained in 'info'
*/
public void callHome(PhoneHomeInfo info, final String targetUrl) throws ResourceException, PhoneHomeException {
public void callHome(PhoneHomeInfo info, final String targetUrl) throws PhoneHomeException {
try {
info = Objects.requireNonNull(info);
info = Objects.requireNonNull(info);
} catch (final NullPointerException e) {
throw new PhoneHomeException("Expected parameters to not be null");
}

final PhoneHomeClientApi client = ClientResource.create(new Context(), new Reference(targetUrl),
PhoneHomeClientApi.class);

client.getClientResource().setEntityBuffering(true);
logger.info("PhoneHomeInfo: " + info.toString());

client.postPhoneHomeInfo(info);
client.getClientResource().release();
final ClientResource resource = new ClientResource(targetUrl);
resource.setEntityBuffering(true);
resource.setMethod(Method.POST);

final Gson gson = new GsonBuilder().create();
final String json = gson.toJson(info);

final StringRepresentation representation = new StringRepresentation(json, MediaType.APPLICATION_JSON);

resource.getRequest().setEntity(representation);

final int responseCode = client.getClientResource().getResponse().getStatus().getCode();
try {
resource.handle();
} catch (final Exception e) {
final int responseCode = resource.getResponse().getStatus().getCode();
throw new PhoneHomeException("Error when phoning-home: " + responseCode, e);
} finally {
resource.release();
}
final int responseCode = resource.getResponse().getStatus().getCode();
if (responseCode >= 200 && responseCode < 300) {
logger.info("Phone Home Call Successful, status returned: " + responseCode);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public PhoneHomeException() {
super();
}

public PhoneHomeException(String message) {
public PhoneHomeException(final String message) {
super(message);
}

public PhoneHomeException(final String message, final Throwable e) {
super(message, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.mockserver.model.Header;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;
import org.restlet.resource.ResourceException;

import com.blackducksoftware.integration.phone.home.enums.BlackDuckName;
import com.blackducksoftware.integration.phone.home.enums.PhoneHomeSource;
Expand Down Expand Up @@ -108,7 +107,7 @@ public void callHomeNull() throws Exception {

@Test
public void callHomeInvalidUrl() throws Exception {
exception.expect(ResourceException.class);
exception.expect(PhoneHomeException.class);
final PhoneHomeClient phClient = new PhoneHomeClient();

final String regId = "regId";
Expand Down

0 comments on commit aa5f9a7

Please sign in to comment.