PDA

View Full Version : [FIXED][3.x] HttpProxy when configured with its own Connection instance



Animal
8 May 2009, 5:07 AM
It has



doRequest : function(action, rs, params, reader, cb, scope, arg) {
var method = (this.api[action]) ? this.api[action]['method'] : undefined;
var o = {
params : params || {},
method: method,
request: {
callback : cb,
scope : scope,
arg : arg
},
reader: reader,
callback : this.createCallback(action, rs),
scope: this
};

if(this.useAjax){
// Set the connection url. If this.conn.url is not null here,
// the user may have overridden the url during a beforeaction event-handler.
// this.conn.url is nullified after each request.
if (this.conn.url === null) {
this.conn.url = this.buildUrl(action, rs);
}
else if (this.conn.prettyUrls === true && rs instanceof Ext.data.Record && !rs.phantom) {
this.conn.url += '/' + rs.id;
}
Ext.applyIf(o, this.conn);

// If a currently running request is found for this action, abort it.
if (this.activeRequest[action]) {
Ext.Ajax.abort(this.activeRequest[action]);
}
this.activeRequest[action] = Ext.Ajax.request(o);

// request is sent, nullify the connection url in preparation for the next request
this.conn.url = null;

}else{
// url is not built correctly here when we are using a configured Connection as opposed to the Ajax instance.
// That url building code has to go outside of the conditional, and apply it to o
this.conn.request(o);
}

christocracy
10 May 2009, 9:30 AM
Ok, I'm on it.

christocracy
10 May 2009, 9:45 AM
Will this work for you, Nige?



doRequest : function(action, rs, params, reader, cb, scope, arg) {
var method = (this.api[action]) ? this.api[action]['method'] : undefined;
var o = {
params : params || {},
method: method,
request: {
callback : cb,
scope : scope,
arg : arg
},
reader: reader,
callback : this.createCallback(action, rs),
scope: this
};
// Set the connection url. If this.conn.url is not null here,
// the user may have overridden the url during a beforeaction event-handler.
// this.conn.url is nullified after each request.
if (this.conn.url === null) {
this.conn.url = this.buildUrl(action, rs);
}
else if (this.conn.prettyUrls === true && rs instanceof Ext.data.Record && !rs.phantom) {
this.conn.url += '/' + rs.id;
}
if(this.useAjax){

Ext.applyIf(o, this.conn);

// If a currently running request is found for this action, abort it.
if (this.activeRequest[action]) {
Ext.Ajax.abort(this.activeRequest[action]);
}
this.activeRequest[action] = Ext.Ajax.request(o);
}else{
this.conn.request(o);
}
// request is sent, nullify the connection url in preparation for the next request
this.conn.url = null;
},

Animal
10 May 2009, 10:10 AM
I haven't had a problem., I posted this here in response to someone's help thread. I'll try to find it and point them to here so they can test.

Animal
10 May 2009, 10:15 AM
I still don't think that's fully right... but then I use DWR at work, so I can't test it.

But if you look at the else side which uses this.conn.request(o), you see that o does not have the URL set into it.

Animal
10 May 2009, 10:20 AM
OK, I see it's setting it into the conn object.

But wouldn't this statement:



this.conn.url += '/' + rs.id;


Keep adding "/theId" to the end without ever removing the last used id?

christocracy
11 May 2009, 11:31 AM
Keep adding "/theId" to the end without ever removing the last used id?

No, but that bit is kind of tricky.

that else comes into play only when a user has added a beforewrite listener and manually changed the url.



new Ext.data.Store({
proxy: hproxy,
listeners: {
beforewrite : function(store, action, rs, options) {
switch (action) {
case 'create':
store.proxy.conn.url = '/some/different/url';
break;
}
}
})




doRequest : function(action, rs, params, reader, cb, scope, arg) {
var method = (this.api[action]) ? this.api[action]['method'] : undefined;
var o = {
params : params || {},
method: method,
request: {
callback : cb,
scope : scope,
arg : arg
},
reader: reader,
callback : this.createCallback(action, rs),
scope: this
};
// Set the connection url. If this.conn.url is not null here,
// the user may have overridden the url during a beforeaction event-handler.
// this.conn.url is nullified after each request.
if (this.conn.url === null) {
this.conn.url = this.buildUrl(action, rs);
}
else if (this.conn.prettyUrls === true && rs instanceof Ext.data.Record && !rs.phantom) {
// This is the tricky part...in beforewrite above, I changed url and since they have prettyUrls on,
// I'm automatically tacking on the /id for them. It's an assumption. Maybe I should do nothing
// here, that is, if user modifies url in mid-request, it's Caveat Emptor.
this.conn.url += '/' + rs.id;
}
if(this.useAjax){

Ext.applyIf(o, this.conn);

// If a currently running request is found for this action, abort it.
if (this.activeRequest[action]) {
Ext.Ajax.abort(this.activeRequest[action]);
}
this.activeRequest[action] = Ext.Ajax.request(o);
}else{
this.conn.request(o);
}
// request is sent, nullify the connection url in preparation for the next request
this.conn.url = null; // <-- this.conn.url get nullified after each request and rebuilt again via buildUrl
},

aconran
12 May 2009, 9:47 AM
Closing this ticket as it looks to be resolved. Could someone please verify?

On a sidenote, what do you guys think about abstracting the prettyUrls configuration into a RestfulStore subclass instead of making it a config?

Animal
14 May 2009, 12:02 AM
I think it's a good idea. IMHO (as a Java developer who expects to process HTTP params at a resource allocated to a fixed URI), this concept of having a URI specify an instance is nonstandard.

christocracy
14 May 2009, 9:23 AM
Right, so you wouldn't touch the config-param prettyUrls then, which is default false.

aconran
14 May 2009, 12:36 PM
Right, so you wouldn't touch the config-param prettyUrls then, which is default false.

Yea. Let's remove the prettyUrls configuration and create it as a subclass which people who are using a RESTful architecture can use.