use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class HttpViewHandler method render.
public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {
if (request == null)
throw new ViewHandlerException("Null HttpServletRequest object");
if (UtilValidate.isEmpty(page))
throw new ViewHandlerException("Null or empty source");
if (Debug.infoOn())
Debug.logInfo("Retreiving HTTP resource at: " + page, module);
try {
HttpClient httpClient = new HttpClient(page);
String pageText = httpClient.get();
// TODO: parse page and remove harmful tags like <HTML>, <HEAD>, <BASE>, etc - look into the OpenSymphony piece for an example
response.getWriter().print(pageText);
} catch (IOException e) {
throw new ViewHandlerException("IO Error in view", e);
} catch (HttpClientException e) {
throw new ViewHandlerException(e.getNonNestedMessage(), e.getNested());
}
}
use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class ValueLinkApi method send.
/**
* Transmit a request to ValueLink
* @param url override URL from what is defined in the properties
* @param request request Map of request parameters
* @return Map of response parameters
* @throws HttpClientException
*/
public Map<String, Object> send(String url, Map<String, Object> request) throws HttpClientException {
if (debug) {
Debug.logInfo("Request : " + url + " / " + request, module);
}
// read the timeout value
String timeoutString = (String) props.get("payment.valuelink.timeout");
int timeout = 34;
try {
timeout = Integer.parseInt(timeoutString);
} catch (NumberFormatException e) {
Debug.logError(e, "Unable to set timeout to " + timeoutString + " using default " + timeout);
}
// create the HTTP client
HttpClient client = new HttpClient(url, request);
client.setTimeout(timeout * 1000);
client.setDebug(debug);
client.setClientCertificateAlias((String) props.get("payment.valuelink.certificateAlias"));
String response = client.post();
// parse the response and return a map
return this.parseResponse(response);
}
use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class ClearCommerceException method sendRequest.
private static Document sendRequest(Document requestDocument, String paymentConfig, Delegator delegator) throws ClearCommerceException {
if (UtilValidate.isEmpty(paymentConfig)) {
paymentConfig = "payment.properties";
}
String serverURL = EntityUtilProperties.getPropertyValue(paymentConfig, "payment.clearcommerce.serverURL", delegator);
if (UtilValidate.isEmpty(serverURL)) {
throw new ClearCommerceException("Missing server URL; check your ClearCommerce configuration");
}
if (Debug.verboseOn()) {
Debug.logVerbose("ClearCommerce server URL: " + serverURL, module);
}
OutputStream os = new ByteArrayOutputStream();
try {
UtilXml.writeXmlDocument(requestDocument, os, "UTF-8", true, false, 0);
} catch (TransformerException e) {
throw new ClearCommerceException("Error serializing requestDocument: " + e.getMessage());
}
String xmlString = os.toString();
if (Debug.verboseOn()) {
Debug.logVerbose("ClearCommerce XML request string: " + xmlString, module);
}
HttpClient http = new HttpClient(serverURL);
http.setParameter("CLRCMRC_XML", xmlString);
String response = null;
try {
response = http.post();
} catch (HttpClientException hce) {
Debug.logInfo(hce, module);
throw new ClearCommerceException("ClearCommerce connection problem", hce);
}
Document responseDocument = null;
try {
responseDocument = UtilXml.readXmlDocument(response, false);
} catch (Exception e) {
throw new ClearCommerceException("Error reading response Document from a String: " + e.getMessage());
}
if (Debug.verboseOn()) {
Debug.logVerbose("Result severity from clearCommerce:" + getMessageListMaxSev(responseDocument), module);
}
if (Debug.verboseOn() && getMessageListMaxSev(responseDocument) > maxSevComp) {
Debug.logVerbose("Returned messages:" + getMessageList(responseDocument), module);
}
return responseDocument;
}
use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class WidgetMacroLibraryTests method testHtmlMacroLibrary.
public void testHtmlMacroLibrary() throws Exception {
HttpClient http = initHttpClient();
if (Start.getInstance().getConfig().portOffset != 0) {
Integer port = 8443 + Start.getInstance().getConfig().portOffset;
screenUrl = screenUrl.replace("8443", port.toString());
}
http.setUrl(screenUrl.concat(authentificationQuery));
String screenOutString = http.post();
assertNotNull("Response failed from ofbiz", screenOutString);
assertEquals("Response contentType isn't good : " + http.getResponseContentType(), "text/html;charset=UTF-8", http.getResponseContentType());
// Test if a ftl macro error is present
assertFalse("Html Screen contains Macro on error : see " + screenUrl + " for more detail", screenOutString.contains("FreeMarker template error:"));
}
use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class WidgetMacroLibraryTests method testCsvMacroLibrary.
public void testCsvMacroLibrary() throws Exception {
String screencsvUrl = screenUrl.concat("Csv");
HttpClient http = initHttpClient();
http.setUrl(screencsvUrl.concat(authentificationQuery));
String screenOutString = http.post();
assertNotNull("Response failed from ofbiz", screenOutString);
assertEquals("Response contentType isn't good : " + http.getResponseContentType(), "text/csv;charset=UTF-8", http.getResponseContentType());
// Test if a ftl macro error is present
assertFalse("Csv Screen contains Macro on error : see " + screencsvUrl + " for more detail", screenOutString.contains("FreeMarker template error:"));
}
Aggregations