Use properties of browserfield in http connection - blackberry

I am accessing https site(sample.aspx), To access the site we need useragent, javascript,cookie must be enabled,So i tried in browser field i am getting correct proper response,Where as in http connection i cant get the response.Please help me how to use the following properties in http connection,
String userAgent = "BlackBerry" + DeviceInfo.getDeviceName() + "/" + DeviceInfo.getSoftwareVersion() +" Profile/" + System.getProperty("microedition.profiles") +" Configuration/" + System.getProperty( "microedition.configuration") + " VendorID/" + Branding.getVendorId()
BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.USER_AGENT, userAgent);
config.setProperty(BrowserFieldConfig.ENABLE_COOKIES,Boolean.TRUE);
config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
myBrowserField = new BrowserField(config);
I need to enable javascript and cookies and in my http connection.

you can call something like
httpConnection.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");

Related

How to resolve Default parser issue?

Hi i am getting the following error when trying to run a post req. Are there any dependencies that are missing ?
Exception in thread "main" java.lang.IllegalStateException: Cannot invoke the path method because no content-type was present in the response and no default parser has been set.
You can specify a default parser using e.g.:
RestAssured.defaultParser = Parser.JSON;
String a= "80820221";
String body= "{\n" +
" \"request\": {\n" +
" \"id\": \"" + a + "\",\n" +
" \"id2\": \"800002400434\",\n" +
" \"id3\": \"\",\n" +
" \"id4\": \"WEB\"\n" +
" }\n" +
"}";
RequestSpecBuilder reqBuilder = new RequestSpecBuilder();
// Setting Base URI
reqBuilder.setBaseUri(base);
// Setting Base Path
reqBuilder.setBasePath(basePath");
reqBuilder.setContentType(ContentType.JSON);
// Getting RequestSpecification reference using builder() method
RequestSpecification reqSpec = reqBuilder.build();
Response response = RestAssured.given(reqSpec).body(body).log().all().when().post().then().log().all().extract().response();
int status = response.getStatusCode();
System.out.println(status);
**String successMessage = response.getBody().path("response.status")**;
System.out.println(successMessage);
it is giving errror in the above line
i am expecting 200 response. In postman it is giving 200 but in script it is returning 400 and unable to get the response body

How to change JSESSIONID in Vaadin after login

Im trying to change the JSESSIONID in vaadin after login.
this is my code
System.out.println("0000.....OLD-SESSION: " + VaadinSession.getCurrent().getSession().isNew());
System.out.println("0000.....OLD-SESSION-ID: " + VaadinSession.getCurrent().getSession().getId());
VaadinSession.getCurrent().getSession().invalidate();
WrappedSession newSession = VaadinService.getCurrentRequest().getWrappedSession(true);
System.out.println("1111.....NEW-SESSION: " + newSession.isNew());
System.out.println("1111.....NEW-SESSION-ID: " + newSession.getId());
VaadinService.getCurrentResponse().addCookie(new Cookie("JSESSIONID", newSession.getId()));
///////////////////// OUTPUT ////////////////////////
0000.....OLD-SESSION: false
0000.....OLD-SESSION-ID: F353B452D148B35E71920C73EA3BB7AA
1111.....NEW-SESSION: true
1111.....NEW-SESSION-ID: 8C6E4EF40724C060B9B10C1E70FB2441
JSESSIONID is changeing successfully but after login on my dashboard im getting SESSION EXPIRED box. How can i resolve this in Vaadin.
MY AIM: change JSESSION ID after login in VAADIN
NOW IM DOING SOMETHING LIKE THIS, im using VaadinService.reinitializeSession
System.out.println("0000.....OLD-SESSION: " + VaadinSession.getCurrent().getSession().isNew());
System.out.println("0000.....OLD-SESSION-ID: " + VaadinSession.getCurrent().getSession().getId());
for (Cookie cookie : VaadinService.getCurrentRequest().getCookies())
{
System.out.println("OLD:: " + cookie.getName() + " - " + cookie.getValue());
}
// VaadinSession.getCurrent().getSession().invalidate();
// WrappedSession newSession = VaadinService.getCurrentRequest().getWrappedSession(true);
VaadinService.reinitializeSession(VaadinService.getCurrentRequest());
System.out.println("1111.....NEW-SESSION: " + VaadinSession.getCurrent().getSession().isNew());
System.out.println("1111.....NEW-SESSION-ID: " + VaadinSession.getCurrent().getSession().getId());
for (Cookie cookie : VaadinService.getCurrentRequest().getCookies())
{
System.out.println("NEW:: " + cookie.getName() + " - " + cookie.getValue());
}
VaadinService.getCurrentResponse().addCookie(new Cookie("JSESSIONID", VaadinSession.getCurrent().getSession().getId()));
///////////////// NEW OUTPUT /////////////////
0000.....OLD-SESSION: false
0000.....OLD-SESSION-ID: 7115CC9FF20C2CB485B9F35FDCCF7DEE
OLD:: JSESSIONID - 0D9FCDE46EC8BFDF90A267E01F763EE9
OLD:: JSESSIONID - 7115CC9FF20C2CB485B9F35FDCCF7DEE
1111.....NEW-SESSION: true
1111.....NEW-SESSION-ID: 44969C81DAA007B8CF296C8FCEE6581D
NEW:: JSESSIONID - 0D9FCDE46EC8BFDF90A267E01F763EE9
NEW:: JSESSIONID - 7115CC9FF20C2CB485B9F35FDCCF7DEE
but JSESSIONID is not updating on browser cookie
Use VaadinService.reinitializeSession
I'm using spring security session fixation. In my case, the login and the dashboard respectively has own UI. After the login happen a redirect (site reload) to dashboard.
Spring security generates the new session and migrate necessary data. The new session id is written in the cookie in browser while redirect.

Receive data from web server

I have a problem in a program that implements a simple web server.
When I send HTTP request to the webserver, the webserver sends HTTP code to client, but I want to receive => I have error "Connection is reset!)
clientSocket = new Socket("localhost", 1234);
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(
new BufferedOutputStream(clientSocket.getOutputStream()), "UTF-8")
);
out.write(OUTPUT_HEADERS+"GET /"+"home.html" + " HTTP/1.1\nHost:"+clientSocket.getLocalAddress() +"\nUser-agent: Mozilla/5.0\nAccept-language: fa");
out.flush();
System.out.println(" waiting...");
InputStreamReader isr=new InputStreamReader(clientSocket.getInputStream());
BufferedReader br=new BufferedReader(isr);
while (br.ready()) {
System.out.println(br.readLine());
}
According to the HTTP 1.1 spec:
http://www.w3.org/Protocols/HTTP/1.1/rfc2616bis/draft-lafon-rfc2616bis-03.html#request
The request and request headers needs to be terminated with CR/LF.
i.e. Change:
out.write(OUTPUT_HEADERS+"GET /"+"home.html" + " HTTP/1.1\nHost:"+clientSocket.getLocalAddress() +"\nUser-agent: Mozilla/5.0\nAccept-language: fa");
out.flush();
to
out.write(OUTPUT_HEADERS+"GET /"+"home.html" + " HTTP/1.1\r\nHost:"+clientSocket.getLocalAddress() +"\r\nUser-agent: Mozilla/5.0\r\nAccept-language: fa\r\n");
out.write("\r\n");
out.flush();

Titanium Studio to Grails imge post

I am trying to POST an image to my grails application and I'm not having much luck.
My titanium code is:
function upload(){
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function(e){
Ti.API.info(picMedia + " : " +message.value);
Ti.API.info('IN ERROR ' + e.error);
alert('Sorry, we could not upload your photo! Please try again.');
};
xhr.onload = function(){
Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState);
};
xhr.onsendstream = function(e){
Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress);
};
// open the client
xhr.open('POST', 'http://localhost:8080/FYP/Profile/appUploader');
// send the data
xhr.send({
media: picMedia,
message: message.value,
});
}
My grails code is as follows:
def appUploader(){
println "MEDAI PARAMS: " + params.media
def f = request.getFile('media') ;
println "HERE: " + f
if (request.getFile(params.media).getOriginalFilename()) {
println "FROM APP: " + request.getFile('myFile').getOriginalFilename()
return
}
}
Im getting error from the mobile app and error on the "if" line in the web app.
What am i doing wrong?
we had the same problem in one of our apps. The difficulty is that titanium is not really able to handle binary files in that case.
We did the following:
create base64 encoded string of the image on client side
post this string to the backend
decode base64 to image again
We analyzed a lot of network traffic and in most cases titanium tries to send the file but due to javascript its alway converted into some kind of ascii and this is not usable by the server side.

Nodejs : Redirect URL

I'm trying to redirect the url of my app in node.js in this way:
// response comes from the http server
response.statusCode = 302;
response.setHeader("Location", "/page");
response.end();
But the current page is mixed with the new one, it looks strange :| My solution looked totally logical, I don't really know why this happens, but if I reload the page after the redirection it works.
Anyway what's the proper way to do HTTP redirects in node?
Looks like express does it pretty much the way you have. From what I can see the differences are that they push some body content and use an absolute url.
See the express response.redirect method:
https://github.com/visionmedia/express/blob/master/lib/response.js#L335
// Support text/{plain,html} by default
if (req.accepts('html')) {
body = '<p>' + http.STATUS_CODES[status] + '. Redirecting to ' + url + '</p>';
this.header('Content-Type', 'text/html');
} else {
body = http.STATUS_CODES[status] + '. Redirecting to ' + url;
this.header('Content-Type', 'text/plain');
}
// Respond
this.statusCode = status;
this.header('Location', url);
this.end(body);
};
server = http.createServer(
function(req, res)
{
url ="http://www.google.com";
body = "Goodbye cruel localhost";
res.writeHead(301, {
'Location': url,
'Content-Length': body.length,
'Content-Type': 'text/plain' });
res.end(body);
});
Yes it should be full url in setHeader.
res.statusCode = 302;
res.setHeader('Location', 'http://' + req.headers['host'] + ('/' !== req.url)? ( '/' + req.url) : '');
res.end();
What happens if you change it to 307 instead?
This issue may also depend on the type of request you are handling. A POST request cannot be redirected using the header. For example, a first-time visitor from to your app in FB will most-likely be coming via a "signed request" POST and therefore a redirect will not work.

Resources