I have build a REST server and trying to make my java application communicate to it.
But I keep getting a 404 error.
When I type in the url in my browser along with the function name like:
[url]/controller/functionname/1.json
it works fine, returning me the right data.
Without the function name:
[url]/controller/1.json
I get this error:
"action 1.json not defined in controller".
I've checked my .htaccess file and routes against a previous version I had build which was working just fine. I can't figure out what the problem might be. Any suggestions?
And oh, I should mention, the earlier version that I talked about was build on windows and this one on ubuntu.
Related
A lot of people have the same error for many different reasons, so, after trying a composer update, I've tried to investigate it starting from the browser and reconstructing step by step what is happening. It's really hard for me and I would really appreciate help from a PHP Developer!
From Chrome Developer Tools I could find the Ajax request in the background and the called url on the server
By playing with the url I realized that changing the action name returned a different error code, which let me understand that the current call is just a generic API in the middle between the browser and whatever is "apierror-visualeditor-docserver-http"
The Ajax call
{mysite}
/ api.php
? action=visualeditor
& paction=parse
&page=Cosa_c%27%C3%A8_da_fare%3F
Example
https://www.tematichedigenere.com/api.php?action=visualeditor&paction=parse&page=Cosa_c%27%C3%A8_da_fare%3F
The response from the Ajax call
The serverside call to rest api
Then I can see from the Apache server's log that the api page contacts the following url (returning 500)
GET
//rest.php/
{mywebsiteurl}
/v3/page/html/
Cosa_c%27%C3%A8_da_fare%3F/27246
?redirect=false
&stash=true
example
"GET //rest.php/www.tematichedigenere.com/v3/page/html/Cosa_c%27%C3%A8_da_fare%3F/27246?redirect=false&stash=true HTTP/1.0" 500 5621 "-" "VisualEditor-MediaWiki/1.38.2"
Another example of log (returning 404)
{an IP} - -
[04/Dec/2022:14:16:12 +0000]
"POST
/rest.php/
{mywebsiteurl}/v3
/transform/html/to/wikitext
/Riflessioni_sulla_sessualizz._femm._collegate_-_bozza%2Fprova
HTTP/1.0"
404
467
"-"
"VisualEditor-MediaWiki/1.38.2 X-Middleton/1"
Maybe the initial double / is wrong?
Anyway if I call the uri directly from my browser https://tematichedigenere.com/rest.php/www.tematichedigenere.com/v3/page/html/Cosa_c%27%C3%A8_da_fare%3F/27246?redirect=false&stash=true
The server does a antirobot check but I'm not sure that was the problem.
I've realized that the 500 error code hides a more complex real error which is returned by accessing directly the url from the log.
As you say, the visualeditor API is mostly just a proxy to the Parsoid API. The double / is wrong (check your $wgVirtualRestConfig settings maybe), I don't think it actually matters though. The error sounds like you are using incompatible library versions - make sure MediaWiki core and the VisualEditor extension are for the same release, and that the parsoid Composer library is up to date.
Update from OP:
the issue was solved. I simply had to delete the folder /vendor/wikimedia/parsoid and copy it from the fresh install. I couldn't see there were disalignment because of a problem in the compare tool. I got a lot of help in the IRC channel (not in Phabricator and not in Mediawiki forums, it seems IRC is really helpful for MW products).
I'm currently trying to wrap my head around Wordpress and its relation to the REST API. All of theses issues are only occurring in the context of plugin development. So far I had setup my endpoint and written my callback which will be executed whenever someone is sending a GET-Request to said endpoint. However, my callback is never called. This is the file which I've written so far.
/*
* Plugin Name: cola-learning
*/
if(!defined('ABSPATH')){
die;
}
if(!function_exists('add_action')){
echo 'You cant access this ressource!';
exit;
}
function PrintRESTResponse()
{
return rest_ensure_response("student");
}
function SetupREST()
{
return register_rest_route("student/v1","/view/",[
'methods' => 'GET',
'callback' => 'PrintRESTResponse'
],false);
}
add_action('rest_api_init','SetupREST');
Perhaps it might also help, if I'll give some background information about my development machine:
- OS: Windows 10
- Server: Apache Web Server (included inside XAMPP)
- Wordpress Version: 5.3.2
- PHP Version: 7.4
- Development IDE: Eclipse 2019-12 CDT ( with PHP Plugin )
From my research, everything should work fine. However, it doesnt :/ Did I miss something crucial?
Update:
WordPress REST API Routing
WordPress is having a default route for all request which are directed to the REST API ( at least if you use XAMPP with the Bitnami WordPress application module). Now, if one wants to send a request to said REST API, the person needs to use an URL with the form of ip:port/wp-json/rest_route. ip ressembles the ip address of the server which is hosting wordpress. port is the port of said server. wp-json, however, is the portion which differs an ordinary request from a request to the REST API. Everything after this portion (rest_route) is the rest route which I've defined in the above source code.
What went wrong?
My request was pointed to the wrong endpoint. Therefore I used the URL 'localhost:wpPort/wordpress/student/v1/view/'. However, the 'wp-json/' portion is missing. Therefore WordPress will search for a page that doesn't exist in the first place. Instead I should have used the URL 'localhost:wpPort/wordpress/wp-json/student/v1/view/'.
After some troubleshooting it turns out the URL being used to test was missing a part of the endpoint path.
Here is the correct path to test the newly registered endpoint.
localhost:80/wordpress/wp-json/student/v1/view/
Here's some more reading on WP Rest API endpoints:
https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/
I am getting an error like this:
Array to string conversion
Inside:
/var/.../vendor/cartalyst/sentry/src/Cartalyst/Sentry/SentryServiceProvider.php
Code snippet where the error was thrown:
throw new \InvalidArgumentException("Invalid hasher [$hasher] chosen for Sentry.");
I was doing ordianry work in one of my controllers and this error occured when I clicked on one of the buttons inside my blade.
I have commented the code out but the error still is being displayed, not only on this one page but on every single one in my project. I can't even go to my /home/index.php page.
I have done
composer update
inside my project but that did not help. What can fix the problem?
#update
Yes I have checked sentry config file before I've made a new topic. I have the same problem when I load older versions (which do not contain the latest changes I've made today) of my project on to apache server which is running on Ubuntu 14.04.
Ideas what causes the problem?
In the config for Sentry you have to define a hasher.
It has to be a string. It can be 'native', 'bcrypt', 'sha256' or 'whirlpool'. Apparently in your app, it's not a string, but an array. Check your configuration. It's probably in app/config/packages/cartalyst/sentry/config.php
I have two cakephp sites setup for the same site. One is my local version which I develop on, one is the live one.
I installed a User management plugin on both apps, and it works on my localhost site, but not on the live site.
I get this error on the live site:
Fatal error: Call to undefined function usermgmtinit() in /home2/collehn6/public_html/devcr12/app/Plugin/Usermgmt/Controller/Component/UserAuthComponent.php on line 53
The line in question is:
UsermgmtInIt($this);
I tried changing this line to:
$this->UsermgmtInIt();
And that just game me another error. Why is it working on my local site, but not on the live site?
The plugin you're referring to expects you to load its bootstrap file which contains:
function UsermgmtInIt(&$controller) {
...
As such the problem is probably that in your application you're loading the plugin like so:
CakePlugin::load('Usermgmt');
Wheras it needs to be loaded like so:
CakePlugin::load('Usermgmt', array('bootstrap' => true));
Check the Readme if that doesn't immediately solve the problem.
It should be no surprise that changing code to be fundamentally different doesn't make it work.
I’m getting a funny error after I deploy a fully working symfony project to my web host (hostgator). Everything works fine on my localhost.
Here’s the error:
500 | Internal Server Error | sfException
Call to undefined method sfApplyApplyForm::isCaptchaEnabled.
Here’s what I’m using:
Symfony 1.4
Doctrine 2.0
sfForkedDoctrineApplyPlugin - for
registering new users with:
sfDoctrineGuardPlugin - for
authentication
I get the error when I click the “Register” link.
Obviously, the form is Captcha enabled. I’ve tried turning it off in config/app settings with no change in error. I’ve also confirmed that my public and private keys are correct and registered... I’ve even updated them with no change in error msg.
A search on Google brings up nothing helpful.
Any ideas about where to begin troubleshooting?
To correct this problem I just copied the isCaptiaEnabled() method from the plugin to the model class where I embedded the plugin form. I believe I had to also copy a couple of other methods over as well. But as soon as I did that, the errors never came back.