curl command into Java - encoding xml file - java

I have what I believe is a simple curl command that I'm trying to turn into appropriate Java code, to put into my Java-based app. The curl command is like this:
curl -d command=setUserItem -d data_action=replace --data-urlencode user#user.xml --data-urlencode vfs_items#vfs_items.xml https://www.example.com/
Note it involves two xml flat files... When I invoke curl from the folder that contains those files... I get back a good response, that is an xml that has a few tags that lets me know it processed the command okay, and it creates a user as it should.
Below is my Java code. My feeling is that i'm not doing the part of handling the xml files's content correctly... I try just putting it into a string, but no luck. When I invoke through Java.... I get back a "bad" response indicating i'm not calling it correctly.
String xmlUser, xmlVfsItems, xmlPermissions;
String urlStr;
String[] paramName;
String[] paramVal;
xmlUser = "" +
" <?xml version=\"1.0\" encoding=\"UTF-8\"?> <user type=\"properties\"> " +
" <password>web</password> " +
" <version>1.0</version> " +
" <root_dir>/</root_dir> " +
" <userVersion>6</userVersion> " +
" </user> " +
"";
xmlVfsItems = "" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
"<vfs_items type=\"vector\"> " +
"<vfs_items_subitem type=\"properties\"> " +
"<name>curl_user</name> " +
"<path>/</path> " +
"<vfs_item type=\"vector\"> " +
"<vfs_item_subitem type=\"properties\"> " +
"<url>FILE://Users/ftp_accounts/curl_user/</url> " +
"</vfs_item_subitem> " +
"</vfs_item> " +
"</vfs_items_subitem> " +
"</vfs_items> " +
"";
urlStr = "https://www.example.com/";
paramName = ["command", "data_action","user", "vfs_items"];
paramVal = ["setUserItem", "replace", xmlUser, xmlVfsItems];
httpPost(urlStr, paramName, paramVal);
String httpPost(String urlStr, String[] paramName, String[] paramVal) throws Exception {
URL url = new URL(urlStr);
HttpURLConnection conn =
(HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// Create the form content
OutputStream out = conn.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
for (int i = 0; i < paramName.length; i++) {
writer.write(paramName[i]);
writer.write("=");
writer.write(URLEncoder.encode(paramVal[i], "UTF-8"));
writer.write("&");
}
writer.close();
out.close();
if (conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
// Buffer the result into a string
BufferedReader rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
println(sb.toString());
return sb.toString();
}
This is the good response I get from curl:
<?xml version="1.0" encoding="UTF-8"?>
<result><response_status>OK</response_status> <response_type>text</response_type>
<response_data></response_data></result>
The web-service involes creating a user within the CrushFTP system, and I can also verify the new user is created.
Here's the "bad response" I get from java... It looks like it is presenting the webpage as if I had accessed the url through a browser... the user-record it is suppose to create is not created:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>CrushFTP WebInterface</title> <link rel="stylesheet" type="text/css" href="/WebInterface/jQuery/css/login.css" /> <script type="text/javascript" src="/WebInterface/Resources/js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="/WebInterface/jQuery/js/jquery-ui-1.8.2.custom.min.js"></script> <script type="text/javascript" src="/WebInterface/jQuery/js/jquery.blockUI.js"></script> <script type="text/javascript" src="/WebInterface/Resources/js/login.js"></script> <script type="text/javascript"> function showRecaptcha(element) { if(window.Recaptcha) { window.Recaptcha.create("/*RECAPTCHA_PUBLIC_KEY*/", element, { theme: "red" }); } } $(document).ready(function() { /*RECAPTCHA*/ }); var passwordRule = {random_password_length:6,min_password_numbers:0,min_password_lowers:0,min_password_uppers:0,min_password_specials:0}; </script> <script></script> </head> <body style="overflow-x: hidden; overflow-y: auto;" class="login"> <div id="login"> <div id="languageSelector" style="display:none;"> <select> <option value="en" rel="English">English</option> <option value="cn" rel="Chinese">Chinese</option> <option value="cs" rel="Czech">Czech</option> <option value="da" rel="Danish">Danish</option> <option value="nl" rel="Dutch">Dutch</option> <option value="fr" rel="French">French</option> <option value="de" rel="German">German</option> <option value="hu" rel="Hungarian">Hungarian</option> <option value="it" rel="Italian">Italian</option> <option value="pl" rel="Polish">Polish</option> <option value="sk" rel="Slovak">Slovak</option> <option value="es" rel="Spanish">Spanish</option> <option value="se" rel="Swedish">Swedish</option> </select> </div> <form id="loginForm" name="loginForm" method="post" action="/" onSubmit="return doLogin2();"> <div id="panelbody"> <div id="branding" class="clearfix branding"> <img id="loginWheel" src="/WebInterface/images/wheel.gif" /> <a id="defaultLogoLink" href="http://www.crushftp.com/"> <img id="imgLogo" src="/WebInterface/images/logo.png" style="border-width:0px;float:left;" /> </a> </div> <div id="panelLogin"> <div> <label id="UserNameText">Username</label> <input autocomplete="on" type="text" class="textbox" name="username" id="username" value="" /> </div> <div> <label id="PasswordText">Password</label> <input type="password" class="textbox" name="password" id="password" value="" /> </div> <div id="rememberMePanel"> <label><input type="checkbox" name="remember" id="remember" /> <span id="RememberMeText">Remember Me</span></label> </div> <div style="clear:both;height:1px;padding:0px;margin:0px;"></div> <div id="recaptcha_div"></div> <div style="clear:both;height:1px;padding:0px;margin:0px;"></div> <div class="submit clearfix"> <input type="submit" value="login" style='display:none;' /> <input type="hidden" name="command" value="login" /> <input type="hidden" name="skip_login" value="true" /> <input type="hidden" name="encoded" value="false" /> <input type="submit" value="login now" style="position:absolute;left:-1000px;top:-1000px;" /> <a class="button" id="btnLogin" href="javascript:void(0);"> <span id="LoginButtonText">Login</span> </a> </div> <p class="lostpassword"> I forgot my password, email it to me. </p> </div> </div> </form> <form id="changePassForm" method="post" target="dummyIframe" action="/WebInterface/function/" onSubmit="doLogin();"> <div id="changepasswordPanel" style="display:none;margin-bottom:10px;"> <div class="clearfix branding" style="clear:both;"> <a id="defaultLogoLink" href="http://www.crushftp.com/"> <img id="imgLogo" src="/WebInterface/images/logo.png" style="border-width:0px;float:left;margin:3px 0px 10px 0px;" /> </a> </div> <h2 class="popupHeader" style="clear:both;margin-top:15px;" id="ChangePasswordHeaderText"> Change your password </h2> <div class="passwordChangeNote" id="ChangePasswordNoteText"> You must change your password to continue </div> <div class="buttonPanel"> <label for="current_password" id="CurrentPasswordText">Current Password:</label> <input id="current_password" class="textbox" type="password" /> <br /> <br /> <label for="new_password1" id="NewPasswordText">New Password:</label> <input id="new_password1" class="textbox" type="password" /> <br /> <br /> <label for="new_password2" id="ConfirmPasswordText">Confirm Password:</label> <input id="new_password2" class="textbox" type="password" /> <div style="text-align:right;margin-top:10px;"> <a id="btnChangePasswordCancel" class="button" href="javascript:void(0);"> <span id="CancelButtonText">Cancel</span> </a> <a id="btnChangePassword" class="button" href="javascript:void(0);"> <span id="ChanngePasswordButtonText">Change Password</span> </a> </div> <div style="clear:both"></div> <div class="spacing"> <br /> <hr /> <br /> </div> <div> <a id="btnGeneratePassword" class="button" href="javascript:void(0);" style="float:left"> <span id="GeneratePasswordButtonText">Generate password</span> </a> <div id="passwordGeneratePanel" style="display:none;"> <br /> <br /> <input id="generated_password" type="text" class="textboxSmall" style="float:left;" /> <a id="usePassword" class="button" href="javascript:void(0);" style="float:left"> <span id="GeneratePasswordUseButtonText">Use this</span> </a> <a id="cancelPassword" class="button" href="javascript:void(0);" style="float:left"> <span id="GeneratePasswordCancelButtonText">Cancel</span> </a> </div> <div style="clear:both"></div> </div> </div> </div> </form> </div> <div id="OTPBox" style="display:none;"> <img class="closeButton" alt="close" src="/WebInterface/jQuery/images/cancel.png" onclick="$.unblockUI();"/> <h2 class="popupHeader" id="OTPDialogHeaderText"> Enter your OTP here </h2> <div class="buttonPanel"> <div style="width:100%;"> <input id="otp" type="password" style="width:95%;padding:5px;" /> </div> <br /> <br /> <div style="text-align: right; margin-top: 10px;"> <button id="btnSubmitOTP"> <span id="OTPSubmitButtonText">Submit</span> </button> </div> </div> </div> <div id="olderBrowserNotice" style="display:none;top:100px;padding: 10px;" class="alertMessage"> <div id="OldBrowserNoticeHTMLAsText"> Your browser is out of date, it was released almost a decade ago! As a result it is very slow, full of bugs, and this WebInterface may or may not even work with IE6. <br /> <br /> <div style="text-align:right;"> <button id="proceedAnyway">Proceed Anyway Cautiously</button>or get a better browser : Chrome | FireFox </div> </div> </div> <iframe id="dummyIframe" name="dummyIframe" src="javascript:false;" style="display:none;"></iframe> </body></html>

I "dumbed down" the question to post it here, and I mistakenly omitted a key part... The part that was actually causing my problem... The URL also had a username/password, which I needed to turn into a Authorization: header with the credentials BASE64 encoded.
Thanks all for responding... the mention about the header got me thinking about it.

Related

How to use getParts in java to get only image parts?

I'm trying to upload a file to cloudinary. I'm stucked at how to only get parts of image from the form. It keeps on throwing exception: Invalid image file. If I remove all text inputs in the form, the uploading is successful. I guess that happens because the form also has text inside. Please help me solve this. I'm really grateful for your support.
Here is my code:
Form.jsp:
<form role="form" action="<c:url value="/admin/product/update"/>" method="post" enctype="multipart/form-data">
<input name="id" value="${product.id}" hidden="">
<div class="form-group">
<label>Name:</label> <input class="form-control" value="${product.name}" name="name" />
</div>
<div class="form-group">
<label>Price:</label> <input class="form-control" value="${product.price}" type="number" name="price" />
</div>
<div class="form-group">
<label>Quantity:</label> <input class="form-control" value="${product.quantity}" type="number" name="quantity" />
</div>
<div class="form-group">
<label>Image:</label> <input class="form-control" value="${product.image}" name="image" />
</div>
<div class="form-group">
<label>Description </label> <br>
<textarea rows="4" cols="50" name="description" value="${product.description}" ></textarea>
</div>
<div class="form-group">
<label>Category</label>
<div class="checkbox">
<select name="catid">
<c:forEach items="${categorylist}" var="c">
<option value="${c.id}">${c.name}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group">
<label>image</label> <input type="file" name="image" value="${product.image }" />
</div>
Servlet.java
BeanUtils.populate(product, request.getParameterMap());
//if (catid != product.getCategory().getId()) {
// Category category = new Category();
category = dao2.getCategoryByID(catid);
product.setCategory(category);
Map result = null;
Collection<Part> fileParts = request.getParts();
for (Part part : fileParts) {
String fileName = part.getSubmittedFileName();
result = UploadImage.uploadImage(fileName, part);
String url = String.valueOf(result.get("url"));
product.setImage(url);
if (result == null) {
throw new RuntimeException("Loi upload");
}
}
dao.update(product);
The Cloudinary upload method supports uploading media files from the sources like a local path, a remote URL, a private storage URL (S3 or Google Cloud storage), a base64 data URI, or an FTP URL.
Based on your code, it seems that you are only supplying the filename of the image.
String fileName = part.getSubmittedFileName();
result = UploadImage.uploadImage(fileName, part);
You would need to update the code to input the local path of the image.

Saving an image inserted by user in a folder under WEB-INF in a jsp project

I am trying to save an image inserted by an <input> field in a form by the user to a folder named imgs under the WEB-INF folder and store in the table column of the product the path of that photo so i can later display them in a products page for my online shop.
I don't know how to send the image to the java file (using jdbc server) so i can save it and also how i can save it. I have researched online but I have not fount what i am looking for. Below is my .jsp file.
<body>
<%
if(request.getParameter("btn") != null){
String name = request.getParameter("name");
String description = request.getParameter("description");
double price = Double.valueOf( request.getParameter("price"));
String brand = request.getParameter("brand");
String type = request.getParameter("type");
int quantity = Integer.parseInt( request.getParameter("quantity"));
File picture =
Client client = Client.create();
WebResource webResource =client.resource("...link.../"+name+"/"+description+"/"+price+"/"+brand+"/"+type+"/"+quantity+"/"+picture);
ClientResponse myresponse = webResource.accept("text/plain").get(ClientResponse.class);
}
%>
<div class="p-5" >
<h1 id="title" class="d-flex justify-content-center" style="font-size:4rem;">Edit your Profile</h1>
<form class="container " method="post">
<div class="form-row">
<div class="form-group col-6">
<label for="name">Product name:</label>
<input class="form-control" type="text" name="name"><br>
</div >
</div>
<div class="form-row">
<div class="form-group col-6">
<label for="description">Description:</label>
<textarea class="form-control" name="description" cols="40" rows="5"></textarea><br>
</div >
</div>
<div class="form-row">
<div class="form-group col-3">
<label for="price">Price:</label>
<input class="form-control" type="number" name="price"><br>
</div >
<div class="form-group col-6">
<label for="brand">Product brand:</label>
<input class="form-control" type="text" name="brand"><br>
</div >
</div>
<div class="form-row">
<div class="form-group col-6">
<label for="type">Product type(running, walking, casual ,etc...):</label>
<input class="form-control" type="text" name="type"><br>
</div >
<div class="form-group col-6">
<label for="quantity">Available quantity:</label>
<input class="form-control" type="text" name="quantity"><br>
</div >
</div>
<div class="form-row">
<div class="form-group col-6">
<label for="picture">Product picture:</label>
<input class="form-control" type="file" name="picture"><br>
</div >
</div>
<button type="submit" name="btn">Sign in</button>
</form>
</div>
</body>

Conversion of 3 files to user desired output using Angular and springboot

I'm trying to upload multiple files to springboot server from angular but I don't know why I'm getting error.But in postman the code is working fine and I'm able to upload files and output format.
I'm getting this error in browser
HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "OK", url: 'http://localhost:8080/file/Upload', ok: false, …}
Error in backend terminal:
DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'fileN' is not present]
springboot restapi:
#postMapping(value="/Upload")
public ResponseEntity<List<String>> uploadFiles(#RequestParam ("fileN")List<MultipartFile> multipartFiles,#RequestParam("fileFormat")String id) throws IOException, FOPException, TransformerException{
List<String> filenames = new ArrayList<>();
try{
for(MultipartFile file : multipartFiles){
String filename = StringUtils.cleanPath(file.getOriginalFilename());
Path fileStorage = get(DIRECTORY, filename).toAbsolutePath().normalize();
copy(file.getInputStream(), fileStorage, REPLACE_EXISTING);
filenames.add(filename);
}
fileConversion.Convert(id);
}
catch (Exception e){
e.printStackTrace();
}
return ResponseEntity.ok().body(filenames);
user service:
constructor(private http: HttpClient){}
uploadFile(formData: FormData): Observable<any>{
const headerDist = {
'Access-Control-Allow-Origin': '*';
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
'access-control-allow-credentials':'true'
'Content-Type': 'multipart/form data; boundary=Inflow'
}
const requestOptions = {
headers: new HttpHeaders(headerDist),
};
return this.http.post('http://localhost:8080/file/Upload',formData,requestOptions);
}
appcomponent:
onSubmit(){
const formData = new formData();
formData.append('fileN', this.angForm.get('file1').value);
formData.append('fileN', this.angForm.get('file2').value);
formData.append('fileN', this.angForm.get('file3').value);
formData.append('fileN', this.angForm.get('fileFormat').value);
this.userService.uploadFile(formData).subscribe (
(res) => console.log(res),
(err) => console.log(err)
)};
html:
<h2 id="zone" xmlns="http://www.w3.org/1999/html">File Conversions</h2>
<form [formGroup]="angForm" enctype="multipart/form-data" (ngSubmit)="onSubmit()" >
<div class="main">
<div class="classOne">
<div class="form-two">
<input type="file" class="file-input" formControlName="file1" id="ixml" value="" accept="xml/*" required (change)='uploadF($any($event.target).files)' #open>
<div class="file-upload">
<p class="para-tag">Input XML :</p>
<button mat-raised-button color="primary" class="upload-btn" (click)="open.click()">Choose File</button>
</div>
</div>
</div>
<div *ngIf="angForm.controls['file1'].invalid" class ="alert alert-danger">
<div *ngIf="angForm.controls['file1'].errors.required"></div>
</div>
<div class="classTwo">
<div class="form-two">
<input type="file" class="file-input" formControlName="file2" id="udtd" value="" accept="dtd/*" required (change)="uploadFile($event.target.files)"#ele>
<div class="file-upload">
<p class="para-tag">Upload DTD : </p>
<button mat-raised-button color="primary" class="upload-btn" (click)="ele.click()">Choose File</button>
</div>
</div>
</div>
<div *ngIf="angForm.controls['file2'].invalid" class ="alert alert-danger">
<div *ngIf="angForm.controls['file2'].errors.required"></div>
</div>
<div class="classThree">
<div class="form-two">
<input type="file" class="file-input" formControlName="file3" id="uxsl" value="" accept="xsl/*" required (change)="uploading($event.target.files);"#choose>
<div class="file-upload">
<p class="para-tag">Upload XSL : </p>
<button mat-raised-button color="primary" class="upload-btn" (click)="choose.click()">Choose File</button>
</div>
</div>
</div>
<div *ngIf="angForm.controls['file3'].invalid" class ="alert alert-danger">
<div *ngIf="angForm.controls['file3'].errors.required"></div>
</div>
<div class="classFour">
<p class="para-tag-two">Choose Your Output Format :</p>
<div>
<input type="radio" id="pdf" value="pdf" name="fileFormat" formControlName="fileFormat">
<label for="pdf">PDF</label><br>
<input type="radio" id="ps" value="ps" name="fileFormat" formControlName="fileFormat">
<label for="ps">PostScript</label><br>
<input type="radio" id="png" value="png" name="fileFormat" formControlName="fileFormat">
<label for="png">PNG</label><br>
<input type="radio" id="txt" value="txt" name="fileFormat" formControlName="fileFormat">
<label for="txt">Text</label><br>
<input type="radio" id="print" value="print" name="fileFormat" formControlName="fileFormat">
<label for="print">Print</label><br><br>
</div>
</div>
<div *ngIf="angForm.controls['fileFormat'].invalid" class ="alert alert-danger">
<div *ngIf="angForm.controls['fileFormat'].errors.required"></div>
</div>
<div class="submit">
<button style="width:100px;" type="submit" [disabled]="angForm.invalid" mat-raised-button color="warn"disabled="true" >Submit</button>
</div>
</div>
</form>

php mailform with JAvascript validation

I'm having a problem with my one page contact form.
When i click the submit button, i run a javascript check to see if the fields are filled.
The check works fine but i don't have any clue why the PHP isn't responing.
i can't use another php page to do the processing because i want to use the same contact page for other contact purposes.
So this is the sequence i want to get:
1. Form gets filled in
2. On click of the submit butten, javascript checks the fields.
3. If okay, javascript submits the form
4. if mail has been sent, the page is reloaded to contact.php?MailStatus=Success
5. if not (it will run a javascript giving en errormessage telling the user to retry without the fields being cleared.
contact.php (code)
<!DOCTYPE html>
<html>
<head>
<title>Mijn Dier En Ik</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="www.csl-tech.be" />
<meta name="description" content="Op zoek naar dierenhotels, artsen, winkels,... Dan is Mijn Huisdier en Ik de website die je zoekt. Neem een kijkje!" />
<link rel="stylesheet" type="text/css" href="CSLCSS.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="functions.js"></script>
</head>
<body>
<div class="container csl-main">
<div class="row">
<div class="col-md-6">
<form id="MailForm" method="post">
<div id="Message"></div>
<div id="FormFields">
<div class="form-group">
<label for="fname">Voornaam</label>
<input class="form-control" type="text" id="fname" placeholder="Uw voornaam...">
</div>
<br />
<div class="form-group">
<label for="lname">Achternaam</label>
<input class="form-control" type="text" id="lname" placeholder="Uw achternaam...">
</div>
<br />
<div class="form-group">
<label for="email">E-mail</label>
<input class="form-control" type="text" id="email" placeholder="Uw e-mail...">
</div>
<br />
<div class="form-group">
<label for="country">Land</label>
<select class="form-control" id="country" name="country">
<option value="Belgie">België</option>
<option value="Nederland">Nederland</option>
</select>
</div>
<br />
<div class="form-group">
<label for="subject">Onderwerp</label>
<select class="form-control" id="subject" name="subject">
<option value="Vragen">Vragen over Mijn Dier en Ik</option>
<option value="Suggesties">Suggesties voor de website</option>
<option value="Reservatie of Contact">Vragen over het reservatie- en/of contactsysteem</option>
<option value="Foto inzending">Foto inzenden</option>
<option value="Aanpassing gegevens">Aanpassing gegevens</option>
<option value="Andere">Andere</option>
</select>
</div>
<br />
<div class="form-group">
<label for="message">Uw bericht</label>
<textarea class="form-control" id="message" placeholder="Typ hier uw bericht..." style="height:200px"></textarea>
</div>
<br />
<input id="submit" class="btn btn-default" value="Versturen" onclick="CheckMailEntry()">
</div>
</form>
</div>
</div>
</div>
</body>
<?php
if ($_GET['MailStatus'] == 'Success') {
echo '<script type="text/javascript">MailSuccess()</script>';
}
if(isset($_POST['submit'])) {
header('Location: contact.php?MailStatus=Success');
echo 'ok';
}
?>
</html>
Javascript code:
function CheckMailEntry() {
document.getElementById("Message").innerHTML = "";
if (document.getElementById("fname").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Voer uw voornaam in.</div>";
} else if (document.getElementById("lname").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Voer uw achternaam in.</div>";
} else if (document.getElementById("email").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Voer uw email in.</div>";
} else if (document.getElementById("message").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Gelieve een bericht te typen.</div>";
} else {
document.getElementById("Message").innerHTML = "";
document.getElementById("submit").submit();
};
};
function MailSuccess() {
document.getElementById("Message").innerHTML = "<div class='alert alert-success'><strong>Succes:</strong> Wij hebben uw mail ontvangen en zullen deze zo snel mogelijk beantwoorden.</div>";
document.getElementById("FormFields").innerHTML = "";
};

Htmlunit redirect does not work

I am using version 2.28, I am having some issues trying to click a
button that redirects me twice to different URLs.
The result of the click method it is an UnexpectedPage ... (response
status code 200).
I tried to set:
webClient.getCache().setMaxSize(0);
webClient.getOptions().setRedirectEnabled(true);
but I can't reach the page after. I have JavaScript enable.
this is a web written in PHP
the button is currently doing this:
$.ajax({
url: '{{ action('LoanController#checkLoanProcessed') }}',
data: data,
type: 'POST',
cache: false,
dataType: "json",
success: function(data) {
if (data.status === true && data.processed === true)
{
clearInterval(interval); window.location.href = data.redirect; }
}
});
};
Any clue ?
HTML
<script>var SITE_URL = 'https://staging.tutasa.com.uy/';</script>
<script type="text/javascript">
var user_id = '49095';
var user_first_name = 'JUAN';
var duration_6 = "6 Months";
var duration_1 = '1 Year';
var duration_2 = '2 Years';
var duration_3 = '3 Years';
var duration_4 = '4 Years';
var duration_6_quota = '6 Quotas';
var duration_1_quota = '12 Quotas';
var duration_2_quota = '24 Quotas';
var duration_3_quota = '36 Quotas';
var duration_4_quota = '48 Quotas';
var quota_label = [];
quota_label['quota_0'] = '6 Monthly Quotas of:';
quota_label['quota_1'] = '12 Monthly Quotas of:';
quota_label['quota_2'] = '24 Monthly Quotas of:';
quota_label['quota_3'] ='36 Monthly Quotas of:';
quota_label['quota_4'] = '48 Monthly Quotas of:';
var borrower_page = true;
var lender_page = false;
</script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
TuTasa - Your Account </title>
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/layouts/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/layouts/css/datepicker3.css">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/css/app.css?1512484810">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/css/app2.css?1512484810">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/layouts/css/bootstrap-slider.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://staging.tutasa.com.uy/layouts/js/jquery.min.js"></script>
<script type="text/javascript">
var CURRENCY_SYMBOL = '$U';
var CURRENCY_THOUSAND_SEP = ',';
var CURRENCY_DEC_POINT = '.';
var THOUSAND_SEP = ',';
var DEC_POINT = '.';
</script>
</head>
<body>
<div id="wrap" class="container-fluid">
<div id="main" class="row clearfix">
<div class="col-sm-offset-2 col-sm-8 col-md-offset-1 col-md-10 main">
<div class="container-fluid create-new-loan ">
<div class="panel panel-default">
<div class="panel-body pl0 pr0">
<div class="row bs-wizard" style="border-bottom:0;">
<div class="col-xs-3 bs-wizard-step complete">
<div class="progress"><div class="progress-bar"></div></div>
1
<div class="text-center bs-wizard-stepnum">1. Personal</div>
</div>
<div class="col-xs-3 bs-wizard-step active"><!-- complete -->
<div class="progress"><div class="progress-bar"></div></div>
2
<div class="text-center bs-wizard-stepnum">2. Income</div>
</div>
<div class="col-xs-3 bs-wizard-step disabled"><!-- complete -->
<div class="progress"><div class="progress-bar"></div></div>
3
<div class="text-center bs-wizard-stepnum">3. Decision</div>
</div>
<div class="col-xs-3 bs-wizard-step disabled"><!-- active -->
<div class="progress"><div class="progress-bar"></div></div>
4
<div class="text-center bs-wizard-stepnum">4. Money</div>
</div>
</div>
<form method="POST" action="https://staging.tutasa.com.uy/loan/create" accept-charset="UTF-8" class="form-horizontal"><input name="_token" type="hidden" value="BXLImooTL1DnEn4ouSi4uCJ1GG4fZawTdRkRzDtG">
<input name="int" type="hidden" value="">
<input name="user_id" type="hidden" value="49095">
<input name="type" type="hidden" value="borrower">
<div class="panel panel-default hidden">
<div class="panel-heading">Income</div>
<div class="panel-body">
<input type="hidden" name="borrow_amount_min" value="10000.00"/>
<input type="hidden" name="borrow_amount_max" value="200000.00"/>
<div class="form-group">
<label for="education" class="col-sm-4 control-label">Education<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="education" name="education"><option value=""></option><option value="1">Primary</option><option value="2">Secondary</option><option value="3">University</option><option value="4" selected="selected">Post Graduate</option><option value="5">Other</option></select>
</div>
</div>
<div class="form-group">
<label for="income_type" class="col-sm-4 control-label">Means of Income<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="income_type" name="income_type"><option value=""></option><option value="1">Employee</option><option value="2">Businessman</option><option value="3">Independent Professional</option><option value="4">Pension</option><option value="5">Allowances</option><option value="6" selected="selected">Rent</option><option value="7">Unemployed</option></select>
</div>
</div>
<div class="hidden income-employee income-1">
<div class="form-group">
<label for="company_name" class="col-sm-4 control-label">Company Name<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="company_name" type="text" value="" id="company_name">
</div>
</div>
<div class="form-group">
<label for="job_title" class="col-sm-4 control-label">Job Title</label>
<div class="col-sm-4">
<input class="form-control" name="job_title" type="text" value="" id="job_title">
</div>
</div>
<div class="form-group">
<label for="company_phone_no" class="col-sm-4 control-label">Company telephone number<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="company_phone_no" type="text" value="" id="company_phone_no">
</div>
</div>
<div class="form-group">
<label for="company_supervisor" class="col-sm-4 control-label">Name of Supervisor<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="company_supervisor" type="text" value="" id="company_supervisor">
</div>
</div>
<div class="form-group">
<label for="job_duration" class="col-sm-4 control-label">How long have you been with this job?<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="job_duration" name="job_duration"><option value="6" selected="selected">Less then 6 months</option><option value="12">6 months to 1 year</option><option value="24">1 year to 2 years</option><option value="36">2 years to 3 years</option><option value="37">More than 3 years</option></select>
</div>
</div>
</div>
<div class="form-group">
<label for="monthly_income" class="col-sm-4 control-label">What's your monthly net income?<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="monthly_income" type="text" value="350000" id="monthly_income">
</div>
<div class="col-sm-4">
<label class="disclosure">Need to show proof of income</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<input class="form-control" id="monthly_income_text" readonly="true" name="monthly_income_text" type="text" value="Trescientos cincuenta mil">
</div>
</div>
<div class="form-group">
<label for="proof_of_income" class="col-sm-4 control-label">Do you have proof of income?<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="proof_of_income" name="proof_of_income"><option value="Select">Select</option><option value="Yes" selected="selected">Yes</option><option value="No">No</option><option value="Maybe">Maybe</option></select>
</div>
</div>
<div class="form-group">
<label for="bank_account" class="col-sm-4 control-label">Do you have bank account under your name?<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="bank_account" name="bank_account"><option value="Select">Select</option><option value="Yes" selected="selected">Yes</option><option value="No">No</option><option value="Yes, but I don't remember the details">Yes, but don't remember details</option></select>
</div>
</div>
<input type="hidden" name="calculate_status" class="form-control" value="1" />
<div class="form-group">
<div class="col-sm-4 col-sm-offset-3">
<input class="btn btn-primary btn-lg" name="calculate" type="submit" value="How much can I borrow?">
</div>
</div>
</div>
</div>
<input name="temp_amount" type="hidden" value="30000.0000">
<input name="temp_duration" type="hidden" value="0">
<div class="panel panel-default loan_amt_duration">
<div class="panel-heading">
Find below the maximum you can borrow based on the information provided.
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12">
<h3>
Amount
</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-10 mt-15">
<a class="amountSliderDecrease" href="#">
<span class="glyphicon glyphicon-minus mr-15"></span>
</a>
<input id="amount" name="amount" data-slider-id='amountSlider' data-slider-class="slider-long" type="text" data-slider-min="10000.00" data-slider-max="200000.00" data-slider-step="10000" data-slider-value="30000.0000"/>
<a class="amountSliderIncrease" href="#">
<span class="glyphicon glyphicon-plus ml-15"></span>
</a>
</div>
<div class="col-sm-2 mt-15">
<input id="amount-manual-loan" name="amount-manual" class="amount-manual text-center" min="10000.00" max="200000.00"/>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12">
<h3>
Loan Duration
</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-10 mt-15">
<a class="durationSliderDecrease" href="#">
<span class="glyphicon glyphicon-minus mr-15"></span>
</a>
<input id="duration" name="duration" data-slider-id='durationSlider' type="text" data-slider-min="0" data-slider-max="4" data-slider-step="1" data-slider-value="0"/>
<a class="durationSliderIncrease" href="#">
<span class="glyphicon glyphicon-plus ml-15"></span>
</a>
</div>
</div>
</div>
<div class="pt-40 col-sm-12">
<div class="row totals">
<div id="borrower-data-url" data-url="https://staging.tutasa.com.uy/borrower/repayment-calculate" class="hide"></div>
<div class="col-md-3 mb-25 selected-result">
<span id="borrow_amount">$U 30,000</span>
<span class="amt_label">Total Amount</span>
</div>
<div class="col-md-3 mb-25 selected-result">
<span class="borrow_quota_display">$U 6,171</span>
<span id="borrow_quota_label" class="amt_label">
6 Monthly Quotas of:<sup>*</sup>
</span>
</div>
<div class="col-md-3 mb-25 selected-result">
<span class="borrow_rate_display">30.84%</span>
<span class="amt_label">Interest Rate</span>
</div>
<div class="col-md-3 mb-25">
<button id="credit_score" onClick="void(0)" style="cursor:pointer;" class="btn btn-block btn-success btn-lg col-sm-12" name="review" type="submit" value="Proceed to credit scoring">Proceed to credit scoring</button>
<button id="credit_score" onClick="void(0)" style="cursor:pointer; margin-top:15px;" class="btn btn-block btn-primary btn-lg col-sm-12" name="back_to_income" type="submit" value="Back">Back</button>
</div>
<input name="borrow_quota" type="hidden" value="6171">
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<p>*Representative APR <span id="borrow_rate" class="borrow_rate borrow_rate_display">30.84</span>%. Terms subject to market conditions.</p>
</div>
<script type="text/javascript">
$(document).ready(function(){
if(false){
$('input[name="calculate"]').click();
}
$('#monthly_income').inputmask('[999999999]', {"numericInput": true, "greedy": false, "placeholder": ""});
$('#monthly_income').on('keyup', _.debounce(function(){
monthlyIncomeText();
}, 1000));
_.each(['input[name="borrow_quota"]','#purpose','#education','#priority','#income_type','#company_name','#job_title','#company_phone_no','#company_supervisor','#job_duration','#businessman_org_name',
'#businessman_org_phone','#businessman_ref','#indep_prof_industry','#indep_prof_ref','#indep_prof_ref_phone','#retired_prev_employer_name','#allow_grantor','#unemp_prev_employer_name',
'#monthly_income','#proof_of_income','#bank_account','#repayment_likelihood','#calculate_status','#fast_track_code','#fast_track_code_status','#amount_payable_to'], function(input){
$(input).change(function(){
var data = {};
if($('#amount').val()) data[btoa('amount')] = btoa($('#amount').val());
if($('#duration').val()) data[btoa('duration')] = btoa($('#duration').val());
if($('#borrow_rate').text()) data[btoa('rate')] = btoa($('#borrow_rate').text());
if($('input[name="borrow_quota"]').val()) data[btoa('quota')] = btoa($('input[name="borrow_quota"]').val());
if($('input[name="borrow_quota"]').val()) data[btoa('total')] = btoa($('#duration').val() ? 0.5 * 12 * $('input[name="borrow_quota"]').val() : $('#duration').val() * $('input[name="borrow_quota"]').val());
if($('#education').val()) data[btoa('education')] = btoa($('#education').val());
if($('#priority').val()) data[btoa('priority')] = btoa($('#priority').val());
if($('#income_type').val()) data[btoa('income_type')] = btoa($('#income_type').val());
if($('#monthly_income').val()) data[btoa('monthly_income')] = btoa($('#monthly_income').val());
if($('#proof_of_income').val()) data[btoa('proof_of_income')] = btoa($('#proof_of_income').val());
if($('#proof_of_income').val()) data[btoa('proof_of_income')] = btoa($('#proof_of_income').val());
if($('#bank_account').val()) data[btoa('bank_account')] = btoa($('#bank_account').val());
if(input.indexOf('#') != -1){
data[btoa(input.replace('#', ''))] = btoa($(input).val());
}
data[btoa('user_id')] = btoa(49095);
data[btoa('type')] = btoa('borrower');
data['_token'] = $('form').find('input[name="_token"]').val();
$.ajax({
url: 'https://staging.tutasa.com.uy/loan/save-temp-loan',
data: data,
type: 'POST',
cache: false,
dataType: "json"
});
});
});
$('#fast_track_code_status').val('');
$('.fast_track_code_error').hide();
if($('#fast_track_code').val() != '') {
if($('#fast_track_code_apply').length > 0) {
$( "#fast_track_code_apply" ).trigger( "click" );
}
}
function showIncomeFields(){
$('.income-employee').addClass('hidden');
$('.income-businessman').addClass('hidden');
$('.income-independent-professional').addClass('hidden');
$('.income-retired').addClass('hidden');
$('.income-allowances').addClass('hidden');
$('.income-rent').addClass('hidden');
$('.income-unemployed').addClass('hidden');
$('.income-'+$('#income_type').val()).removeClass('hidden');
}
showIncomeFields();
$('#income_type').change(function(){
showIncomeFields();
});
function monthlyIncomeText(){
console.log($('#monthly_income').val());
if($('#monthly_income').length && $.isNumeric($('#monthly_income').val()) && $('#monthly_income').val() > 0){
var data = {};
data[btoa('number')] = btoa($('#monthly_income').val());
data['_token'] = $('form').find('input[name="_token"]').val();
$.ajax({
url: 'https://staging.tutasa.com.uy/borrower/numbers-to-words',
data: data,
type: 'POST',
cache: false,
dataType: "json",
success: function(data) {
console.log(data);
if (data.status === true) {
$('#monthly_income_text').val(data.text.substr(0,1).toUpperCase() + data.text.substr(1));
}else{
$('#monthly_income_text').val('');
}
},
error: function(error) {
console.log(error);
$('#monthly_income_text').val('');
}
});
}else{
$('#monthly_income_text').val('');
}
}
monthlyIncomeText();
});
</script>
</div>
</div>
</div>
<script src="https://staging.tutasa.com.uy/js/underscore-min.js"></script>
<script src="https://staging.tutasa.com.uy/js/pdf/build/pdf.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/bootstrap.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/bootstrap-datepicker.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/angular.min.js"></script>
<script src="https://staging.tutasa.com.uy/js/bootbox.min.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/bootstrap-slider.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/heartcode-canvasloader-min.js"></script>
<script src="https://staging.tutasa.com.uy/js/inputmask/inputmask.js"></script>
<script src="https://staging.tutasa.com.uy/js/inputmask/jquery.inputmask.js"></script>
<script src="https://staging.tutasa.com.uy/js/inputmask/inputmask.numeric.extensions.js"></script>
<script src="https://staging.tutasa.com.uy/js/sliders.js?1512484810"></script>
<script src="https://staging.tutasa.com.uy/js/scripts.js?1512484810"></script>
</body>
</html>

Categories

Resources