use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class WidgetMacroLibraryTests method testFopMacroLibrary.
public void testFopMacroLibrary() throws Exception {
String screentextUrl = screenUrl.concat("Fop");
HttpClient http = initHttpClient();
http.setUrl(screentextUrl.concat(authentificationQuery));
// FIXME need to check if the stream is an application-pdf that don't contains ftl stack trace
InputStream screenInputStream = (InputStream) http.postStream();
assertNotNull("Response failed from ofbiz", screenInputStream);
assertEquals("Response contentType isn't good : " + http.getResponseContentType(), "application/pdf;charset=UTF-8", http.getResponseContentType());
String screenOutString = "";
try {
BodyContentHandler handler = new BodyContentHandler(Integer.MAX_VALUE);
Metadata metadata = new Metadata();
new PDFParser().parse(screenInputStream, handler, metadata, new ParseContext());
screenOutString = handler.toString();
} finally {
screenInputStream.close();
}
// Test if a ftl macro error is present
assertFalse("Fop Screen contains Macro on error : see " + screentextUrl + " for more detail", screenOutString.contains("FreeMarker template error:"));
}
use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class RitaApi method send.
public RitaApi send() throws IOException, GeneralException {
if (host == null || port == 0) {
throw new GeneralException("TCP transaction not supported without valid host/port configuration");
}
if (mode == MODE_IN) {
String stream = this.toString() + "..\r\n";
Debug.logInfo("Sending - \n" + stream, module);
String urlString = "http://" + host + ":" + port;
HttpClient http = new HttpClient(urlString);
http.setDebug(true);
Map<String, String> docMap = new HashMap<>();
String resp = null;
try {
resp = http.post(stream);
} catch (HttpClientException e) {
Debug.logError(e, module);
throw new IOException(e.getMessage());
}
String[] lines = resp.split("\n");
for (int i = 0; i < lines.length; i++) {
Debug.logInfo(lines[i], module);
if (!".".equals(lines[i].trim())) {
String[] lineSplit = lines[i].trim().split(" ", 2);
if (lineSplit != null && lineSplit.length == 2) {
docMap.put(lineSplit[0], lineSplit[1]);
} else {
Debug.logWarning("Line split error - " + lines[i], module);
}
} else {
break;
}
}
RitaApi out = new RitaApi(docMap);
return out;
}
throw new IllegalStateException("Cannot send output object");
}
use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class AIMPaymentServices method processCard.
private static Map<String, Object> processCard(Map<String, Object> request, Properties props, Locale locale) {
Map<String, Object> result = new HashMap<String, Object>();
String url = props.getProperty("url");
if (UtilValidate.isEmpty(url)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingAuthorizeNetTransactionUrlNotFound", locale));
}
if (isTestMode()) {
Debug.logInfo("TEST Authorize.net using url [" + url + "]", module);
Debug.logInfo("TEST Authorize.net request string " + request.toString(), module);
Debug.logInfo("TEST Authorize.net properties string " + props.toString(), module);
}
// card present has a different layout from standard AIM; this determines how to parse the response
int apiType = UtilValidate.isEmpty(props.get("cpMarketType")) ? AuthorizeResponse.AIM_RESPONSE : AuthorizeResponse.CP_RESPONSE;
try {
HttpClient httpClient = new HttpClient(url, request);
String certificateAlias = props.getProperty("certificateAlias");
httpClient.setClientCertificateAlias(certificateAlias);
String httpResponse = httpClient.post();
Debug.logInfo("transaction response: " + httpResponse, module);
AuthorizeResponse ar = new AuthorizeResponse(httpResponse, apiType);
if (ar.isApproved()) {
result.put("authResult", Boolean.TRUE);
} else {
result.put("authResult", Boolean.FALSE);
if (Debug.infoOn()) {
Debug.logInfo("transactionId: " + ar.getTransactionId(), module);
Debug.logInfo("responseCode: " + ar.getResponseCode(), module);
Debug.logInfo("responseReason: " + ar.getReasonCode(), module);
Debug.logInfo("reasonText: " + ar.getReasonText(), module);
}
}
result.put("httpResponse", httpResponse);
result.put("authorizeResponse", ar);
} catch (HttpClientException e) {
Debug.logInfo(e, "Could not complete Authorize.Net transaction: " + e.toString(), module);
}
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
return result;
}
use of org.apache.ofbiz.base.util.HttpClient in project ofbiz-framework by apache.
the class TestEvent method httpClientTest.
public static String httpClientTest(HttpServletRequest request, HttpServletResponse response) {
try {
HttpClient http = new HttpClient("http://ofbiz.apache.org/cgi-bin/http_test.pl");
http.setHeader("Cookie", "name=value,value=name");
http.setHeader("User-Agent", "Mozilla/4.0");
http.setParameter("testId", "testing");
Debug.logInfo(http.post(), module);
} catch (Exception e) {
Debug.logInfo(e, "HttpClientException Caught.", module);
}
return "success";
}
Aggregations