将JSON数据传递给REST服务
当我传递JSON数据使用POST休息服务获取像不受支持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
当我试图调用休息时使用这些作为postman中的标题 - Content-Type:application / json,响应:请求失败。 接受:application / json,回应:不支持的媒体类型。
这是我的休息方法 - (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;
}
}
我正在使用它来创建休息服务。
链接地址: http://www.djcxy.com/p/48569.html