因此,我通过Dropwizard获得了此Web服务应用程序。这是简单的发布方法:
@Path(OmniURL.USERPATH)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class UserResource {
private final UserMobileDao userMobileDao;
public UserResource(UserMobileDao userMobileDao) {
this.userMobileDao = userMobileDao;
}
@POST
@UnitOfWork
public UserMobile createUserMobile(UserMobile userMobile) {
userMobile.setCreationDate(new Date());
return userMobileDao.save(userMobile);
}
}
这是我尝试从android应用程序发布的Json :(最近我通过Postman应用程序发布,返回了相同的错误,并且他的ContentType正确设置为“ application / json”作为标头)
{"creationDate":null,"email":"[email protected]","facebookProfile":{"email":"[email protected]","id":"679284068825262"},"id":null,"name":"Jack Et","onlineStoreUser":null}
这代表这个实体:
@Entity
@Table(name = "user_mobile")
public class UserMobile implements Serializable{
private static final long serialVersionUID = -273822158021109237L;
@Id
@SequenceGenerator(name = "seq_user_mobile", sequenceName = "seq_user_mobile", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_user_mobile")
@Column(name = "user_id")
private Long id;
@Column(name = "email", length=30, nullable=false)
private String email;
@OneToOne(optional=true)
private FacebookProfile facebookProfile;
@Column(name = "creation_date")
private Date creationDate;
@OneToOne(fetch=FetchType.LAZY,optional=true)
private OnlineStoreUser onlineStoreUser;
@Column(name = "name", length=30, nullable=false)
private String name;
....getters and setters
}
我已经尝试过CORS设置,例如:
/* e.servlets().addFilter("cors-filter", CrossOriginFilter.class)
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
*/
Dynamic filter = e.servlets().addFilter("CORS", CrossOriginFilter.class);
filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
filter.setInitParameter("allowedOrigins", "*");
filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
filter.setInitParameter("allowedMethods", "GET,PUT,POST,DELETE,OPTIONS");
//filter.setInitParameter("preflightMaxAge", "5184000"); // 2 months
filter.setInitParameter("allowCredentials", "true");
没有成功...
有趣的是,在创建所有具有其属性的实体之前,我已经使用名称和电子邮件对UserMobile进行了测试,并且效果很好。因此,我相信这是我的一个简单而愚蠢的错误。
好的,所以这里的人们不可能解决它。没有足够的信息。
我有来自Dropwizard的以下设置:
@Override
public void initialize(Bootstrap<OmnichannelConfiguration> btstrp) {
btstrp.addBundle(new ConfiguredAssetsBundle("/banana", "/banana"));
btstrp.addBundle(hibernateBundle);
}
而且我真的不知道为什么要使用它。我来自另一个项目。:P
我的路线是:
@Path(OmniURL.USERPATH)
哪个OmniURL.USERPATH是“ / banana / user”
所以它们不能走同一条路,我更改了ConfiguredAssetsBundle并开始工作。“我的简单愚蠢的错误”
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句