0

ConsumerData

package org.apache.fineract.lab.data;

import java.util.Date;


public class ConsumerData {
    private String uniqueIndentifier;
    private String firstName;
    private String lastName;
    private Boolean active;
    private Date lastModified;

    public ConsumerData(){

        super();
    }

    public String getUniqueIndentifier() {
        return uniqueIndentifier;
    }

    public void setUniqueIndentifier(String uniqueIndentifier) {
        this.uniqueIndentifier = uniqueIndentifier;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

    public Date getLastModified() {
        return lastModified;
    }

    public void setLastModified(Date lastModified) {
        this.lastModified = lastModified;
    }
}

ConsumersApiResource

package org.apache.fineract.lab.api;


import org.apache.fineract.lab.data.ConsumerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collection;
import java.util.HashMap;

    @Path("/consumers")
    @Component
    @Scope("singleton")

    public class ConsumersApiResource {

     private static final Logger LOGGER= LoggerFactory.getLogger(ConsumersApiResource.class);
        private final HashMap<String,ConsumerData>mockedConsumerData=new HashMap<>();
      public ConsumersApiResource() {
            super();
        }

        @GET
        @Consumes({ MediaType.APPLICATION_JSON })
        @Produces({ MediaType.APPLICATION_JSON })
        public Collection<ConsumerData> fetchAll()
        {
            return this.mockedConsumerData.values();
        }

        @POST
        @Consumes({ MediaType.APPLICATION_JSON })
        @Produces({ MediaType.APPLICATION_JSON })
        public Response createConsumer (final ConsumerData consumerData)
        {
            this.mockedConsumerData.put(consumerData.getUniqueIndentifier(),consumerData);
            return Response.status(Response.Status.CREATED).build();
        }

    }

extensionContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
           xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:sec="http://www.springframework.org/schema/security"
           xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">



        <context:annotation-config/>
        <context:component-scan base-package="org.apache.fineract.lab"/>
        <jpa:repositories base-package="org.apache.fineract.lab.api"/>


        </beans>

Error:

While I am trying to POST and GET data from /consumers path I am getting following Not found error.Did not get Endpoint but I am unable to solve this issue.

{
  "timestamp": 1466503124489,
  "status": 404,
  "error": "Not Found",
  "message": "Not Found",
  "path": "/fineract-provider/api/v1/consumers"
}

Please help me to sort this out.Thanks in advance.

Abu Sufian
  • 991
  • 1
  • 6
  • 15
  • That's a Spring MVC response, not a Jersey response. So my guess is you don't even have Jersey configured correctly. Where is your Jersey configuration? – Paul Samsotha Jun 21 '16 at 10:33
  • Ok where is your JAX-RS configuration? – Paul Samsotha Jun 21 '16 at 10:48
  • JAX-RS Has nothing to do with Spring MVC. Both support a REST "layer" but are completely different framework. If you want to use Spring MVC, then use Spring MVC components. You are trying to use JAX-RS components with Spring MVC, which won't work. If you want to use Spring MVC, look up some good tutorials for it. Or if you want to use JAX-RS, then look up some good tutorials for _it_. – Paul Samsotha Jun 21 '16 at 14:27
  • I think both things work together as I am trying to develop MifosX(http://mifos.org/) which is an OpenSource Banking software.Their architecture is like that.They used Spring and Jax-RS together.So I have to do it according to their architecture. – Abu Sufian Jun 21 '16 at 15:04
  • Using _Spring_ with JAX-RS is different than using _Spring MVC_ with JAX-RS. With JAX-RS, the only reason you would use Spring is for DI of the service layer, which is possible. Spring != Spring MVC. If you are going to use JAX-RS, then you need to configure the application in a JAX-RS way, which will be implementation specific, because Spring DI in JAX-RS is implementation specific. – Paul Samsotha Jun 21 '16 at 15:09
  • Thank you for your clarification which helps me lot to understand but I am stuck with this problem.What might be wrong in source code as I am unable to find out.Can you please help me to figure it out.As I followed their documentation but Endpoint give error as It is unable to find proper path.What might be the problem in source code? – Abu Sufian Jun 21 '16 at 15:17
  • where are you linking "fineract-provider/api/v1" I can't see that anywhere in your code? – sadaf2605 Jun 22 '16 at 05:45

1 Answers1

0

You need to import extensionContext.xml. Add <import resource="extensionContext.xml"/> line in your appContext.xml.

Nazeer
  • 1
  • 1