我正在使用JPA开发JavaSE应用程序.不幸的是,我null
打电话后:
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
您将在下面找到:
EntityManagerFactory
并意外返回null
persistence.xml
档案我的代码片段:
public class Main {
private static final String PERSISTENCE_UNIT_NAME = "MeineJpaPU";
private static EntityManagerFactory factory;
public static void main(String[] args) {
// I get null on this line!!!
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
// do stuff with entity manager
...
}
}
Run Code Online (Sandbox Code Playgroud)
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MeineJpaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>path.to.package.server.Todo</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url" …
Run Code Online (Sandbox Code Playgroud) 我正在设计一个RESTful API.
一项服务应为多个键值对提供查询功能.例如,客户端可以使用一个HTTP GET请求查询不同的产品和相关数量.
客户想要使用金额44和产品2查询产品1,金额为55.我实际上不希望我的URI看起来像这样:
/produkt?productId1=1&productquantity1=44&productId2=2&productquantity2=55
Run Code Online (Sandbox Code Playgroud)
因为我不知道有多少产品被查询.
或者像这样:
/produkt?product=1,44&product=2,55
Run Code Online (Sandbox Code Playgroud)
因为客户怎么能知道在逗号之前有productId和逗号之后的数量.
有没有人有其他解决方案?或者,提供使用一个请求查询多个产品的可能性是不是RESTful?是否更好地提供仅查询一个具有相关数量的产品的可能性,如果客户想要查询更多产品,他们应该发送更多请求?
我在这个主题中阅读了很多关于REST API版本的内容:API版本化的最佳实践?
因此,我想使用HTTP-Accept-Header来指示客户端要求的版本.但是如何在我的应用程序中应用它?因此,有哪些变化?编组员如何知道应该使用哪个版本?我必须注册我的类型吗?
我所知道的是我必须更改@Produces
-Annotation 的内容
@GET
@Path("/locations")
@Produces("application/vnd.mycompany-v1+xml")
Location[] getLocations();
Run Code Online (Sandbox Code Playgroud)
但还有什么必须改变?
你们如何测试您的 SOAP 服务?你使用类似的工具soapUI
还是你写的Unit Tests
?只是想听听一些意见,你更喜欢什么,两种方法的优点或缺点是什么?如果有人写Unit Tests
,你能举个例子如何写吗???
编辑:我开发了很多 REST 服务,我通常使用 JUnit 和 REST 客户端框架进行测试。因此,当部署 REST 服务时,我能够使用 http 连接将这些服务作为 JUnit 测试来调用。SOAP 中也有类似的东西吗?有人有 SOAP 客户端的示例代码吗?
我写了一个Rest-Service,我想测试一下.我想在没有运行服务器的情况下运行JUnit测试.为此,我使用RestEasy的服务器端模拟框架.
我的问题是,如何使用这个框架在Http-Body中使用编组的Java对象来发出Http-Put或Http-Post请求?
下面的代码适用于Http-Get,但如何制作Put或Post,也许有人为此获得了一些示例代码?
@Test
public void testClient() throws Exception {
Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
POJOResourceFactory noDefaults = new POJOResourceFactory(
MyClass.class);
dispatcher.getRegistry().addResourceFactory(noDefaults);
{
MockHttpRequest request = MockHttpRequest.get("/message/test/"
+ requestParam);
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
}
}
Run Code Online (Sandbox Code Playgroud) java ×4
rest ×3
http ×2
jax-rs ×2
soa ×2
web-services ×2
http-headers ×1
java-ee ×1
jpa ×1
junit ×1
resteasy ×1
soap ×1
unit-testing ×1
versioning ×1