Friday, 29 September 2017

XMLHttpRequest cannot load http://yourdomain.com/path/resoruce. Response for preflight has invalid HTTP status code 401

XMLHttpRequest cannot load http://yourdomain.com/path/resoruce. Response for preflight has invalid HTTP status code 401
If you are using token-based authentication for your spring java API, then you will get this error if you don't handle preflight requests. To know about preflight requests you can visit this link. In preflight requests browser will send a pre-request before the original request and check if it is safe to send information to that API. The browser will first send options request. To allow preflight request you should enable your API to accept OPTIONS request. In Java, you can do this by adding following code in spring filter.


public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
  throws IOException, ServletException {
 HttpServletResponse hsResponse = (HttpServletResponse) response;
 HttpServletRequest request = (HttpServletRequest) request;
 hsResponse.setHeader("Access-Control-Allow-Origin", "*");  //add * for global origin or http://localhost:8200
 hsResponse.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
 hsResponse.setHeader("Access-Control-Max-Age", "5000");
    hsResponse.setHeader("Access-Control-Allow-Credentials", "true");
 hsResponse.setHeader("Access-Control-Allow-Headers",
   "x-requested-with, authorization, Content-Type, Authorization, credential, X-XSRF-TOKEN");

 if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
  hsResponse.setStatus(HttpServletResponse.SC_OK);
 } else {
  chain.doFilter(request, response);
 }

}
This will fix preflight errors in your spring api.

Sunday, 9 July 2017

Warning (initialization): An error occurred while loading -SPACEMACS

Error=> When spacemacs is installed first time, while downloading packges spacemacs gives this error. Warning (initialization): An error occurred while loading.

Sollution => start emacs in insecure mode.

open command prompt(windows) , or terminal(unix) and locate emacs directory. and type 
=>emacs --insecure

This will solve the problem.

Thursday, 6 July 2017

Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.

Error =>Java Build path Problem.


Sollution=> In eclipse right click on your project and select BuildPath-> Configure BuildPath.
In the Java Build Path window select Libraries tab and select JRE  System Library[J2SE-1.5] click on edit then select alternate JRE or work space default JRE and select jre1.8.0 and above. click on finish.
Apply.

XMLHttpRequest cannot load http://yourdomain.com/path/resoruce. Response for preflight has invalid HTTP status code 401

XMLHttpRequest cannot load http://yourdomain.com/path/resoruce. Response for preflight has invalid HTTP status code 401 If you are using ...