不支持IBM Process Server v8.5.5抛出415介质调用restful服务时出错

时间:2016-08-31 23:37:22

标签: java apache-wink

大家好,我是这个ibm网络领域的新手,我写了一个简单的java代码,并将其作为一个宁静的公开。

申请类

public class WorkflowResourceApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
    Set<Class<?>> classes = new HashSet<Class<?>>();
    classes.add(LibraryServiceImpl.class);
    return classes;
}

}

服务

@Path("/books")
@Produces( MediaType.APPLICATION_JSON)
@Consumes( MediaType.APPLICATION_JSON)
public class LibraryServiceImpl implements LibraryService {

private LibraryDAO libDao = new LibraryImpl();

@Path("/getbooks")
@GET
public Response getBooks(@QueryParam("format") String format) throws SQLException {
    return Response.status(Status.OK).entity(new GenericEntity<List<Book>>(libDao.getAllBooks()) {
    }).status(Status.OK).build();

}

Web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Library</display-name>
<servlet>
    <description>
    JAX-RS Tools Generated - Do not modify</description>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.library.nag.restful.application.WorkflowResourceApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

使用默认提供的apache wink。没有编译错误。当我在邮递员中看到响应时,错误代码415,即不支持的mediatype。

以下是我的IBM Business Integrator中的错误

00000121 RequestProces I org.apache.wink.server.internal.RequestProcessor logException The following error occurred during the invocation of the handlers chain: WebApplicationException (415 - Unsupported Media Type) with message 'null' while processing GET request

但是当我部署了但没有使用websphere v8.5.5时,同一个项目在tomcat中运行。在我的研究中,我发现应该将以下依赖项添加到我的server.xml

 <application location="C:\myproject\target\myapp.war" type="war">
<classloader apiTypeVisibility="spec,ibm-api,api,third-party"/>

当我尝试将其添加到

中找到的server.xml时
${PROFILE_HOME}/config/cells/${CELL}/nodes/${NODE}/servers/${SERVER}/server.xml

我的服务器甚至没有启动。我做错了什么。请帮帮我

谢谢。

2 个答案:

答案 0 :(得分:0)

在客户端,您是否使用HTTP标头"Accept=application/json"进行呼叫?

答案 1 :(得分:0)

您必须专门使用Accept,而不仅仅是package com.cerebro.model.domain; import java.io.Serializable; import java.util.logging.Logger; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Transient; import javax.validation.constraints.Digits; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.hibernate.validator.constraints.NotEmpty; import com.google.common.base.MoreObjects; @Entity @Table(name = "service_contract") public class ServiceContract extends AbstractBaseEntity implements Identifiable<Long>, Serializable { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(ServiceContract.class.getName()); // Raw attributes private Long id; private String name; private String description; private String type; private Long contractStart; private Long contractEnd; private Boolean isrepeated; private Boolean autoApproved; private Boolean staffAutoApproved; private String status; // Many to one private HospitalUnit unit; private Staff preferredStaff; private Specialty specialty; private SkillMaster skill; private ServiceLocation ServiceLocation; private ServiceSchedule ServiceSchedule; private Hospital hospital; @Override public String entityClassName() { return ServiceContract.class.getSimpleName(); } // -- [id] ------------------------ @Override @Column(name = "id", precision = 19) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "service_contract_id_seq") @SequenceGenerator(name = "service_contract_id_seq", sequenceName = "service_contract_id_seq", allocationSize = 1) @Id public Long getId() { return id; } @Override public void setId(Long id) { this.id = id; } public ServiceContract id(Long id) { setId(id); return this; } @Override @Transient public boolean isIdSet() { return id != null; } // -- [name] ------------------------ @NotEmpty @Size(max = 256) @Column(name = "name", nullable = false, length = 256) public String getName() { return name; } public void setName(String name) { this.name = name; } public ServiceContract name(String name) { setName(name); return this; } // -- [description] ------------------------ @NotEmpty @Size(max = 500) @Column(name = "description", nullable = false, length = 500) public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public ServiceContract description(String description) { setDescription(description); return this; } // -- [type] ------------------------ @NotEmpty @Size(max = 50) @Column(name = "`type`", nullable = false, length = 50) public String getType() { return type; } public void setType(String type) { this.type = type; } public ServiceContract type(String type) { setType(type); return this; } // -- [contractStart] ------------------------ @Digits(integer = 19, fraction = 0) @NotNull @Column(name = "contract_start", nullable = false, precision = 19) public Long getContractStart() { return contractStart; } public void setContractStart(Long contractStart) { this.contractStart = contractStart; } public ServiceContract contractStart(Long contractStart) { setContractStart(contractStart); return this; } // -- [contractEnd] ------------------------ @Digits(integer = 19, fraction = 0) @Column(name = "contract_end", precision = 19) public Long getContractEnd() { return contractEnd; } public void setContractEnd(Long contractEnd) { this.contractEnd = contractEnd; } public ServiceContract contractEnd(Long contractEnd) { setContractEnd(contractEnd); return this; } // -- [isrepeated] ------------------------ @NotNull @Column(name = "isrepeated", nullable = false, length = 1) public Boolean getIsrepeated() { return isrepeated; } public void setIsrepeated(Boolean isrepeated) { this.isrepeated = isrepeated; } public ServiceContract isrepeated(Boolean isrepeated) { setIsrepeated(isrepeated); return this; } // -- [autoApproved] ------------------------ @NotNull @Column(name = "auto_approved", nullable = false, length = 1) public Boolean getAutoApproved() { return autoApproved; } public void setAutoApproved(Boolean autoApproved) { this.autoApproved = autoApproved; } public ServiceContract autoApproved(Boolean autoApproved) { setAutoApproved(autoApproved); return this; } // -- [staffAutoApproved] ------------------------ @NotNull @Column(name = "staff_auto_approved", nullable = false, length = 1) public Boolean getStaffAutoApproved() { return staffAutoApproved; } public void setStaffAutoApproved(Boolean staffAutoApproved) { this.staffAutoApproved = staffAutoApproved; } public ServiceContract staffAutoApproved(Boolean staffAutoApproved) { setStaffAutoApproved(staffAutoApproved); return this; } // -- [createdts] ------------------------ public ServiceContract createdts(Long createdts) { setCreatedts(createdts); return this; } // -- [updatedts] ------------------------ public ServiceContract updatedts(Long updatedts) { setUpdatedts(updatedts); return this; } // -- [createdby] ------------------------ public ServiceContract createdby(String createdby) { setCreatedby(createdby); return this; } // -- [status] ------------------------ @NotEmpty @Size(max = 2147483647) @Column(name = "status", nullable = false, length = 2147483647) public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public ServiceContract status(String status) { setStatus(status); return this; } // ----------------------------------------------------------------- // Many to One support // ----------------------------------------------------------------- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // many-to-one: ServiceContract.unit ==> HospitalUnit.id // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @NotNull @JoinColumn(name = "unit_id", nullable = false) @ManyToOne public HospitalUnit getUnit() { return unit; } /** * Set the {@link #unit} without adding this ServiceContract instance on the * passed {@link #unit} */ public void setUnit(HospitalUnit unit) { this.unit = unit; } public ServiceContract unit(HospitalUnit unit) { setUnit(unit); return this; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // many-to-one: ServiceContract.preferredStaff ==> Staff.id // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @JoinColumn(name = "preferred_staff_id") @ManyToOne public Staff getPreferredStaff() { return preferredStaff; } /** * Set the {@link #preferredStaff} without adding this ServiceContract * instance on the passed {@link #preferredStaff} */ public void setPreferredStaff(Staff preferredStaff) { this.preferredStaff = preferredStaff; } public ServiceContract preferredStaff(Staff preferredStaff) { setPreferredStaff(preferredStaff); return this; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // many-to-one: ServiceContract.specialty ==> Specialty.id // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @NotNull @JoinColumn(name = "specialty_id", nullable = false) @ManyToOne public Specialty getSpecialty() { return specialty; } /** * Set the {@link #specialty} without adding this ServiceContract instance * on the passed {@link #specialty} */ public void setSpecialty(Specialty specialty) { this.specialty = specialty; } public ServiceContract specialty(Specialty specialty) { setSpecialty(specialty); return this; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // many-to-one: ServiceContract.skill ==> SkillMaster.id // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @NotNull @JoinColumn(name = "skill_id", nullable = false) @ManyToOne public SkillMaster getSkill() { return skill; } /** * Set the {@link #skill} without adding this ServiceContract instance on * the passed {@link #skill} */ public void setSkill(SkillMaster skill) { this.skill = skill; } public ServiceContract skill(SkillMaster skill) { setSkill(skill); return this; } @OneToOne(mappedBy = "ServiceContract", cascade = CascadeType.PERSIST) public ServiceLocation getServiceLocation() { return ServiceLocation; } public void setServiceLocation(ServiceLocation ServiceLocation) { this.ServiceLocation = ServiceLocation; } public ServiceContract serviceLocation(ServiceLocation ServiceLocation) { setServiceLocation(ServiceLocation); return this; } @OneToOne(mappedBy = "ServiceContract", cascade = CascadeType.PERSIST) public ServiceSchedule getServiceSchedule() { return ServiceSchedule; } public void setServiceSchedule(ServiceSchedule ServiceSchedule) { this.ServiceSchedule = ServiceSchedule; } public ServiceContract serviceSchedule(ServiceSchedule ServiceSchedule) { setServiceSchedule(ServiceSchedule); return this; } @NotNull @JoinColumn(name = "hospital_id", nullable = false) @OneToOne public Hospital getHospital() { return hospital; } public void setHospital(Hospital hospital) { this.hospital = hospital; } public ServiceContract hospital(Hospital hospital) { setHospital(hospital); return this; } /** * Apply the default values. */ public ServiceContract withDefaults() { return this; } /** * Equals implementation using a business key. */ @Override public boolean equals(Object other) { return this == other || (other instanceof ServiceContract && hashCode() == other.hashCode()); } private IdentifiableHashBuilder identifiableHashBuilder = new IdentifiableHashBuilder(); @Override public int hashCode() { return identifiableHashBuilder.hash(log, this); } /** * Construct a readable string representation for this ServiceContract * instance. * * @see java.lang.Object#toString() */ @Override public String toString() { return MoreObjects.toStringHelper(this) // .add("id", getId()) // .add("name", getName()) // .add("description", getDescription()) // .add("type", getType()) // .add("contractStart", getContractStart()) // .add("contractEnd", getContractEnd()) // .add("isrepeated", getIsrepeated()) // .add("autoApproved", getAutoApproved()) // .add("staffAutoApproved", getStaffAutoApproved()) // .add("createdts", getCreatedts()) // .add("updatedts", getUpdatedts()) // .add("createdby", getCreatedby()) // .add("status", getStatus()) // .toString(); } }