Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.paypal.base.soap;
  
  import java.util.HashMap;
  import java.util.Map;
  
MerchantAPICallPreHandler is an implementation of com.paypal.base.APICallPreHandler for Merchant API service. This serves as a decorator over a basic com.paypal.base.APICallPreHandler
 
 public class MerchantAPICallPreHandler implements APICallPreHandler {

Pattern for Message Formatting
 
 	private static final Pattern REGEX_PATTERN = Pattern.compile("(['])");

API Username for authentication
 
 	private String apiUserName;

 
 	private ICredential credential;

Access token if any for authorization
 
 	private String accessToken;

TokenSecret if any for authorization
 
 	private String tokenSecret;

 
SDK Name used in tracking
 
 	private String sdkName;

SDK Version
 
 	private String sdkVersion;

PortName to which a particular operation is bound;
 
 	private String portName;

Internal variable to hold headers
 
 	private Map<StringStringheaders;

Internal variable to hold payload
 
 	private String payLoad;

Map used for to override ConfigManager configurations
 
 	private Map<StringStringconfigurationMap = null;

Private Constructor

Deprecated:
 
 	private MerchantAPICallPreHandler(APICallPreHandler apiCallHandler) {
 		super();
 		this. = apiCallHandler;
 	}

Private Constructor
			Map<StringStringconfigurationMap) {
		super();
		this. = apiCallHandler;
		this. = configurationMap;
	}

MerchantAPICallPreHandler decorating basic com.paypal.base.APICallPreHandler using API Username

Deprecated:
Parameters:
apiCallHandler Instance of com.paypal.base.APICallPreHandler
apiUserName API Username
accessToken Access Token
tokenSecret Token Secret
Throws:
com.paypal.base.exception.InvalidCredentialException
com.paypal.base.exception.MissingCredentialException
			String apiUserNameString accessTokenString tokenSecret)
		this(apiCallHandler);
		this. = apiUserName;
		this. = accessToken;
		this. = tokenSecret;
	}

MerchantAPICallPreHandler decorating basic com.paypal.base.APICallPreHandler using com.paypal.base.credential.ICredential

Deprecated:
Parameters:
apiCallHandler Instance of com.paypal.base.APICallPreHandler
credential Instance of com.paypal.base.credential.ICredential
			ICredential credential) {
		this(apiCallHandler);
		if (credential == null) {
					"Credential is null in MerchantAPICallPreHandler");
		}
		this. = credential;
	}

MerchantAPICallPreHandler decorating basic com.paypal.base.APICallPreHandler using com.paypal.base.credential.ICredential

Parameters:
apiCallHandler Instance of com.paypal.base.APICallPreHandler
credential Instance of com.paypal.base.credential.ICredential
sdkName SDK Name
sdkVersion sdkVersion
portName Port Name
configurationMap
			ICredential credentialString sdkNameString sdkVersion,
			String portNameMap<StringStringconfigurationMap) {
		this(apiCallHandlerconfigurationMap);
		this. = sdkName;
		this. = sdkVersion;
		this. = portName;
		if (credential == null) {
					"Credential is null in MerchantAPICallPreHandler");
		}
		this. = credential;
	}

MerchantAPICallPreHandler decorating basic com.paypal.base.APICallPreHandler using API Username

Parameters:
apiCallHandler Instance of com.paypal.base.APICallPreHandler
apiUserName API Username
accessToken Access Token
tokenSecret Token Secret
sdkName SDK Name
sdkVersion sdkVersion
portName Port Name
configurationMap
Throws:
com.paypal.base.exception.InvalidCredentialException
com.paypal.base.exception.MissingCredentialException
			String apiUserNameString accessTokenString tokenSecret,
			String sdkNameString sdkVersionString portName,
			Map<StringStringconfigurationMap)
		this(apiCallHandlerconfigurationMap);
		this. = apiUserName;
		this. = accessToken;
		this. = tokenSecret;
		this. = sdkName;
		this. = sdkVersion;
		this. = portName;
	}

Returns:
the sdkName
	public String getSdkName() {
		return ;
	}

Deprecated:
Parameters:
sdkName the sdkName to set
	public void setSdkName(String sdkName) {
		this. = sdkName;
	}

Returns:
the sdkVersion
	public String getSdkVersion() {
		return ;
	}

Deprecated:
Parameters:
sdkVersion the sdkVersion to set
	public void setSdkVersion(String sdkVersion) {
		this. = sdkVersion;
	}

Returns:
the portName
	public String getPortName() {
		return ;
	}

Deprecated:
Parameters:
portName the portName to set
	public void setPortName(String portName) {
		this. = portName;
	}
	public Map<StringStringgetHeaderMap() throws OAuthException {
		if ( == null) {
			if ( instanceof SignatureCredential) {
				SignatureHttpHeaderAuthStrategy signatureHttpHeaderAuthStrategy = new SignatureHttpHeaderAuthStrategy(
				 = signatureHttpHeaderAuthStrategy
else if ( instanceof CertificateCredential) {
				CertificateHttpHeaderAuthStrategy certificateHttpHeaderAuthStrategy = new CertificateHttpHeaderAuthStrategy(
				 = certificateHttpHeaderAuthStrategy
			}
		}
		return ;
	}
	public String getPayLoad() {
		// This method appends SOAP Headers to payload
		// if the credentials mandate soap headers
		if ( == null) {
			String header = null;
			if ( instanceof SignatureCredential) {
				SignatureSOAPHeaderAuthStrategy signatureSoapHeaderAuthStrategy = new SignatureSOAPHeaderAuthStrategy();
				signatureSoapHeaderAuthStrategy
				header = signatureSoapHeaderAuthStrategy
						.generateHeaderStrategy(sigCredential);
else if ( instanceof CertificateCredential) {
				CertificateSOAPHeaderAuthStrategy certificateSoapHeaderAuthStrategy = new CertificateSOAPHeaderAuthStrategy();
				certificateSoapHeaderAuthStrategy
				header = certificateSoapHeaderAuthStrategy
						.generateHeaderStrategy(certCredential);
			}
					header);
		}
		return ;
	}
	public String getEndPoint() {
		String endPoint = searchEndpoint();
		if (endPoint == null) {
				if (getCredential() instanceof CertificateCredential) {
else {
				}
				if (getCredential() instanceof CertificateCredential) {
else {
				}
			}
		}
		return endPoint;
	}
		return ;
	}
	public void validate() throws ClientActionRequiredException {
		if (mode == null && searchEndpoint() == null) {
			// Mandatory Mode not specified.
					"mode[production/live] OR endpoint not specified");
		}
		if ((mode != null)
				&& (!mode.trim().equalsIgnoreCase(.) && !mode
			// Mandatory Mode not specified.
					"mode[production/live] OR endpoint not specified");
		}
	}
	/*
	 * Search a valid endpoint in the configuration, returning null if not found
	 */
	private String searchEndpoint() {
		String endPoint = this..get(. + "."
getPortName()) != null ? this.
						.getEndPoint() : null);
		if (endPoint != null && endPoint.trim().length() <= 0) {
			endPoint = null;
		}
		return endPoint;
	}
	/*
	 * Returns a credential as configured in the application configuration
	 */
		ICredential returnCredential = null;
		CredentialManager credentialManager = new CredentialManager(
		returnCredential = credentialManager.getCredentialObject();
		if ( != null && .trim().length() > 0) {
			// Set third party authorization to token
			// if token is sent as part of request call
			if (returnCredential instanceof SignatureCredential) {
				SignatureCredential sigCred = (SignatureCredentialreturnCredential;
				sigCred.setThirdPartyAuthorization(tokenAuth);
else if (returnCredential instanceof CertificateCredential) {
				CertificateCredential certCred = (CertificateCredentialreturnCredential;
				certCred.setThirdPartyAuthorization(tokenAuth);
			}
		}
		return returnCredential;
	}
	/*
	 * Returns default HTTP headers used in SOAP call
	 */
		Map<StringStringreturnMap = new HashMap<StringString>();
		// Add user-agent header
		returnMap.putAll(uaHeader.getHeader());
		return returnMap;
	}

	private void initCredential() throws InvalidCredentialException,
		if ( == null) {
		}
	}

Gets Namespace specific to PayPal APIs
	private String getNamespaces() {
		return "xmlns:ns=\"urn:ebay:api:PayPalAPI\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\"";
	}

Returns Payload after decoration
	private String getPayLoadUsingSOAPHeader(String payLoadString namespace,
			String header) {
		String returnPayLoad = null;
		String formattedPayLoad = processPayLoadForFormatting(payLoad);
		returnPayLoad = MessageFormat.format(formattedPayLoadnew Object[] {
				namespaceheader });
		return returnPayLoad;
	}

Process the payload before using message formatting
		Matcher match = .matcher(payLoad);
		StringBuffer sb = new StringBuffer();
		while (match.find()) {
			match.appendReplacement(sb"'" + match.group());
		}
		match.appendTail(sb);
		// Fix json strings in element values by replacing {
		// by '{' and matching } by '}'
		return sb.toString().replaceAll("(?<!\\{[01]{1})}""'}' ")
				.replaceAll("\\{(?![01]})""'{' ");
	}
New to GrepCode? Check out our FAQ X