尝试在数据库中插入对象时,我收到以下错误消息:
com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException:
DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2,
TABLEID=19, COLNO=0, DRIVER=4.15.134
Run Code Online (Sandbox Code Playgroud)
如何检索引发错误的表/列名称?
我有一台服务器正在执行对外部服务器的Webservice调用.此调用必须通过SSL并使用代理进行:
我的信任库配置得很好:
trustStore is: /opt/configuration/keystore/truststore.jks
trustStore type is : jks
trustStore provider is :
init truststore
adding as trusted cert:
Run Code Online (Sandbox Code Playgroud)
我的握手也正确完成了:
https-jsse-nio-8443-exec-6, READ: TLSv1.2 Handshake, length = 40
Padded plaintext after DECRYPTION: len = 16
0000: 14 00 00 0C 78 49 E5 E1 29 04 A5 1D FC 4F E6 E2 ....xI..)....O..
*** Finished
verify_data: { 120, 73, 229, 225, 41, 4, 165, 29, 252, 79, 230, 226 }
***
[read] MD5 and SHA1 hashes: len = 16
0000: …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我有以下项目结构:
我有一个生成war文件的模块,可以部署在Tomcat应用程序服务器中.该模块依赖于Axis2库:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-webapp</artifactId>
<type>war</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
此类包含WEB-INF下conf文件夹中的axis2.xml文件.
现在这个模块依赖于一个单元模块,它具有jar的包类型.
现在在我的web模块中,在我的存根的代码中,我有以下代码:
.GazelleObjectValidator.getInstance()validateObject();
XcpdValidationService是jar模块(依赖项)中的一个类,此方法通过SSL调用外部Web服务并使用代理.
此Web服务客户端由JAX WS RI生成
但是这个类不使用父模块中的axis2.xml配置并使用它自己的轴配置,这是默认设置,我的代理没有配置...
@WebEndpoint(name = "GazelleObjectValidatorPort")
public GazelleObjectValidator getGazelleObjectValidatorPort() {
return super.getPort(new QName("http://ws.validator.sch.gazelle.ihe.net/", "GazelleObjectValidatorPort"), GazelleObjectValidator.class);
}
Run Code Online (Sandbox Code Playgroud)
该方法本身如下所示:
@WebMethod
@WebResult(name = "validationResult", targetNamespace = "")
@RequestWrapper(localName = "validateObject", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObject")
@ResponseWrapper(localName = "validateObjectResponse", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObjectResponse")
public String validateObject(
@WebParam(name = "base64ObjectToValidate", targetNamespace = "")
String base64ObjectToValidate,
@WebParam(name = "xmlReferencedStandard", targetNamespace = "") …Run Code Online (Sandbox Code Playgroud) 尝试在DB中插入Individual类型的对象时,我得到一个NOT NULL约束违例异常.我使用hsql版本2.3.2.我让hibernate为我生成数据库表.在普通代码中(我使用SQLServer数据库)一切正常.
这是我的单个对象,其中ID由数据库生成,并且是表的主键.
个别对象:
@XmlRootElement
@Entity
@Table(name="INDIVIDUALS")
public class Individual {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="INDIVIDUAL_ID")
private long id;
Run Code Online (Sandbox Code Playgroud)
在HealthCareProfessional对象中,存在指向此Individual对象的主键的链接:
@Entity
@Table(name="HEALTHCARE_PROFESSIONALS")
public class HealthCareProfessional {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="HEALTHCARE_PROFESSIONAL_ID")
private long id;
@ManyToOne
@JoinColumn(name = "INDIVIDUAL_ID", nullable = false, updatable = false, insertable = true)
private Individual individual;
...
Run Code Online (Sandbox Code Playgroud)
我定义entityManagerFactory的应用程序上下文如下所示:
<jdbc:embedded-database id="dataSource" type="HSQL" />
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="/persistence-unittest.xml" />
<property name="persistenceUnitName" value="testingSetup"/>
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!-- Create the database, please --> …Run Code Online (Sandbox Code Playgroud) 我有一个巨大的文件,其中包含ObjectOutputStream一个接一个地写入的对象列表.
for (Object obj : currentList){
oos.writeUnshared(obj);
}
Run Code Online (Sandbox Code Playgroud)
现在我想使用ObjectInputStream读取此文件.但是,我需要同时读取多个文件,因此我无法将整个文件读入内存.但是,使用ObjectInputStream会导致堆内存不足错误.从我读到的,这是因为ObjectInputStream有内存泄漏并且即使在返回它们之后也维护对read对象的引用.
我如何要求ObjectInputStream不保持其读取的引用?
我正在使用ph-schematron,这是一个通过ISO Schematron验证XML文档的Java库:
该库提供了两种XML文档验证方式:
我很想使用第二种类型,但我的Schematron文件包含XSLT函数,所以我们必须使用XSLT而不是纯粹的验证.
我有一个有两个输入参数的验证方法:
现在我的XSLT文件包含这样的行:
<xsl:when test="count(hl7:confidentialityCode[concat(@code,@codeSystem)=doc('include/voc-1.3.6.1.4.1.12559.11.10.1.3.1.42.31-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code,@codeSystem) or @nullFlavor])>=1" />
Run Code Online (Sandbox Code Playgroud)
doc函数在我的项目的主目录中查找名为"include"的文件夹,而不是相对于XSLT文档的文件夹(这将更加逻辑).
现在我有例外:
java.io.FileNotFoundException: C:\LocalData\Development\projectname\include\voc-1.3.6.1.4.1.12559.11.10.1.3.1.42.31-DYNAMIC.xml (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:451)
at net.sf.saxon.event.Sender.send(Sender.java:153)
at net.sf.saxon.functions.DocumentFn.makeDoc(DocumentFn.java:330)
at net.sf.saxon.functions.Doc.call(Doc.java:138)
at net.sf.saxon.functions.Doc.call(Doc.java:24)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546)
at net.sf.saxon.expr.Expression.evaluateItem(Expression.java:773)
at net.sf.saxon.expr.SimpleStepExpression.iterate(SimpleStepExpression.java:108)
at net.sf.saxon.expr.SlashExpression.iterate(SlashExpression.java:868)
at …Run Code Online (Sandbox Code Playgroud) 我正在努力使用一些Spring-security OAuth2配置.
我正在使用:
我想使用Spring安全性的PreAuthorize注释保护我的REST API,我在其中定义了有权访问该方法的角色:
@Transactional
@POST
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response create(User user) throws BusinessException {
LOG.info("POST Request: Creation of a new user with username [{}]", user.getUsername());
UserValidator.validateUser(user);
User createdUser = userDao.create(user);
return Response.ok(createdUser).build();
}
Run Code Online (Sandbox Code Playgroud)
当我为具有角色"ROLE_ADMIN"的用户使用有效的承载令牌调用API方法时,我得到以下异常:
09-Sep-2014 16:13:40.977 SEVERE [http-nio-8080-exec-6] com.sun.jersey.spi.container.ContainerResponse.mapMappableContainerException The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AbstractAccessDecisionManager.checkAllowIfAllAbstainDecisions(AbstractAccessDecisionManager.java:70)
at org.springframework.security.access.vote.UnanimousBased.decide(UnanimousBased.java:107)
at ...
Run Code Online (Sandbox Code Playgroud)
使用邮递员时,我看到以下错误说明:
{
"error": "unauthorized",
"error_description": "Full authentication is …Run Code Online (Sandbox Code Playgroud) rest spring spring-security oauth-2.0 spring-security-oauth2
首先我的设置:
一点背景:
我有一个REST Web服务,它部署在Tomcat Web服务器上,下面有一个h2数据库.我有一个没有任何POST/PUT方法的REST服务.在为其编写集成测试时,我使用H2控制台手动添加了数据库中的条目,并将h2文件放在服务器上.最后,我的集成测试调用REST服务,并返回在DB中手动注入的数据,测试成功.这是不可维护的,为每个测试注入我需要的数据会很棒(这种方法可以用于以后的其他集成测试......).目标是将数据注入与Tomcat上部署的应用程序使用的数据库相同的数据库中.
我认为这很容易,我编写了一个集成测试,重用了服务器端使用的相同应用程序上下文:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="${database.url}" />
<property name="username" value="" />
<property name="password" value="" />
</bean>
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="be.wiv_isp.healthdata.catalogue.domain" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
</props>
</property>
</bean>
<bean id="jpaVendorAdaptor" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf" />
</bean>
Run Code Online (Sandbox Code Playgroud)
数据库url在属性fil中定义的位置:
database.url=jdbc:h2:file:${healthdata.working.dir}/database/database-catalogue;AUTO_SERVER=true
Run Code Online (Sandbox Code Playgroud)
然后我将EntityManager注释为我的PersistenceContext并编写了一个简单的单元测试:
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = {"classpath:/applicationContext-it-test.xml"})
public …Run Code Online (Sandbox Code Playgroud) 我用:
在我的HTML中,我有以下标签,它占用了页面的整个宽度:
<label class="test">Patient</label>
Run Code Online (Sandbox Code Playgroud)
这是我的css:
.test {
display: block;
font-weight: bold;
color: #009fd1;
font-size: .6em;
text-align: left;
padding: 0.5rem;
background: #085a9f;
border-radius: 3px;
}
Run Code Online (Sandbox Code Playgroud)
当我使用iText将HTML转换为PDF时,我的标签显示如下:
它看起来像他把一切都正确,除了display: block和border-radius: 3px
这是iText中的问题吗?
要完成,这是我的转换代码:
public ByteArrayOutputStream createPdf(String html) throws IOException {
ByteArrayOutputStream baos = null;
html = replaceStylesheet(html);
try {
baos = new ByteArrayOutputStream();
WriterProperties writerProperties = new WriterProperties();
//Add metadata
writerProperties.addXmpMetadata();
PdfWriter pdfWriter = new PdfWriter(baos, writerProperties);
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
PageSize pageSize = PageSize.A4; …Run Code Online (Sandbox Code Playgroud) 我有一个位于 $PROJECT_HOME/src/test/resources 的 test.properties 文件,其内容如下:
hostname=${host}
Run Code Online (Sandbox Code Playgroud)
我还有一个 main.properties 文件位于: $PROJECT_HOME/src/main/resources 具有相同的内容。
然后我在我的项目的 pom 文件中指定了以下几行。
<properties>
<host>localhost</host>
</properties>
<build>
<resources>
<!-- Filter resource files -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
....
</build>
Run Code Online (Sandbox Code Playgroud)
执行 mvn clean install 后,我看到目标文件夹中的 main.properties 替换为 localhost 值。但是我的 test.properties 中的属性不是...
我的第一个想法是调整资源如下:
<properties>
<host>localhost</host>
</properties>
<build>
<resources>
<!-- Filter resource files -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
....
</build>
Run Code Online (Sandbox Code Playgroud)
现在构建时,test.properties 文件将替换为 localhost 值,但放置在目标的 classes 文件夹中。在测试类中,仍然存在没有替换值的 test.properties 文件...
有没有办法也替换 test-classes 文件夹中的值?我的想法是在我的本地服务器上使用 localhost 值而不将其指定为参数,并在对测试服务器执行集成测试时使用备用主机覆盖此值。在这种情况下,我在我们的持续集成系统上指定值 -Dhost=<>。