我们有一个包含a .har和a 的大型项目监听器.war,目前在JBoss AS 5上运行.我们希望将此应用程序迁移到JBoss AS 7.大多数AS 7文档都是以Maven为中心的.该项目当前不符合Maven目录结构约定,必须完全重构.
是否值得将此应用程序迁移到Maven?
或者用蚂蚁离开它会更快吗?
我正在将应用程序从hibernate xml配置迁移到注释,我不知道如何使我的BusinessObjectInterceptor类适应新的基于注释的格式.
我们正在改变我们的HibernateUtil类来创建SessionFactory
InitialContext ctx = new InitialContext();
sessionFactory = (SessionFactory)ctx.lookup("java:/hibernate/SessionFactory");
Run Code Online (Sandbox Code Playgroud)
创建EntityManagerFactory
entityManagerFactory = Persistence.createEntityManagerFactory("primary");
Run Code Online (Sandbox Code Playgroud)
我们正在将HibernateUtil类从使用sessionFactory.openSession()更改为从EntityManager创建会话
//s = sessionFactory.openSession(new BusinessObjectInterceptor());
EntityManager entityManager = entityManagerFactory.createEntityManager();
s = entityManager.unwrap(Session.class);
Run Code Online (Sandbox Code Playgroud)
问题是我不确定如何将BusinessObjectInterceptor注入新的Hibernate会话,或者正确的方法来注释我的类以便他们可以使用Interceptor
我正在尝试将Interceptor设置为persistence.xml中的属性.我不确定这是否正确
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="primary"><jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.ejb.interceptor.session_scoped" value="com.mycompany.common.persistence.BusinessObjectInterceptor"/>
</properties>
Run Code Online (Sandbox Code Playgroud)
我们的类以前是通过hbm.xml文件配置的
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.mycompany.liveexpert.common.businessobjects.ServerSettings" table="server_settings">
<id name="serverSettingsID" type="integer" column="server_settings_id">
<generator class="identity" />
</id>
<version name="updateCounter" column="update_counter"/>
<property name="changedDate" type="timestamp" column="changed_date"/>
<property …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Tuckey urlRewriteFilter将任何URL重写为https://,同时保留附加到URL的任何查询字符串参数.我的urlrewrite.xml文件目前看起来像
<urlrewrite use-query-string="true">
<rule>
<note>
The rule means that requests to /test/status/ will be redirected to /rewrite-status
the url will be rewritten.
</note>
<from>/test/status/</from>
<to type="redirect">%{context-path}/rewrite-status</to>
</rule>
<rule match-type="regex">
<condition type="header" operator="notequal" name="X-Forwarded-Proto">^HTTPS$</condition>
<condition type="request-uri" operator="notequal">/station/StationPingServlet</condition>
<condition type="request-uri" operator="notequal">/station/StudioPingServlet</condition>
<from>^.*$</from>
<to type="permanent-redirect" last="true">https://%{server-name}%{request-uri}</to>
</rule>
<outbound-rule>
<note>
The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.
The above rule and this outbound-rule means that end users should …Run Code Online (Sandbox Code Playgroud) 我使用下面的方法遇到了一个奇怪的问题。
@Override
public String deleteToEe(String body) {
logger.debug("Request body");
logger.debug(body);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
headers.add("partner", "test");
headers.add("api_key", "certxxxx");
HttpEntity<String> request = new HttpEntity<String>(body, headers);
ResponseEntity<String> result = null;
try {
result = restTemplate.exchange(targetUrl, HttpMethod.DELETE, request, String.class);
} catch (RestClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result.getBody();
}
Run Code Online (Sandbox Code Playgroud)
当我通过 Postman 命中控制器请求映射来触发此方法时,它起作用了。但是当测试人员通过集成测试触发此方法时,或者当我使用curl触发此方法时
curl -X DELETE -H "Accept: application/json" -H "Content-type: application/json" -d "{"userName": "21", "courseId": "104882_bfaculty3_1024", "isbn": "9780323055", "schoolUserId": "1234" }" http://localhost:8080//api/provision
Run Code Online (Sandbox Code Playgroud)
此时我在代码中遇到空指针异常
result = …Run Code Online (Sandbox Code Playgroud) public String requestAccessToken(String username, String password, String oauthaurl) {
log.info("Request access token");
String token = null;
List<HttpMessageConverter<?>> converters = getMessageConverters();
RestTemplate restTemplate = new RestTemplate();
restTemplate.setMessageConverters(converters);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> oauthPayload = new LinkedMultiValueMap<String, String>();
oauthPayload.add("username", username);
oauthPayload.add("password", password);
oauthPayload.add("grant_type", "password");
HttpEntity<?> request = new HttpEntity<>(oauthPayload, headers);
ResponseEntity<?> response = restTemplate.postForEntity(oauthaurl, request, Object.class);
log.info(response.getStatusCode().toString());
log.info(response.getBody().toString());
JSONObject jsonObject = new JSONObject(response.getBody());
log.info(jsonObject.toString());
//get access_token from jsonObject here
return token;
}
Run Code Online (Sandbox Code Playgroud)
我从令牌网址请求OAuth访问令牌的方法遇到麻烦。我实际上是从服务器获取带有access_token的响应,我在解析响应时遇到了麻烦。
log.info(response.getBody().toString());
Run Code Online (Sandbox Code Playgroud)
退货
{access_token=EI79TeB_Vavu-vgl5WLp8CNWpLUWQBpS3Cm4uU-C1VCJkQJFEo2SthMjPN4gmvQ9ZpQu6Iku11mnvZSUKPVim0MsAEpcMbBdIWl3AMiXCfv9OeqfJRK_1wwIyjo5brDeHK8L5XJPsg98mEKL41qg2IW0Ks9TeYbkRyw4CFKwjcuTi3W3toLBlEGOEinNnrrj6bhOjwaaCVT7zWAIVoImXa-h0VTsoCn2XRVoCO7GENV-Qx55JzTFPJhe2sg72HgRbN8kTID_AcsN8wSKRTQ3T0N74Ks8dfs3YRx0NP4-ADByMcMEnyP8IGoCPHwANNwA8JpYaL2pijWBjOm7VSA53B9Knqxv1EYajBFYXfy74jYUFqlGTKLRUtuKomJh_d9OHM04V-q7xgtlg9upB3s9ORXjbTmzRDzq9U4P67FGJdQe4D4WKUju7oNtjkDzbQZEp0A9fxyHxHFI7MRP4mwPuxMldgytX8Oc1SqoakFre7qzxldaitWqKqnt217e7N7G, token_type=bearer, expires_in=1209599, userName=xxx, …Run Code Online (Sandbox Code Playgroud) 我正在使用 logback 记录到 Spring Boot 服务中的滚动文件。在我的一门课程中,我试图记录一个非常长的字符串(一个非常大的对象数组的字符串值,可以包含数万个元素)。
log.info(str);
Run Code Online (Sandbox Code Playgroud)
上面没有打印,可能是因为str的值是一个非常非常长的字符串。
//logback truncates the list - to preserve this we should record it in an audit table
String rl = String.valueOf(reptIdList);
String truncRlStr = rl.substring(0, Math.min(rl.length(), 100));
log.info(truncRlStr);
Run Code Online (Sandbox Code Playgroud)
上面确实打印了。可能是因为我将很长的字符串截断为 100 个字符。
logback 中的字符串长度可能有限制 - 有没有办法将其设置为最大字符串长度?我注意到登录控制台时对字符串长度没有限制。
感谢您的任何建议。
我通过standalone.bat 启动JBoss as7,它通过standalone.conf.bat 获取JAVA_OPTS 启动选项。我在standalone.conf.bat中设置了大部分JAVA_OPTS,我对一些JAVA_OPTS有一些疑问
-mp "/opt/jboss-as-7.0.0.Final/modules"
-logmodule org.jboss.logmanager
-jaxpmodule javax.xml.jaxp-provider
Run Code Online (Sandbox Code Playgroud)
我尝试将这些设置为
set "JAVA_OPTS=%JAVA_OPTS% -mp /opt/jboss-as-7.0.0.Final/modules"
set "JAVA_OPTS=%JAVA_OPTS% -logmodule org.jboss.logmanager"
set "JAVA_OPTS=%JAVA_OPTS% -jaxpmodule javax.xml.jaxp-provider"
Run Code Online (Sandbox Code Playgroud)
在standalone.conf.bat中。这似乎不起作用,当我通过standalone.bat启动JBoss时,我收到诸如“无法识别的选项-mp”或“无法识别的选项-logmodule”之类的错误。如果我从standalone.conf.bat 中删除这些行,我的JBoss 就能够成功启动。
我的问题是 - 我是否需要设置这些 JBoss 启动选项?我找不到太多关于它们是什么的文档,尤其是“-mp”。如果是这样,设置这些启动选项的最佳方法是什么?JBoss 不喜欢上面的语法。任何建议表示赞赏。
我需要一些关于这个java方法的建议。此方法的目的是获取一个表示日期的字符串(该字符串是根据 EST 时区中的日期创建的)并将其转换为 UTC 时区中的 java Date 对象。
private Date buildValidationDate(String dateString) throws ParseException {
System.out.println("dateString " + dateString);
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyy hh:mm a");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
dateFormat.setLenient(true);
Date dt = dateFormat.parse(dateString);
System.out.println("dt " + dt);
return dt;
}
Run Code Online (Sandbox Code Playgroud)
我看到的问题是 dt 的值似乎已关闭。例如,如果 dateString 是 '10/16/2012 12:06 PM' - 我期望 dt 的值(以 UTC 表示)类似于 'Tuesday, October 16, 2012 4:06 PM'。相反,dt 的值是“Tue Oct 16 07:06:00 CDT 2012”。这似乎不是正确的 UTC 时间。
我很感激任何建议,如果这似乎是一个简单的问题,我很抱歉我在 Java 日期方面遇到了很多麻烦。我不确定我的编码是否错误,或者我的方法是否有问题。谢谢
我正在浏览http://docs.jboss.org/hibernate/stable/core/reference/en-US/html_single/上的Hibernate教程.我创建了一个新项目,并使用Ch中示例中给出的pom.xml.1
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hibernate.tutorials</groupId>
<artifactId>hibernate-tutorial</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>First Hibernate Tutorial</name>
<build>
<!-- we dont want the version to be part of the generated war file name -->
<finalName>${artifactId}</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.0.Beta5</version>
</dependency>
<!-- Because this is a web app, we also have a dependency on the servlet api. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>
<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId> …Run Code Online (Sandbox Code Playgroud) temp = line.split(",");
if (i < paymentFieldsMapIndex.size()) {
paymentFields.put(paymentFieldsMap.get(next).toString(), temp[i]);
}
Run Code Online (Sandbox Code Playgroud)
此代码将逗号分隔的字符串拆分为子字符串,并使用生成的子字符串填充HashMap值.
在生成的HashMap中,某些子字符串值看起来很有趣,看起来是由于令牌中存在逗号.
例如
,"伦敦,英国",
在字符串中出现在HashMap中
Key = key,Value ="LONDON
我认为String split(),如果用双引号括起来,不会破坏包含分隔符的子串吗?
我也试过逃避嵌入式逗号
,"伦敦,英国",
但是HashMap中的字符串看起来像
键=键,值="伦敦\
我错过了什么,或者有什么方法可以解决这个问题吗?谢谢.
SimpleDateFormat formatter = new SimpleDateFormat("mm/dd/yyyy");
dt = formatter.parse(temp[0]);
Run Code Online (Sandbox Code Playgroud)
给了我错误
java.text.ParseException:无法解析的日期:"30-MAR-07"
有没有什么办法可以将给定的String格式化为Date对象,而无需编写自己的字符串拆分和转换为月份数字方法?谢谢
我不确定这是否可行,我想从我的java程序从命令行运行一个Windows exe应用程序 - 类似于
Process process = Runtime.getRunTime().exec("myapp.exe --params");
Run Code Online (Sandbox Code Playgroud)
问题是我想运行从OS X或Linux环境中调用exe的java应用程序.
我想知道是否有人这样做或有任何关于如何做的建议?谢谢
编辑:感谢您的回复.我确实想补充一点,我可能不想使用wine来运行exe,并且可能想要在exe文件周围创建一些类型的包装器来直接从java调用dll中的函数.我以前没有这样做,并想知道是否有任何指针.