Can I use both allowedOrigins(origins) and allowedOriginPatterns(origins)? - spring-mvc

I'm using Spring framework 5.3.17. In my addCorsMappings method I have below configuration. My question is should I use allowedOrigins(origins) or allowedOriginPatterns(origins) or both. Thanks in advance.
registry.addMapping("/**")
.allowedOrigins(origins)
.allowedOriginPatterns(origins)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowCredentials(true)
.maxAge(86400);

Related

Upload file size limit with custom webscript on Alfresco Community 5.2

I need help to upload document content back in Alfresco Community 5.2 though a share javascript.
The destination noderef is already existing, I upload a new version of a document.
I can't use the api/upload web service because I also need to do some operation on the noderef and I have a base64 content of the file which need to be converted.
So I wrote a new webscript and it is all working fine, at least while I upload documents which are smaller than 3MB,
Here it is the code
Alfresco.util.Ajax.request({
method: Alfresco.util.Ajax.POST,
dataObj: {
bytes: response.bytes,
digestAlgorithm: response.digestAlgorithm,
mimeType: response.mimeType.mimeTypeString,
name: response.name,
nodeRef: this.nodeRef,
signatureLevel: this.signatureLevel
},
url: thisClass.urlAlfrescoService + "myOrg/myPackage/uploadDocument",
successCallback: {
fn: thisClass._successOnUploadContent,
scope: this
},
failureCallback: {
fn: thisClass._errorOnUploadContent,
scope: this
},
scope: this,
noReloadOnAuthFailure: true
});
Do I miss some option to increase max upload file size?
I tryed uploading the file normally (with drag and drop) and it works.
The problem is when the file is >= 3MB the java class behind the webscript does not receive any byte
UPDATE
After some researches I found it could be a problem of how data are passed through POST, as application/x-www-form-urlencoded instead of multipart/form-data, but I can't find a way to specify the request content type in the ajax request
SOLUTION
The problem was the application/x-www-form-urlencoded instead of the multipart/form-data, I used a fetch POST request as stated here, but also the ajax request solution is good.
Last week,I had a same very similar problem with Alfresco AJAX request on Alfresco 5.0.2.5 and I used jquery's AJAX calls and it worked for me.
$.ajax({
url: Alfresco.constants.PROXY_URI + "your_web_script",
type: "POST",
data: dataFromFiles,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
dataType: "text",
success: function(data, textStatus, jqXHR) {
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
Reference link : https://blog.arvixe.com/sending-multipart-form-using-ajax/
Hope this helps you.

Decode jQuery dataTables aoData.push parameter in controller

I am using jQuery dataTables verion 1.9.4 and spring MVC. I want to pass encoded parameters to controller using aoData.push method. I have used :
aoData.push({"name":"message", "value":encodeURIComponent("test Message")})
.. But in the controller I am receiving test%20message instead test message. Is there any way to decode the dataTable parameters in controller like filters?
Any help or guidance would be appreciated.
You can try this:
nServerParams": function (aoData) {
aoData.push({ "name": "message", "value": encodeURIComponent("test
Message").replace(" ", "%20")});
},

How to include User-Agent info in a Meteor.http.call? MediaWiki requires it

Whenever I call the below method (CoffeeScript) that is on the server I get "Scripts should use an informative User-Agent string with contact information, or they may be IP-blocked without notice" from Wikipedia. How do I include user-agent info in the call? Or does it grab this from Meteor Accounts (which I'm not using yet)? thank you for any help...
Meteor.methods
wpSearch: (queryStr) ->
result = Meteor.http.call "GET", "http://en.wikipedia.org/w/api.php",
params:
action: "query"
list: "search"
format: "json"
srwhat: "text"
srsearch: queryStr
To clarify the previous answer for future visitors, the syntax for Meteor.http.get is as follows:
result = Meteor.http.get("https://api.github.com/user", {
headers: {
"User-Agent": "Meteor/1.0"
},
params: {
access_token: accessToken
}
});
Note the curly braces around the headers option and the comma afterwards separating the headers and params options (it's a syntax error without these things). This is example is part of the EventedMind how-to to customize the loginButtons during the onCreateUser() callback.
Just set User-Agent in the headers parameter (see http://docs.meteor.com/#meteor_http)
Meteor.methods
wpSearch: (queryStr) ->
result = Meteor.http.call "GET", "http://en.wikipedia.org/w/api.php",
headers:
"User-Agent": "Meteor/1.0"
params:
action: "query"
list: "search"
format: "json"
srwhat: "text"
srsearch: queryStr

MVC 3 AjaxHelper Ajax.ActionLink vs. Ajax.RouteLink, Ajax.BeginForm vs. AjaxBeginRouteForm

From my understanding
Ajax.ActionLink - Generates a link to a specific action in the current controller
Ajax.RouteLink - Generate a link based on RouteData provided to the helper
However I have been using MVC 3 and note that Ajax.ActionLink has many overloads which can accept just about anything Ajax.RouteLink can including RouteData, protocol, ActionName, ControllerName etc.
The same goes for Ajax.BeginForm and Ajax.BeginRouteForm
So am am missing something or are the Route versions obsolete?
The .Route versions are used to generate links based on route (name) configurations.
route configuration (ex: global.asax)
routes.MapRoute(
"faq",
"pages/faq",
new { controller = "Faq", action = "Index" }
);
usage in a view - with Html.ActionLink
#Ajax.ActionLink(linkText: "something", controller: "Faq", action: "Index")
usage in a view - with Html.RouteLink
#Ajax.RouteLink(linkText: "something", routeName: "faq")

how do you pass a parameter to an asp.net page method using jquery/ajax?

I'm trying to pass parameters to my static web method (which is in an asp.net page). I'm trying to pass the "test1" param with a value of "myvalue". Any ideas on what I am doing wrong?
$.ajax({
type: "POST",
url: "WebForm1.aspx/WebMethod1",
data: {"test1": "myvalue"},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});
my "data" section was wrong. it needs to be "{'test1':'myvalue'}"
What error are you getting?
I've used prototype before (similar to jQuery for ajax) and with that you don't quote the parameter names. So your data parameter should probably be:
data: {test1: "myvalue"}
Give that a shot.
You could also try setting up Fiddler and see the actual request being made.
The way you have it set up, any error that may occur in the ajax call will get silently swallowed. I'd suggest adding an error callback like this:
$.ajax({
type: "POST",
url: "WebForm1.aspx/WebMethod1",
data: {"test1": "myvalue"},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function(response) {
$('body',document).html(response.responseText);
}
});
Also, if you are using Visual Studio, you could run your ASP.NET app in debug mode to catch any server-side error. You can also put a breakpoint somewhere in the server-side code to make sure it's getting hit at all, and to inspect the Request.Form collection.
Hope this helps.

Resources