Struts2 upload file by POSTing - servlets

So I'm trying to integrate wami-recorder into my webapp. The webapp currently is built using the Struts2 framework.
There is an example on StackOverflow here on how to integrate wami-recorder into a php site. How would I achieve similar functionality using Struts2? It seems like wami tries to POST the file to a certain URL. How do I get Struts2 to receive such a file? Or is there a better way to go about this?
EDIT: MMk so, I used Dave's wording to search google and found this. Right now, my action's execute method looks like
HttpServletRequest request = ServletActionContext.getRequest();
InputStream body = null;
try {
body = request.getInputStream();
OutputStream outputStream = new FileOutputStream("/home/test.mp3");
IOUtils.copy(body, outputStream);
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return SUCCESS;'
However, when I use wami to POST
Wami.startRecording("http://localhost:8080/addRecording/test.wav");
I get the following in chrome developer tools:
Request URL:http://localhost:8080/addRecording/test.wav
Request Method:POST
Status Code:404 Not Found
Is there something wrong with the configuration of my action class? Or am I misusing wami?

Turns out with the updated code the file is actually being stored. Getting a 404 for other reasons. In any case, my question is answered.

Related

Firebase dynamic link custom params

'm having trouble with the final steps implementing firebase to our unity app, any help would be really really appreciated
The problem involves receiving custom parameters when the app is opened by a dynamic link
The app opens fine, redirects to store etc if needed so that's ok but when I try to use the custom parameter it never holds the desired info but instead returns the fallback url to our website, I'm using the on link received function copied from dynamic link test app.
the outgoing link looks like this - "https://fbb.page.link/PL/?p=XXXXXXXXXX; where XXXXX is the param im looking for
void Start() {
DynamicLinks.DynamicLinkReceived += OnDynamicLink;
}
void OnDynamicLink(object sender, EventArgs args) {
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}",
dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
// Display the dynamic link received by the application.
void OnDynamicLink(object sender, EventArgs args) {
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}",
dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
but the recieved link returns our homepage and not 'p'
Again any help much appreciated
I finally found the reason this wasnt working for me so for anyone searching as this has been troubling us for some time.
In the end it was because I was using a shortened link which was occluding the parameters I needed, once I tried using the original long link it worked straight away
So for cleanliness sake, I use a link to our website plus the required param, the site takes the param and inserts it into a preset long dynamic link url and redirects to that link, this gives us a nice tidy url with the benefits of parameters

Adding an Event for Espresso on Wordpress from C#

Working with WordPress and the Espresso Plugin for Events. I've never dealt with WP or Plugin's before, so I'm in new territory.
I am attempting to add an event and I keep getting the following error:
{"code":"rest_cannot_create_events","message":"Sorry, you are not allowed to create events. Missing permissions: ee_edit_events,ee_edit_others_events,ee_edit_private_events","data":{"status":403}}
I've gone into the WP admin pages and made sure the user I am trying to login as has all the permissions for this plugin.
The first thing I do is access the /wp-login.php page to get the Cookies:
string formVars = "";
string result = "";
string eventUrl = $"<url>/wp-login.php";
Dictionary<string, string> headers = new Dictionary<string, string>();
formVars = $"log={UserName}&pwd={Password}";
Cookie = new System.Net.CookieContainer();
AllowAutoRedirect = false;
result = PerformPost(eventUrl, formVars, true, headers);
The PerformPost uses an HttpWebRequest to send and receive.
That part seems to work and I get what looks like valid cookies.
I then do another post to /wp-json/ee/v4.8.29/events/ and pass in the body just the name of the event like EVT_name=TestEvent.
It's at this point that I get the the error mentioned above.
So a couple of questions.
1) Has anyone done this before? (Added an Event to Espresso on WordPress)
2) If Espresso doesn't like what I am feeding it, does it generate this error rather than just telling me I'm not giving it the correct information?
I've also tried using the Basic Auth plugin with the same results.
Any help is greatly appreciated.

Check if a webpage is online using VB in asp.net

I have been toying with getting this working for a while now to no avail.
I want to check if a website is available and display its status in a label. I have no code to share as I haven't got this anywhere close. I am using VS 2013 building a asp.net website using VB.
I thought I could just ping the website but after multiple test using command.exe the website doesn't respond to pings even when up.
I know the page will be taken offline periodically for updates as this happened last week and when it is you get page cannot be displayed. I need to test if the page is online and return true if it is and false if not.
The simple way is to do an httpWebRequest and examine the result. If the page doesn't exist, you will get an error that indicates that. I'm not as familiar with .webClient but that apparently works as well.
This past question gives you examples of both.
You can easily do this using HttpWebRequest.
try {
HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("siteAddress");
HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
myHttpWebResponse.Close();
}
catch(WebException e) {
//There is a problem accessing the site
}

Can't get profile data in Application_Start

I have the following code at some point in Application_Start
MembershipUserCollection users = Membership.GetAllUsers();
foreach (MembershipUser u in users)
{
ProfileBase profile = ProfileBase.Create(u.UserName, false);
if (profile["Index"] != null)
{
// Some code
}
}
The problem is that when i try to access the profile properties I get "Request is not available in this context" httpException. I have tried using profile.GetPropertyValue but no luck also.
Why does profile need the request object and how can I get this to work?
EDIT:
I have looked into the .NET code and found that at some point SqlProfileProvider.GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc) is called, inside of which rests this string of code:
if (!current.Request.IsAuthenticated)
Apparently this will never work if not in request context. The workaround descripbed in Onur's answer will work fine.
Apparently you are trying to access request object which is not possible in your case.
Please take a look following link and apply one of workarounds if possible.
http://mvolo.com/iis7-integrated-mode-request-is-not-available-in-this-context-exception-in-applicationstart
and if you give more information what are you trying to achieve we can find another way.
You could get the "string value" properties by querying the aspnet_Profiles table and parsing the string.
SELECT [UserName]
,[PropertyNames]
,[PropertyValuesString]
FROM [aspnet_Profile]
LEFT JOIN [aspnet_Users] on [aspnet_Users].UserId = [aspnet_Profile].UserId
The PropertyValuesString can be parsed with a bit of code. This link should explain the format in detail https://msdn.microsoft.com/en-us/library/aa478953.aspx#persistence_format.

Drupal node.save and JSONP

I am having an issue with call Drupal node.save using MooTool's JSONP. Here is an example.
Here is my request:
callback Request.JSONP.request_map.request_1
method node.save
sessid 123123123123123
node {"type":"blog","title":"New Title","body":"This is the blog body"}
Here is my result
HTTP/1.0 500 Internal Server Error
I got this working before, but i used AMFPHP and was able to send objects to drupal. I am assuming that this has to do with Drupal expecting an object, but since it is a GET it gets transformed as a string. Is there any way of getting around this with out hacking the code?
Here is my code:
$('newBlogSubmit').addEvent('click', function()
{
var node = {
type : "blog",
title:"New Title",
body :"This is the blog body"
}
var string = JSON.encode(node);
string.escapeRegExp()
var sessID = _sessID;
DrupalService.getInstance().node_save(string, sessID, drupal_handleBlogSubmit);
});
My Drupal Service JS Code:
//NODE
DrupalService.prototype.node_save = function(node, sessid, callback){
var dataObj = {
method : "node.save",
sessid : sessid,
node : node
}
DrupalService.getInstance().request(dataObj, callback);
}
//SEND REQUEST AND CALLBACK FUNCTION
DrupalService.prototype.request = function(dataObject, callback){
new JsonP('http://myDrupalSite.com/services/json', {data: dataObject,onComplete: callback}).request();
}
I am trying to connect the dots, but not too familiar with Drupal, but i would guess all I need to do is turn the string back into an object. Any ideas where I should be looking, or if there is an existing patch?
A first question could be why you use mootools since Drupal comes with jQuery and use it extensively throughout the different modules and Drupal core itself.
Anyways I don't know mootools so can't help you there, but if your request in ending in a internal server error, you have a problem with your drupal code or your js code. So even if I knew exactly what you were doing, I couldn't tell you the problem without looking at the drupal code for your http://myDrupalSite.com/services/json callback.
In general, what you want to make sure is:
You make a POST request, as drupal will cache get's and the semantic of this, is that you are posting data - the node - to the server.
Your data should be sent as post params, this will make them end up in the PHP $_POST variable
Your callback should validate the data and act accordingly, creating a node when the data is intact. You don't need session id's since the script will have the same session the browser has.
I've answered a similar question in detail, which was about altering a field instead of saving a node, but much of the work is still the same. You can take a look on the post, although this is with jQuery and not Mootools.

Resources