我正在使用JAXB 2.2.8-b01 impl,我有一个架构,它有一个xs:date元素,用于创建XMLGregorianCalendar实例.我正在尝试获取Joda-Time DateTime时间戳格式,但由于我必须有一个XMLGregorianCalendar实例,所以我不确定它是否可行.有任何想法吗?
架构XSD:
<xs:element type="xs:date" name="date-archived" minOccurs="0" maxOccurs="1" nillable="false"/>
Run Code Online (Sandbox Code Playgroud)
JAXB生成的属性:
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar date;
Run Code Online (Sandbox Code Playgroud)
XML转换类:
//java.util.Date being passed
private XMLGregorianCalendar converToGregorianCal(Date date) {
DatatypeFactory df = null;
try {
df = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
LOG.error("error getting DatatypeFactory instance " + e.getMessage());
}
if (date == null) {
return null;
} else {
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(date.getTime());
return df.newXMLGregorianCalendar(gc);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JNI函数创建Java类,并使用DeviceId.java构造函数方法设置该类的一些属性.我能够使用GetMethodID获取构造函数方法,但是如何创建Device.java的新实例然后设置属性(setId和setCache).目标是将完全填充的Device.java对象实例返回给调用者.有任何想法吗?
JNI功能:
JNIEXPORT jobject JNICALL Java_com_test_getID(JNIEnv *env, jclass cls)
{
jmethodID cnstrctr;
jclass c = (*env)->FindClass(env, "com/test/DeviceId");
if (c == 0) {
printf("Find Class Failed.\n");
}else{
printf("Found class.\n");
}
cnstrctr = (*env)->GetMethodID(env, c, "<init>", "(Ljava/lang/String;[B)V");
if (cnstrctr == 0) {
printf("Find method Failed.\n");
}else {
printf("Found method.\n");
}
return (*env)->NewObject(env, c, cnstrctr);
}
Run Code Online (Sandbox Code Playgroud)
Java类:
package com.test;
public class DeviceId {
private String id;
private byte[] cache;
public DeviceId(){}
public DeviceId(String id, byte[] cache){
this.id=id;
this.cache=cache;
}
public byte[] getCache() { …Run Code Online (Sandbox Code Playgroud) 我有一个基于RESTeasy的REST Web服务(见下文).我正在尝试使用谷歌REST客户端来执行测试我的服务的请求,但我不确定应该如何设置请求.
我不知道如何发送byte[]作为param(filedata).
关于如何测试这个的任何想法?
我得到以下异常:
java.io.IOException:无法获取multipart的边界
同
request:
-content-type=multipart/form-data
-form params:
test=testvalue
Run Code Online (Sandbox Code Playgroud)
休息方法:
@POST
@Path("/upload")
@Consumes("multipart/form-data")
public Response create(@MultipartForm FileUploadForm form) {
System.out.println("form=" + form.getTest());
return null;
}
Run Code Online (Sandbox Code Playgroud)
FileUploadForm Pojo:
import javax.ws.rs.FormParam;
import org.jboss.resteasy.annotations.providers.multipart.PartType;
public class FileUploadForm {
private byte[] filedata;
private String test;
public FileUploadForm() {}
public byte[] getFileData() {
return filedata;
}
@FormParam("filedata")
@PartType("application/octet-stream")
public void setFileData(final byte[] filedata) {
this.filedata = filedata;
}
public String getTest() {
return test;
}
@FormParam("test")
@PartType("application/json")
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的JUnit测试执行期间从我的类路径加载sample.properties,它无法在类路径中找到该文件.如果我编写Java Main类,我可以正常加载文件.我正在使用下面的ant任务来执行我的JUnit.
public class Testing {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
Properties props = new Properties();
InputStream fileIn = props_.getClass().getResourceAsStream("/sample.properties");
**props.load(fileIn);**
}
}
Run Code Online (Sandbox Code Playgroud)
JUnit的:
<path id="compile.classpath">
<pathelement location="${build.classes.dir}"/>
</path>
<target name="test" depends="compile">
<junit haltonfailure="true">
<classpath refid="compile.classpath"/>
<formatter type="plain" usefile="false"/>
<test name="${test.suite}"/>
</junit>
</target>
<target name="compile">
<javac srcdir="${src.dir}"
includeantruntime="false"
destdir="${build.classes.dir}" debug="true" debuglevel="lines,vars,source">
<classpath refid="compile.classpath"/>
</javac>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}/resources"
includes="**/*.sql,**/*.properties" />
</copy>
</target>
Run Code Online (Sandbox Code Playgroud)
输出:
[junit] Tests run: 0, Failures: 0, Errors: 1, Time elapsed: 0.104 sec
[junit]
[junit] …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用一个TextView,它有两个文本,一个对着最左边,一个对着最右边.我可以在两个单词之间加上空格,但我想知道是否有更好的技巧?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_common"
android:id="@+id/LinearLayout0123">
<TextView
android:layout_width="300dp"
android:layout_height="40dp"
android:textColor="@color/Black"
android:textStyle="bold"
android:textSize="15dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/selector_social_facebook_twitter"
android:text="Right Text Left Text" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个接收HttpServletRequest的Filter,请求是一个POST,它包含一个xml,我需要读入我的filter方法.从HttpServletRequest对象获取已发布的xml的最佳方法是什么.
谁能告诉我slf4j-log4j和log4j-over-slf4j之间的区别?哪个在Java Web应用程序中使用更标准?我目前在类路径上都有这两个因为Web服务器试图阻止StackOverFlowException发生这种情况而导致运行时异常.
例外:
java.lang.IllegalStateException:
在类路径上检测到log4j-over-slf4j.jar和slf4j-log4j12.jar
我正在尝试实现以下,但我的authenticationManager实例抛出以下异常并且没有自动装配.如何手动从Spring获取它的实例?我没有使用弹簧控制器,我正在使用JSF请求范围的bean.当容器尝试自动装配authenticationManager时,我在运行时得到以下异常.requestCache很好.我不明白为什么我有两个实例......
配置:
<authentication-manager>
<authentication-provider user-service-ref="userManager">
<password-encoder ref="passwordEncoder" />
</authentication-provider>
</authentication-manager>
Run Code Online (Sandbox Code Playgroud)
注入自动连接的依赖项失败; 嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:protected org.springframework.security.authentication.AuthenticationManager com.dc.web.actions.SignUpDetail.authenticationManager; 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义类型为[org.springframework.security.authentication.AuthenticationManager]的唯一bean:期望的单个匹配bean但找到2:[org.springframework.security.authentication.ProviderManager #0,org.springframework.security.authenticationManager] javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
@Controller
public class SignupController
{
@Autowired
RequestCache requestCache;
@Autowired
protected AuthenticationManager authenticationManager;
@RequestMapping(value = "/account/signup/", method = RequestMethod.POST)
public String createNewUser(@ModelAttribute("user") User user, BindingResult result, HttpServletRequest request, HttpServletResponse response)
{
//After successfully Creating user
authenticateUserAndSetSession(user, request);
return "redirect:/home/";
}
private void authenticateUserAndSetSession(User user,
HttpServletRequest request)
{
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
user.getUsername(), user.getPassword());
// generate session if one doesn't exist
request.getSession();
token.setDetails(new WebAuthenticationDetails(request)); …Run Code Online (Sandbox Code Playgroud) 我在Eclipse Indigo上使用了antlr-3.4-complete-no-antlrv2.jar版本的ANTLR.
我已经安装了ANTLR IDE插件以及ZEST和GEF.当我生成组合语法文件并添加标题,词法分析器标头和规则时,Eclipse不会生成Parser和Lexer文件.
如果我使用antlr-3.2.jar就可以了.我可以使用java -classpath antlr-3.4-complete-no-antlrv2.jar org.antlr.Tool Sample.g在Eclipse之外生成Lexer和Parser文件(使用antlr-3.4.*).
有没有办法在Eclipse版本3.4中启用它?
我正在尝试构造正确的sql语句(Oracle)以获取每个customer_id的device_id的计数大于给定值.例如,我想知道拥有3个以上device_ids的customer_id.单个device_id只能有一个customer_id与之关联,而customer_id可能有许多device_id.
Table:
device_id
customer_id
....
Data (device_id, customer_id):
00001, CUST1
00002, CUST1
00003, CUST1
00004, CUST1
00005, CUST2
00006, CUST2
Run Code Online (Sandbox Code Playgroud)