Why does Status.CLIENT_ERROR_UNAUTHORIZED in Restlet returns an EmptyRepresentation when post - restlet

The Post method in Restlet 2.x returns an EmptyRepresentation when Status.CLIENT_ERROR_UNAUTHORIZED, it does not do so in Get-method.
Why is that?

I can't reproduce your problem. Could you give the code you use so I can make a try? I guess that you use the method setStatus but you shoud throw a ResourceException with this status code.
When using this code:
public class TestServerResource extends ServerResource {
#Post
public Representation test(Representation repr) {
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED);
}
}
I have the following response:
405 Method Not Allowed
<html>
<head>
<title>Status page</title>
</head>
<body style="font-family: sans-serif;">
<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Method Not Allowed</p>
<p>The method specified in the request is not allowed for the resource identified by the request URI</p>
<p>You can get technical details here.<br>
Please continue your visit at our home page.
</p>
</body>
</html>
Hope it will help you.
Thierry

Related

I am trying to find an element within a <frame> using testcafe but i am unable to do so. is there a method to get this done please?

i have tried the following :
t.switchTo("frameID");
var ele = Selector("#ele");
await t.click(ele);
another attempt :
Selector(() =>{return document.getElementById("frameId").contentDocument.getElementById("#ele")});
This throws the following error : Function for selector should return DomElement, NodeList, HtmlCollection, NULL or undefined.
The HTML DOM is as follows :
<html>
<body>
<frameset>
<frame id='frame1'>
#document
<html>
<body>
<p id='ele1'>Hello World</p>
</body>
</html>
</frame>
</frameset>
</body>
</html>
The frame and frameset features are marked as obsolete in the W3C Recommendation. As TestCafe is based on HTML5 standards that do not support frameset, TestCafe does not support frameset either. So, we'd like to focus on up-to-date features, which will give the best experience in testing modern web applications.
As for the example you shared, you can use this test:
test('test', async t => {
await t.click('#ele1');
})

Styles and events not working in marko template

My component is loading fine but the styles are not loading, nor are the events firing. I am following the documentation and no errors are being thrown but it seems I might be missing something fundamental here?
View template rendered with res.marko:
import Explanation from "./components/explanation.marko";
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
...
<include(Explanation, input.explanation) />
...
</body>
</html>
explanation.marko file:
class {
onExplanationClick() {
console.log("Explanation clicked");
}
}
style {
.explanation-paragraph {
color: red;
}
}
<div id="explanation" on-click('onExplanationClick')>
<for (paragraph in input.content)>
<p class="explanation-paragraph">${paragraph}</p>
</for>
</div>
Server side:
app.get("/explanation/:id", async function(req, res) {
var explanation = await findExplanation(req.params.id);
var template = require("../../views/explanation/explanation.marko");
res.marko(template, { explanation, user: req.user });
});
Also using marko/node-require and marko/express.
You will need to integrate a module bundler/asset pipeline. In the sample marko-express app we are using Lasso (an asset pipeline + JavaScript module bundler).
There's also another sample app that integrates Webpack: https://github.com/marko-js-samples/marko-webpack
The Marko team supports both Lasso and Webpack, but we recommend Lasso because it is simpler and requires minimal configuration.
Please take a look at the marko-express app and feel free to ask questions in our Gitter chat room if you get stuck: https://gitter.im/marko-js/marko

Declaring Variables in DOJO

I am writing a JSP that displays a list of clubs in a grid. The grid shows the name of the club together with its latitude, longitude, website and description.
The actual data to be displayed is stored in a variable (a dojo.data.ItemFileWriteStore) called clubStore.
When the page is loaded, a call is made to a servlet to retrieve the data. The handling function then deletes all the items held in the store and adds new items returned by the servlet.
The JSP code is shown below:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clubs</title>
<style type="text/css">
#import "./dojoroot/dojo/resources/dojo.css";
#import "./dojoroot/dijit/themes/tundra/tundra.css";
#import "./dojoroot/dojox/grid/resources/Grid.css";
#import "./dojoroot/dojox/grid/resources/nihiloGrid.css";
</style>
<script type="text/javascript" src="dojoroot/dojo/dojo.js"
djConfig="parseOnLoad: true, isDebug: false">
</script>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojo.data.ItemFileWriteStore");
var clubData={
items:[{name:'No Clubs', lat:'---', lon:'---', webSite:'---', description:'---'}]
};
var layoutClub=[{field:"name", name:"Name", width:10},
{field:"lat", name:"Lat", width:5},
{field:"lon", name:"Long", width:5},
{field:"webSite", name:"Web Site", width:10},
{field:"description", name:"Description", width:'auto'}];
var clubStore=new dojo.data.ItemFileWriteStore(data:clubData});
</script>
<link rel="stylesheet" href="dojoroot/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="dojoroot/dojox/widget/Dialog/Dialog.css" />
</head>
<body class="tundra">
<%#include file="header.jsp"%>
<div id="clubGrid"
style="width: 800px;"
autoHeight="true"
data-dojo-type="dojox/grid/DataGrid"
data-dojo-props="store:clubStore,
structure:layoutClub,
query:{},
queryOptions:{'deep':true},
rowsPerPage:40">
</div>
<br>
<script>
var urlString="http://localhost:8080/BasicWeb/ClubsServlet";
dojo.xhrGet({
url: urlString,
handleAs: "text",
load: function(data) {
// remove items...
var allData=clubStore._arrayOfAllItems;
for (i=0; i<allData.length; i++) {
if (allData[i]!=null) {
clubStore.deleteItem(allData[i]);
}
}
var jsonClubArray=JSON.parse(data);
for (var i=0; i<jsonClubArray.clubs.length; i++) {
var club=jsonClubArray.clubs[i];
var newClub={name: club.clubname, lat:club.lat, lon:club.lon, webSite: club.website, description: club.description};
clubStore.newItem(newClub);
}
clubStore.save();
}
});
</script>
</body>
</html>
The script to process the servlet response sometimes fails because clubStore is undefined (debugging using Firebug). This does seem to be a spurious fault as some times everything works perfectly.
Any assistance in understanding how to define the clubStore variable would be appreciated.
Thanks.
James.
I think what might be happening is the body script is sometimes running before the head script, so it is kind of a race condition. You could try wrapping your body script into a dojo.ready. (I assume from your code that you are using dojo 1.6 or earlier since you are not using the AMD loader style.)
dojo.ready(function(){
// Put your xhr request code here.
});
You may also want to try testing with a firebug breakpoint in the head and body script. See if the head is sometimes running first.
So the problem turned out to be a syntax error in the declaration - missing '{' in the line
var clubStore=new dojo.data.ItemFileWriteStore(data:clubData});
The spurious aspect to the fault was a red herring - I had previously declared the variable as part of the DOM object and that caused a spurious fault. So I messed up my regression testing as well as introducing a syntax error!
Thanks.
James.
You could try switching the order of your require statements, so it's like this:
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojo.parser");
If that fails, you could set parseOnLoad to false, and then call dojo.parser.parse() after your store has been instantiated like so:
(assuming you are using dojo 1.6 or earlier based on your code)
dojo.addOnLoad(function() {
dojo.parser.parse();
});
Put your clubStore in the global space... just remove the var keyword in front of it...

Why imagecreatefromjpeg does not work in yii framework?

I'm trying to resize an image at runtime in yii, but does not work.
I tried this code in the view but it does not work.
My code in view.php
header('Content-Type: image/jpeg');
$image = imagecreatefromjpeg('image.jpg');
echo imagejpeg($image);
My code in controller
public function actionImage()
{
$this->render('image');
}
Output html
<html debug="true">
<body style="margin: 0px; ">
<img style="-webkit-user-select: none; " src="http://localhost/yiiadministration/index.php?r=administration/products/image"/>
</body>
<script src="chrome-extension://bmagokdooijbeehmkpknfglimnifench/googleChrome.js"/>
</html>
P.S; the code in the view is just to see the operation, and not to scale the image, because I normally do this in php.
Can anyone help?
A header has already been sent before the view is rendered so your code tries to send a new header and fails as it has already been sent.
You can either send that header from the controller or use an img tag in the view as said previously on stack overflow here
Also imagejpeg() outputs the image directly to the browser so the echo is wrong in that context.

"You broke Reddit" when submitting new story

I am making a Reddit app for the iPhone, and part of the app's functionality requires posting new stories (i.e. links or text) to Reddit.
When I attempt this, I make the following request and set the request's cookie based on a past login attempt:
http://www.reddit.com/api/submit/?uh=%#&text=TestofAPISubmitonapigee&kind=self&sr=redditdev&title=APISubmitTest&r=redditdev&api_type=json
(where %# is replaced by the user modhash, something along the lines of aa4aaaa3aaaaaa88ea8b19639c389521a813d21cb3e5688dbf)
Upon submitting the request, however, I receive this response:
<html>
<head>
<title>reddit broke!</title>
</head>
<body>
<div style="margin: auto; text-align: center">
<p>
<a href="/">
<img border="0" src="http://www.redditstatic.com/youbrokeit1.png" alt="you broke reddit" />
</a>
</p>
<p>
I've made a huge mistake!
</p>
</body>
</html>
Or a variation on the above message. Any thoughts on what I'm doing wrong?
I figured it out. All you have to do is put the POST data in the HTTP body of the NSMutableURLRequest using [request setHTTPBody:#"NSString of the POST data"]; rather than the above, which is technically a GET request. I found this confusing, since this method worked for logging in to Reddit using the API. It turns out that you can login by GETting, but you must POST to share a new link.