Passing JSON data to REST service

when i'm passing json data using POST rest service getting error like unsupported mediatype.

Caused By: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (HR.BUSINESS_CARD_DETAILS_PK) violated

Error Code: 1
Call: INSERT INTO BUSINESS_CARD_DETAILS (ID, ADDRESS, COMPANY, CREATEDATE, DEPARTMENT, EMAILID, FIRSTNAME, JOBTITLE, LASTNAME, MIDDLENAME, MOBILENO, USERNAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [12 parameters bound]
Query: InsertObjectQuery(com.killthebookservices.BusinessCardDetails[ id=220 ])
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:902)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:964)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:633)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
    Truncated. see log file for complete stacktrace

When i tried to call rest using these as headers in postman -- Content-Type: application/json, response: request failed. Accept: application/json, response: Unsupported Media type.

this is my rest method - (FACADEREST),

package com.killthebookservices.service;

import com.killthebookservices.BusinessCardDetails;
import java.math.BigDecimal;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


@Stateless
@Path("com.killthebookservices.businesscarddetails")
public class BusinessCardDetailsFacadeREST extends AbstractFacade<BusinessCardDetails> {

    @PersistenceContext(unitName = "KillTheBookDataServicePU",
                        type=PersistenceContextType.TRANSACTION)
    private EntityManager em;

    public BusinessCardDetailsFacadeREST() {
        super(BusinessCardDetails.class);
    }

    @POST
    @Override
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public void create(BusinessCardDetails entity) {
        super.create(entity);

    }

    @PUT
    @Path("{id}")
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public void edit(@PathParam("id") BigDecimal id,BusinessCardDetailsentity) {
        super.edit(entity);
    }

    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") BigDecimal id) {
        super.remove(super.find(id));
    }

    @GET
    @Path("{id}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public BusinessCardDetails find(@PathParam("id") BigDecimal id) {
        return super.find(id);
    }
    @GET
    @Override
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<BusinessCardDetails> findAll() {
        return super.findAll();
    }

    @GET
    @Path("{from}/{to}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<BusinessCardDetails> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }

    @GET
    @Path("count")
    @Produces(MediaType.TEXT_PLAIN)
    public String countREST() {
        return String.valueOf(super.count());
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

}

I'm using this to create rest services.

链接地址: http://www.djcxy.com/p/48570.html

上一篇: 在bash shell脚本中传播所有参数

下一篇: 将JSON数据传递给REST服务