Unable to access files from MarkLogic Java API - java

In the process of showing demoing some new Java code that accesses a local MarkLogic server, I ran into the following error. It pops up any time I try to either load a file, or access its metadata:
Only XML and JSON error messages supported by MarkLogic server.
This is getting triggered in calls to TextDocumentManager.readMetadata() and TextDocumentManager.read(). The code works fine on my machine but NOT on my supervisor's (he's the one seeing the error), which makes me think I tweaked something in the database configuration during development but didn't write it down. Unfortunately, I can't think of what that would be. Does anybody have any suggestions?

The message indicates that the server responded with an error without a Content-Type header declaring error content as JSON or XML.
Thus far, we've seen that Java exception only when the server was not initialized as a REST server.
So, please check your connection parameters. If in doubt, use an HTTP client like curl to make the equivalent request of the REST server to verify that the request is accepted.
If the REST server seems to be operational, you can also turn on error logging on the REST server to help debug the Java client.
To answer the followup question (StackOverFlow timed out on the initial answer):
There's a UI for creating a REST server in InfoStudio database configuration.
Go to port 8000 at the /appservices/ path.
Select the Database from the drop down and click Configure
Add a REST API Instance near the bottom of the page
There's also a REST interface for the admin user (not the REST admin user) to create REST instances on port 8002. For information about those services, please see
http://docs.marklogic.com/REST/client/service-management

Related

How to solve 413 request entity too large

When I post a form with an image taken from my phone I reserve the error "413 request entity too large" I realize that an image included in the form taken by the phone camera is too large, and the server rejects the request... but how can I fix this issue, I'm using Java Spring framework, and MySQL database, all of this handled with Amazon aws services.
You have to modify your .platform as shown in the docs.
For example, you could have the following .platform/nginx/conf.d/myconfig.conf with content:
client_max_body_size 20M;
I struggled with this for so long until I came across this post:
https://medium.com/#robin.srimal/how-to-fix-a-413-request-entity-too-large-error-on-aws-elastic-beanstalk-ac2bb15f244d
Couple things to watch out for here, if your server is restarted or you deploy a new version etc, then your nginx server will also reset and you will need to perform these changes again. Also periodically, AWS seems to reset your EC2 instance address, not sure why, but you need to perform these changes again afterwards. There must be a way of making these changes permanent but I haven't figured that part out yet.
I find the solution thanks for helping...
1-I connect to my EC2 instance throw the "connect" button, a terminal appears.
2-I edit this file: etc/nginx/nginx.conf
3- Add this line:client_max_body_size 10M;
and it works fine.
thank you all ;

Moving webapp from localhost to server - page cannot be found

I have developed a Play! 1.2.7 web application which calls an existing online payment service, eclipsified to work in Java.
I send data in POST to a servlet and get a response in GET to my application. This is possible because one of the data sent to the service is the URL of my controller handling the response.
I had this working perfectly in local environment but when I move the webapp to a Tomcat container on our local server with public ip I'm stuck because service response cannot find my webapp as it used to do with localhost.
Locally the URL was something like
http://localhost:port/myAction
When I put it on tomcat I changed the URL to
http://my.public.ip.address:tomcat_port/app_name/myAction
I get the "page is not available" message from browser.
My guess is that I miss some basics from network communication and I'd like to know how to have this working when the application is deployed on our server.
Ps. sorry for bad tagging, I'm not sure what's this question's target
EDIT: no logs from catalina.out. If I run the application nothing gets logged
I came across the solution by knowing that loopback is not enable by default on every router.
So I will never be able to have a response client side when I send the request from the lan where the server is located, unless loopback is enabled on the router.
To test my application I had to use the server local address, visible from inside.

Android App and PHP Web Service Security

I'm building an android application which uses a PHP web service (I am building this also).
My question is, how do I prevent unauthorised users using my webservice? For example, could someone get the address of my web service and use it outside of my app (e.g. sending post variables to my service)?
Another related question is how do I prevent spam requests on my webservice? Would it be a case of logging the IP address and limiting the amount of calls?
You can use an HTTPS connection between the Android device and your webservice API endpoint.
Limit you webservice so that it accept only HTTPS connections. You can easily do this using Apache (perhaps using the SSLRequireSSL directive) or directly in your PHP connection handler.
While using an HTTPS transport stream, you can pass specific arguments when making an API call to your webservice to ensure the request has been sent from your application. Nobody will be able to know what specific data are transmitted and will not be able to reproduce an acceptable connection to your remote service.
Regarding your second question, you can indeed limit the number of requests for a given amount of time. Either in PHP or by using specific tools such as fail2ban.
PHP can receive data via POST or GET out of your site and even the internet browser. One of the methods used to do this is by curl.
To what are you referring to this question is known as Cross-site request forgery.
If you are able, you should implement the use of HTTPS in your app and this could solve many security problems.
In case you can not use HTTPS (whether it is expensive or any other problem):
You must verify the information received by POST or GET in your PHP, this language has much ability to solve these "problems"; Take a look at this part of the PHP official documentation.
Suppose you're building a login system:
Also you can add in the login page place a hidden element with secret unique code that can happend only once, save this secret code in session, so, the loging script look in session for this code, compare with what was posted to the script, should same to proceed.
And, if you want to get the IP address of your visitors:
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Finally, read this.
EDIT
If you can't pay an HTTPS certificate, (as Halim Qarroum says) you can use:
Self signed SSL certificates,
which are free.
Of course this has its advantages and disadvantages

Get server Port in web application at server start

I need to retrieve server information like Server IP and Port at server startup.
I am using Spring and hibernet in my project and Glassfish (and tomcat) is the application server.
I know that I can get the IP and Port information from request, but there is no request at server startup.
I found on net after some search that IP address can be retrieved as follows:
InetAddress.getLocalHost().getHostName();
but I did not find any method to retrive the current Port of the server. I am hoping to find API from app server which will provide this information. I am using Spring in my application and thus any indications from Spring API will also be helpful.
Well you should configure port in your web.xml as param and read it out in your code using ServletContext or you can use this poor hack
A server may be listening to multiple ports on multiple names, so you cannot be certain that the one chosen automatically is the one you really want.
Question is what you need it for.
If it is for giving URL backs in requests then use the information in requests.
If it is for logging or announcement with ZeroConf, then consider writing application server specific code asking it about its configuration.
If all else fails, explicitly pass in the information through e.g. system properties or JNDI.

Configuring W3C's Unicorn to use a proxy server

I've been trying to setup W3C Unicorn on Ubuntu 10 using Tomcat6 but running into a few problems with proxy servers.
I've got Unicorn configured (via tomcat) to use a proxy server using java's -Dhttp.proxyHost and -Dhttp.proxyPort. This works fine and Unicorn is able to download the files it needs.
The problem is that we're trying to use it to validate content on an internal network which requires bypassing the proxy server. I've tried using -Dhttp.nonProxyHosts but nothing seems to be working. Unicorn just keeps giving the following errors whenever I try to validate using a local URL:
From the HTML validator:
HTTP Error
Unexpected HTTP response 500 Can't connect to some.internal.dom (Bad hostname 'some.internal.dom') while trying to retrieve http://some.internal.dom:4000/
From the HTTP validator:
Checker Error
Could not connect to the server (No address associated with hostname)
And from the Feed Validator:
Server returned (-2, 'Name or service not known')
An error occurred while trying to validate this feed.
I've tried everything I can think of but just don't seem to be able to get the nonProxyHosts to work. Any suggestions?
Thanks
Discovered after some investigation that Unicorn doesn't actually provide the validation services, it redirects requests to the W3C (or any other configured) validation service. This means the local proxy configuration was irrelevant as the request was being passed to W3C who weren't able to connect to our internal network (obviously), which explains why we were getting the error messages despite the proxy configuration working.
Each of the W3C validators can be downloaded and installed independently, and Unicorn can then be configured to connect to those instead of the official W3C validators.
Took a lot of digging to work this out - the W3C Unicorn site needs to explain things a bit clearer!

Categories

Resources