HtmlUnit does not load entire page - amazon-cloudfront

I have checked that HtmlUnit does not load part of this page:
https://www.milanuncios.com/mis-anuncios/
When inspected with a browser, the section:
<div class="ma-LayoutBasicMainContent">
Has into a lot of contents. But when loaded by HtmlUnit it is empty!
I have tried various webClient switches, including
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setDownloadImages(true);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.setJavaScriptTimeout(10000);
But always with same result: The "ma-LayoutBasicMainContent" section is not loaded. This is the code I use:
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.*;
class MarnvHtmlUnitTest {
public static void main(String[] args) {
WebClient webClient = null;
try {
final long javascriptTimeout = 10000;
webClient = new WebClient();
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setDownloadImages(true);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.setJavaScriptTimeout(10000);
String loginURL = "https://www.milanuncios.com/mis-anuncios/";
System.out.println("Connecting to " + loginURL + " (" + webClient.getBrowserVersion() + ")");
HtmlPage page = webClient.getPage(loginURL);
System.out.print(" Waiting for Javascript to complete...");
long millis = System.currentTimeMillis();
webClient.waitForBackgroundJavaScript(javascriptTimeout);
System.out.println(System.currentTimeMillis() - millis + " milliseconds");
if (!page.asText().contains("gestiona tus anuncios")) {
System.out.println("ERROR!");
System.out.println(page.asXml());
System.out.println("EXITING. " + webClient.getWebWindows().size());
return;
}
System.out.println("OK");
} catch (Exception e) {
e.printStackTrace();
}
finally {
if (webClient != null)
webClient.close();
}
}
}
In case of correct page loading, the page should contain the text "gestiona tus anuncios".
Note that the call to "waitForBackgroundJavaScript" returns inmediately, which for me it's strange... it normaly waits some seconds until the page is completely loaded. I am using HtmlUnit 2.36.0.

Related

Testing for file upload in Spring MVC

Project setup:
<java.version>1.8</java.version>
<spring.version>4.3.9.RELEASE</spring.version>
<spring.boot.version>1.4.3.RELEASE</spring.boot.version>
We have a REST controller that has a method to upload file like this:
#PostMapping("/spreadsheet/upload")
public ResponseEntity<?> uploadSpreadsheet(#RequestBody MultipartFile file) {
if (null == file || file.isEmpty()) {
return new ResponseEntity<>("please select a file!", HttpStatus.NO_CONTENT);
} else if (blueCostService.isDuplicateSpreadsheetUploaded(file.getOriginalFilename())) {
return new ResponseEntity<>("Duplicate Spreadsheet. Please select a different file to upload",
HttpStatus.CONFLICT);
} else {
try {
saveUploadedFiles(Arrays.asList(file));
} catch (IOException e) {
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity("Successfully uploaded - " + file.getOriginalFilename(), new HttpHeaders(),
HttpStatus.OK);
}
}
UPDATE:
I've tried this approach from an old example I found, but it doesn't compile cleanly, the MockMvcRequestBuilders.multipart method is not defined....
#Test
public void testUploadSpreadsheet_Empty() throws Exception {
String fileName = "EmptySpreadsheet.xls";
String content = "";
MockMultipartFile mockMultipartFile = new MockMultipartFile(
"emptyFile",
fileName,
"text/plain",
content.getBytes());
System.out.println("emptyFile content is '" + mockMultipartFile.toString() + "'.");
mockMvc.perform(MockMvcRequestBuilders.multipart("/bluecost/spreadsheet/upload")
.file("file", mockMultipartFile.getBytes())
.characterEncoding("UTF-8"))
.andExpect(status().isOk());
}
I believe MockMvcRequestBuilders.multipart() is only available since Spring 5. What you want is MockMvcRequestBuilders.fileUpload() that is available in Spring 4.

Cisco JTAPI phone register/unregister status

I am using the below code to check the phone status(if phone is up or down). When phone is down sends an alarm. However this doesn't show when 8800 series phones are down. Is there any other method to check the Phone register/unregister status?
#Override public void terminalChangedEvent(TermEv[] eventList) {
if ( eventList != null ) {
for (TermEv eventList1 : eventList) {
if (eventList1 instanceof CiscoTermInServiceEv){
if(terminalInService.test()==true){
LogSQL.removeLog(terminal.getName());
}
System.out.println(terminal.getName());
terminalInService.set();
return;
} else if (eventList1 instanceof CiscoTermOutOfServiceEv &&
terminalInService.test()==true) {
offline();
}
}
}
}
Second Question, I was not able to find the methods or documentation about "com.cisco.cti.util.Condition" class. What does Condition.set() and Condition.test() methods do?
Looks like you have the right general idea - JTAPI should work fine for 88xx models, assuming you have the correct device->user association, and user permissions (Standard CTI Enabled, and Standard CTI Allow Control of Phones supporting Connected Xfer and conf needed for 88xx).
Here is my version working on CUCM 11.5:
package com.mycompany.app;
import com.cisco.jtapi.extensions.*;
import java.util.*;
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.callcontrol.*;
import javax.telephony.callcontrol.events.*;
import com.cisco.cti.util.Condition;
public class DataTerm implements ProviderObserver, TerminalObserver {
public static final int OUT_OF_SERVICE = 0;
public static final int IN_SERVICE = 1;
private Address destAddress;
private CiscoTerminal observedTerminal;
private boolean addressInService;
private boolean terminalInService;
protected int state = OUT_OF_SERVICE;
Condition conditionInService = new Condition();
Provider provider;
public DataTerm(String[] args) {
try {
System.out.println("Initializing Jtapi");
String providerName = "ds-ucm115-1.cisco.com";
String login = "dstaudt";
String passwd = "password";
String dest = "2999";
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
String providerString = providerName + ";login=" + login + ";passwd=" + passwd;
System.out.println("Opening " + providerString + "...\n");
provider = peer.getProvider(providerString);
provider.addObserver(this);
conditionInService.waitTrue();
this.destAddress = provider.getAddress(dest);
this.observedTerminal = (CiscoTerminal) destAddress.getTerminals()[0];
try {
if (destAddress != null) {
System.out.println("Adding Terminal Observer to Terminal" + observedTerminal.getName());
observedTerminal.addObserver(this);
}
} catch (Exception e) {
}
} catch (Exception e) {
System.out.println("Caught exception " + e);
}
}
public void terminalChangedEvent(TermEv[] events) {
for (int i = 0; i < events.length; i++) {
Terminal terminal = events[i].getTerminal();
switch (events[i].getID()) {
case CiscoTermInServiceEv.ID:
System.out.println("Received " + events[i] + "for " + terminal.getName());
terminalInService = true;
break;
case CiscoTermOutOfServiceEv.ID:
System.out.println("Received " + events[i] + "for " + terminal.getName());
terminalInService = false;
if (state != OUT_OF_SERVICE) { // you only want to notify when you had notified earlier that you are IN_SERVICE
state = OUT_OF_SERVICE;
}
break;
}
}
}
public void providerChangedEvent(ProvEv[] eventList) {
if (eventList != null) {
for (int i = 0; i < eventList.length; i++) {
if (eventList[i] instanceof ProvInServiceEv) {
conditionInService.set();
}
}
}
}
}
The "com.cisco.cti.util.Condition" seems to be based on this pattern:
public interface Condition
Condition factors out the Object monitor methods (wait, notify and notifyAll) into distinct objects to give the effect of having multiple wait-sets per object, by combining them with the use of arbitrary Lock implementations. Where a Lock replaces the use of synchronized methods and statements, a Condition replaces the use of the Object monitor methods.
Conditions (also known as condition queues or condition variables) provide a means for one thread to suspend execution (to "wait") until notified by another thread that some state condition may now be true. Because access to this shared state information occurs in different threads, it must be protected, so a lock of some form is associated with the condition. The key property that waiting for a condition provides is that it atomically releases the associated lock and suspends the current thread, just like Object.wait.
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Condition.html

phantomjs exception error on Linux(64bit) org.openqa.selenium.NoSuchElementException

the code runs well in my localhost(win10), but exception error on Linux(64bt) :
org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with id 'magix_vf_root'","request":{"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"38","Content-Type":"application/json; charset=utf-8","Host":"localhost:12709"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"magix_vf_root\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/350bd6e0-8784-11e6-b57c-35629091c8a9/element"}}
Command duration or timeout: 60.32 seconds
Here is my code:
public static void testPhantomjs() throws IOException{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "F:\\selenium\\phantomjs.exe");
//caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/opt/phantomjs");
//System.setProperty("webdriver.chrome.driver", "F:\\selenium\\phantomjs.exe");
WebDriver d = new PhantomJSDriver(caps);
try{
//d.manage().timeouts().setScriptTimeout(20L, TimeUnit.SECONDS);
d.manage().timeouts().implicitlyWait(60L, TimeUnit.SECONDS);
d.get("http://www.alimama.com/member/login.htm?forward=http%3A%2F%2Fpub.alimama.com%2Fmyunion.htm");
d.manage().window().maximize();
d = d.switchTo().frame(d.findElement(By.name("taobaoLoginIfr")));
//WebElement quick = new WebDriverWait(d, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("J_Quick2Static")));
//new Actions(d).moveToElement(quick).click().perform();
//quick.click();
d.findElement(By.id("J_Quick2Static")).click();
//d.findElement(By.id("TPL_username_1")).clear();
d.findElement(By.id("TPL_username_1")).sendKeys("username");
//d.findElement(By.id("TPL_password_1")).clear();
d.findElement(By.id("TPL_password_1")).sendKeys("password");
getScreenshot(d, "1");
d.findElement(By.id("J_SubmitStatic")).click();
//d.switchTo().defaultContent();
getScreenshot(d , "2");
d.findElement(By.id("magix_vf_root"));
getScreenshot(d , "3");
Set<Cookie> cookies = d.manage().getCookies();
StringBuffer sb = new StringBuffer();
for (Cookie cookie : cookies) {
sb.append(cookie.getName() + "=" + cookie.getValue() + ";");
}
System.out.println("cookiestr:" + sb.toString());
}catch(Exception e){
e.printStackTrace();
}finally{
getScreenshot(d, "finally");
d.quit();
}
}
And the result message:
the code runs well in my localhost(win10),but exception error on Linux(64bt): org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with id 'magix_vf_root'"
It looks like timing issue, you should try using WebDriverWait to wait until element is present on the DOM as below :-
WebElement quick = new WebDriverWait(d, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("magix_vf_root")));

PushSharp for APNS works on local server but not on azure

I am using push sharp in a ASP.NET web api server. on my local computer everything works like a charm for GCM and APNS but once uploaded to azure only the GCM messages work. the APNS is not working, not throwing exceptions nothing. I have traces in every event the push broker throws but no trace message is called. not even the message queued...
Here is my initialization code:
public PushNotificationManager()
{
_pushService = new PushBroker();
_pushService.OnChannelCreated += OnChannelCreated;
_pushService.OnChannelDestroyed += OnChannelDestroyed;
_pushService.OnChannelException += OnChannelException;
_pushService.OnDeviceSubscriptionChanged += OnDeciveSubscriptionChanged;
_pushService.OnDeviceSubscriptionExpired += OnDeviceSubscriptionExpired;
_pushService.OnNotificationFailed += OnNorificationFailed;
_pushService.OnNotificationRequeue += OnNotificationQueued;
_pushService.OnNotificationSent += OnNOtificationSend;
_pushService.OnServiceException += OnServiceException;
InitAndroidPushService();
InitApplePushService();
}
private void InitApplePushService()
{
try
{
string appDataPath = HttpContext.Current.Server.MapPath("~/app_data");
//***** Development Server *****//
//string file = Path.Combine(appDataPath, "PushSharp.PushCert.Development.p12");
//var appleCert = File.ReadAllBytes(file);
// _applePushService = new ApplePushService(new ApplePushChannelSettings(false, appleCert, "XXXXXXX"));
//***** Production Server *****//
string file = Path.Combine(appDataPath, "PushSharp.PushCert.Production.p12");
var appleCert = File.ReadAllBytes(file);
_pushService.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "XXXXXX"));
Trace.TraceInformation("ApplePushService initialized succesfully");
}
catch (Exception e)
{
Trace.TraceError("Error initializing ApplePushService : " + e);
throw;
}
}
private void InitAndroidPushService()
{
try
{
_pushService.RegisterGcmService(new GcmPushChannelSettings("XXXXXX", "XXXXXX",
"XXXXX"));
Trace.TraceInformation("GooglePushService initialized succesfully");
}
catch (Exception e)
{
Trace.TraceError("Error initializing AndroidPushService : " + e);
}
}
Has anyone enountered such a thing?

LWUIT4IO (v1.5) ConnectionRequest's readResponse() Issue - Nokia SDK 2.0

I have been porting an existing J2ME mobile app, that allows users to view archived news videos, to the latest Nokia SDK 2.0 platform for Series 40 full-touch devices.
I am using both the LWUIT and LWUIT4IO technologies for the UI and Network functionalities of the application respectively.
The app has been tested to work on the S40 5th Edition SDK platform emulator. Extending LWUIT4IO's ConnectionRequest class and utilizing LWUIT's XMLParser, the app can successfully send a HTTP request and get the expected response data from a web service that basically returns an XML-formatted type of feed (containing necessary metadata for the video) (Here's the URL of the web service: http://nokiamusic.myxph.com/nokianewsfeed.aspx?format=3gp)
But for some reason, this is not the case when trying to run the app on the latest Nokia SDK 2.0 platform. It throws a java.lang.NullPointerException upon trying to parse (XMLParser.parse()) the InputStream response of the web service. When I trace the Network Traffic Monitor of the emulator of the corresponding Request sent and Response received - 0 bytes were returned as content despite a successful response status 200. Apparently the XMLParser object has nothing to parse in the first place.
I am hoping that you can somehow shed light on this issue or share any related resolutions, or help me further refine the problem.
Posted below is the code of the SegmentService class (a sub-class of LWUIT's ConnectionRequest) that connects to the webservice and processes the XML response:
public class SegmentService extends ConnectionRequest implements ParserCallback {
private Vector segments;
private Video segment;
public SegmentService(String backend) {
String slash = backend.endsWith("/") ? "" : "/";
setPost(false);
setUrl(backend + slash + "nokianewsfeed.aspx");
addArgument("format", "3gp");
}
public void setDateFilter(String date) {
System.out.println(date);
addArgument("date", date);
}
private Video getCurrent() {
if (segment == null) {
segment = new Video();
}
return segment;
}
protected void readResponse(InputStream input) throws IOException {
InputStreamReader i = new InputStreamReader(input, "UTF-8");
XMLParser xmlparser = new XMLParser();
System.out.println("Parsing the xml...");
Element element = xmlparser.parse(i);
System.out.println("Root " + element.getTagName());
int max = element.getNumChildren();
System.out.println("Number of children: " + max);
segments = new Vector();
for (int c = 0; c < max; c++) {
Element e = element.getChildAt(c);
System.out.println("segment " + c);
int len = e.getNumChildren();
System.out.println("Number of children: " + len);
for (int d=0; d<len; d++) {
Element s = e.getChildAt(d);
String property = s.getTagName();
System.out.println("key: " + property);
String value = (s.getNumChildren()>0) ? s.getChildAt(0).getText() : null;
System.out.println("value: " + value);
if (property.equals("title")) {
getCurrent().setTitle(value);
} else if (property.equals("description")) {
getCurrent().setDescription(value);
} else if (property.equals("videourl")) {
getCurrent().setVideoUrl(value);
} else if (property.equals("thumburl")) {
getCurrent().setThumbUrl(value);
} else if (property.equals("adurl")) {
getCurrent().setAdUrl(value);
} else if (property.equals("publishdate")) {
getCurrent().setPublishDate(value);
} else if (property.equals("category")) {
getCurrent().setCategory(value);
} else if (property.equals("weburl")) {
getCurrent().setWebUrl(value);
} else if (property.equals("thumburl2")) {
getCurrent().setThumb210(value);
} else if (property.equals("thumburl4")) {
getCurrent().setThumb40(value);
}
}
if (segment != null) {
segments.addElement(segment);
segment = null;
}
}
fireResponseListener(new NetworkEvent(this, segments));
}
public boolean parsingError(int errorId, String tag, String attribute, String value, String description) {
System.out.println(errorId);
System.out.println(tag);
System.out.println(value);
System.out.println(description);
return true;
}
}

Resources