Skip to content

Commit

Permalink
Improving the process for configuring the marketo integration, fixes #…
Browse files Browse the repository at this point in the history
…2874 (#2875)

* Improving the process for configuring the marketo integration, fixes #2874
  • Loading branch information
klcodanr authored Aug 19, 2022
1 parent 96b5981 commit ce3787a
Show file tree
Hide file tree
Showing 17 changed files with 1,094 additions and 260 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
[unreleased changes details]: https://github.com/Adobe-Consulting-Services/acs-aem-commons/compare/acs-aem-commons-5.0.14...HEAD

### Changed

- #2874 - Make Marketo Forms Easy to configure
- #2931 - Cloud Manager SonarQube report - 2022.08.10 @ v5.3.2 #2931
- #2877 - Support for selector-based redirects

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2022 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.marketo.client;

import java.io.IOException;
import java.util.Optional;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MarketoApiException extends IOException {

private static final Logger log = LoggerFactory.getLogger(MarketoApiException.class);

private final String requestLine;
private final int statusCode;
private final String reasonString;
private final String responseBody;

private static final String getResponseBody(HttpResponse response) {
if (response != null) {
try {
return StringEscapeUtils
.escapeHtml(StringUtils.abbreviate(EntityUtils.toString(response.getEntity()), 100));
} catch (ParseException | IOException e) {
log.warn("Failed to read response from: {}", response, e);
}
}
return null;
}

public MarketoApiException(String message, HttpRequestBase request, HttpResponse response) {
this(message, request, response, getResponseBody(response), null);
}

public MarketoApiException(String message, HttpRequestBase request, HttpResponse response, String responseBody,
Exception cause) {
super(message, cause);
this.requestLine = Optional.ofNullable(request).map(r -> r.getRequestLine().toString()).orElse(null);
if (response != null) {
this.statusCode = response.getStatusLine().getStatusCode();
this.reasonString = response.getStatusLine().getReasonPhrase();
this.responseBody = responseBody;
} else {
this.statusCode = -1;
this.reasonString = null;
this.responseBody = responseBody;
}
}

public MarketoApiException(String message, HttpRequestBase request, HttpResponse response, String responseBody) {
this(message, request, response, responseBody, null);
}

@Override
public String getMessage() {
return String.format(
"%s\tREQUEST{%s}\tRESPONSE{Status Code: %d, Reason Phrase: %s, Response Body: %s}",
super.getMessage(), getRequestLine(), getStatusCode(), getReasonString(), getResponseBody());
}

/**
* @return the requestLine
*/
public String getRequestLine() {
return requestLine;
}

/**
* @return the statusCode
*/
public int getStatusCode() {
return statusCode;
}

/**
* @return the reasonString
*/
public String getReasonString() {
return reasonString;
}

/**
* @return the responseBody
*/
public String getResponseBody() {
return responseBody;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,47 @@

import javax.annotation.Nonnull;

import org.apache.http.impl.client.CloseableHttpClient;

import com.adobe.acs.commons.marketo.MarketoClientConfiguration;

/**
* A client for interacting with Marketo's API.
*/
public interface MarketoClient {

/**
* Retrieve an API token used for interacting with the Marketo API.
*
* @param config the configuration to use to retrieve the token
* @return a valid Marketo API Token
* @throws IOException an error occurs retrieving the token
*/
public @Nonnull String getApiToken(@Nonnull MarketoClientConfiguration config) throws IOException;

/**
* Retrieve all of the available forms from the current organization in Marketo.
*
* @param config the configuration for this request
* @return the full list of available forms
* @throws IOException an exception occurs interacting with the API
*/
public @Nonnull List<MarketoForm> getForms(@Nonnull MarketoClientConfiguration config) throws IOException;

/**
* Retrieve all of the available forms from the current organization in Marketo.
*
* @param config the configuration for this request
* @return the full list of available forms
* @throws IOException an exception occurs interacting with the API
*/
public @Nonnull List<MarketoField> getFields(@Nonnull MarketoClientConfiguration config) throws IOException;
/**
* Retrieve an API token used for interacting with the Marketo API.
*
* @param config the configuration to use to retrieve the token
* @return a valid Marketo API Token
* @throws IOException an error occurs retrieving the token
*/
public @Nonnull String getApiToken(@Nonnull MarketoClientConfiguration config) throws MarketoApiException;

/**
* Retrieve a HttpClient for interacting with the Marketo API
*
* @return the httpclient
*/
public @Nonnull CloseableHttpClient getHttpClient();

/**
* Retrieve all of the available forms from the current organization in Marketo.
*
* @param config the configuration for this request
* @return the full list of available forms
* @throws IOException an exception occurs interacting with the API
*/
public @Nonnull List<MarketoForm> getForms(@Nonnull MarketoClientConfiguration config) throws MarketoApiException;

/**
* Retrieve all of the available forms from the current organization in Marketo.
*
* @param config the configuration for this request
* @return the full list of available forms
* @throws IOException an exception occurs interacting with the API
*/
public @Nonnull List<MarketoField> getFields(@Nonnull MarketoClientConfiguration config) throws MarketoApiException;

}
Loading

0 comments on commit ce3787a

Please sign in to comment.