Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
HTTP test fails, need to debug. Probably from hostname
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Osborn <osbornjd@ornl.gov>
  • Loading branch information
Joe Osborn committed Apr 2, 2020
1 parent ba6210c commit cae4bca
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
Expand Up @@ -112,8 +112,8 @@ public void setSubject(String emailSubject) {
*
* @param option
*/
public void setOption(String option) {
this.emailAddress = option;
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

/**
Expand Down
Expand Up @@ -12,33 +12,62 @@
package org.eclipse.ice.commands.notification;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.eclipse.ice.commands.CommandStatus;


/**
* This class posts Command job updates to an HTTP link via POST
*
* @author Joe Osborn
*
*/
public class HTTPCommandUpdateHandler implements ICommandUpdateHandler{
public class HTTPCommandUpdateHandler implements ICommandUpdateHandler {


private String HTTPAddress = "";

CommandStatus status = null;

/**
* Default constructor
*/
public HTTPCommandUpdateHandler() {
}

public void setOption(String option) {
this.HTTPAddress = option;

public void setHTTPAddress(String HTTPAddress) {
this.HTTPAddress = HTTPAddress;
}

public void postUpdate() throws IOException {

public void postStatus(CommandStatus status) {
this.status = status;
}

public void postUpdate() throws IOException {

HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(HTTPAddress);

// Setup the parameters to be passed in the post
List<NameValuePair> params = new ArrayList<NameValuePair>(1);
params.add(new BasicNameValuePair("status", status.toString()));
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

// Execute and get the response
try {
HttpResponse response = httpClient.execute(httpPost);
} catch (Exception e) {
logger.info("HTTP Post was not successful.", e);
throw new IOException();
}
}

}
Expand Up @@ -31,13 +31,6 @@ public interface ICommandUpdateHandler {
*/
static final Logger logger = LoggerFactory.getLogger(ICommandUpdateHandler.class);


/*
* Public setter that must be implemented so that the child class can obtain a
* place to send the update
*/
public void setOption(String option);

/*
* This function processes the logic required to post an update about the job
* for the class
Expand Down
Expand Up @@ -61,7 +61,7 @@ public void testEmailNotificationPostUpdate() throws IOException {

EmailUpdateHandler email = new EmailUpdateHandler();
// Just send an email to itself
email.setOption("commandsapi@gmail.com");
email.setEmailAddress("someemail@gmail.com");
email.setEmailText("This is a test email");
email.setSubject("This is a test subject");
email.postUpdate();
Expand Down
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;

import org.eclipse.ice.commands.CommandStatus;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -60,7 +61,8 @@ public void tearDown() throws Exception {
public void testHTTPNotificationPostUpdate() throws IOException {

HTTPCommandUpdateHandler updater = new HTTPCommandUpdateHandler();
updater.setOption("www.example.com");
updater.setHTTPAddress("www.example.com");
updater.postStatus(CommandStatus.INFOERROR);

updater.postUpdate();

Expand Down

0 comments on commit cae4bca

Please sign in to comment.