Thursday, June 15, 2017

$http.get(…).success is not a function

When i was working on application using angular 1.6.4, i was using the $http to get the data from the server. So i used the below line of code

$http.get("data/places.json").success(function (results) {
$scope.places = results.data;
});

but it was throwing an error saying $http.get(…).success is not a function. When i browse through the angular documents and net, it seems to be that, the function success and error has been deprecated from 1.5, instead you have to use then method. The then() method takes two arguments: a success and an error callback which will be called with a response object.

$http.get("data/places.json").then(function (success) {
$scope.places = success.data;
},
function(error){
//do something
});


Happy Programming...!!!

Monday, June 12, 2017

JAX-RS with CXF without Spring

In this post, we will see, how to implement JAX-RS with CXF without using the Spring. Instead of using the Servlet org.apache.cxf.transport.servlet.CXFServlet we will be using the Servlet org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet. When using the CXFNonSpringJaxrsServlet, there is no need for servlet.xml, since the configuration of the endpoints and provider will be taken
automatically done, by the jaxrs.serviceClasses at runtime. Note: this will not generate the WADL file, that's the only disadvantage.

Rest of the items are similar to the normal CXF implementation.

 <web-app>  
  <display-name>cxf</display-name>  
  <servlet>  
   <servlet-name>CXFServlet</servlet-name>  
   <servlet-class>  
   org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet  
  </servlet-class>  
   <init-param>  
    <param-name>jaxrs.serviceClasses</param-name>  
    <param-value>com.school.service.StudentService</param-value>  
   </init-param>  
   <load-on-startup>1</load-on-startup>  
  </servlet>  
  <servlet-mapping>  
   <servlet-name>CXFServlet</servlet-name>  
   <url-pattern>/services/*</url-pattern>  
  </servlet-mapping>  
 </web-app>  


Happy Programming...!!

Tuesday, June 6, 2017

Invalid configuration object output.path is not an absolute path - Webpack

While i was practising the Nodejs with webpack recently i encountered an error, when i try to start the application using command npm start. I received the following error.

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.output.path: The provided value "./build" is not an absolute path!

Below is the snap shot of my webpack.config.js

 
module.exports = {  
  entry: ['./app/index.js'],  
  output: {  
   path: './build',  
   filename: 'bundle.js'  
  },  
  ....
  ...
 };  


The issue is due to path provided for the output, it is a relative path. output.path requires an absolute path, we need to convert it to an absolute path. To convert it into the absolute path, we will be using the path.resolve. Add the below code to your webpack.config.js, this should resolve the issue. Now you start the server, it will work like a charm

 
const path = require('path'); //in the top<
 module.exports = {  
  entry: ['./app/index.js'],  
  output: {  
   > path: 'path.resolve(__dirname, 'build'),'<  
   filename: 'bundle.js'  
  },  
 };  

Happy Programming...!!!