我正在尝试编写一个Java程序,该程序从Polarion获取工作记录信息,并将其写入DAT文件供以后使用。
我已经成功地连接到我们的服务器并检索了WorkItem对象,但是除了getUri()之外,所有的getter方法似乎都无法工作,这带来了一个问题,因为我需要使用WorkItem类的getWorkRecords()方法来满足项目的需求。
我已经在我们的主Polarion服务器和我们的“暂存”服务器上尝试了类的getter方法,我们使用它作为一种测试区域,例如我正在尝试编写的程序,并且我有完全的权限。
不管权限如何,我只是在查询一些我创建并分配给自己的虚拟工作项,所以不应该出现任何权限问题,因为我只是试图查看自己的工作项。
以下是该程序的代码:
package test;
//stg= 10.4.1.50
//main= 10.4.1.10
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import javax.xml.rpc.ServiceException;
import com.polarion.alm.ws.client.WebServiceFactory;
import com.polarion.alm.ws.client.session.SessionWebService;
import com.polarion.alm.ws.client.tracker.TrackerWebService;
import com.polarion.alm.ws.client.types.tracker.WorkItem;
import com.polarion.alm.ws.client.types.tracker.WorkRecord;
public class WorkrecordImporter {
private WebServiceFactory factory;
private TrackerWebService trackerService;
private SessionWebService sessionService;
private WorkItem[] workItems;
private ArrayList<WorkRecord> workRecords;
private String password = //insertpasswordhere;//no peaking
public WorkrecordImporter()throws ServiceException, IOException, ClassNotFoundException{
initializeFields();//initializes all of the Web Services and arrays
//step one
getWorkItems();
//readDATFile();
//step two
getWorkRecords();
//$$$
printWorkRecords();
//$$$$$
writeDATFile();
}
//you know what this does.
public void printWorkRecords(){
for(int temp = 0; temp < workItems.length; temp++){
System.out.println(workItems[temp].getUri().toString());
}
}
public void writeDATFile() throws IOException{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:\\Users\\sweidenkopf\\workspace\\test\\filename.dat"));
try {
out.writeObject(workRecords);
} finally {
// Make sure to close the file when done
out.close();
}
}
/**
* This method sets up the WebServiceFactory at the specified URL. It then initializes the web services, logs in the
* session service, and initializes the arrays.
* @throws MalformedURLException
* @throws ServiceException
* @throws RemoteException
*/
public void initializeFields() throws MalformedURLException, ServiceException, RemoteException{
factory = new WebServiceFactory("//insert url here");
trackerService = factory.getTrackerService();
sessionService = factory.getSessionService();
sessionService.logIn("sweidenkopf", password);
workRecords = new ArrayList<>();
}
public void getWorkItems()throws MalformedURLException, ServiceException, RemoteException{
sessionService.beginTransaction();
workItems = trackerService.queryWorkItems("workRecords.user.id:sweidenkopf", null, null);
sessionService.endTransaction(false);
}
public void getWorkRecords()throws MalformedURLException, ServiceException, RemoteException{
sessionService.beginTransaction();
for(int k = 0; k < workItems.length; k++)
{System.out.println("This is working");
try{//not every work item has work records
System.out.println(workItems[k].getWorkRecords());
WorkRecord[] temp;
temp = workItems[k].getWorkRecords();
for(int x = 0; x < temp.length; x++){
System.out.println("This is working fine");
workRecords.add(temp[x]);
}
}catch(NullPointerException e){
System.out.println("I must regretfully inform you that I have grave news; your endeavors have not been successfull.");
continue;
}
}
System.out.println(workRecords.toString());
sessionService.endTransaction(false);
}
public void readDATFile() throws FileNotFoundException, IOException, ClassNotFoundException{
ObjectInputStream in = new ObjectInputStream(new FileInputStream("C:\\Users\\sweidenkopf\\workspace\\test\\filename.dat"));
try{
Object temp = in.readObject();
workRecords = (ArrayList) temp;
}
finally{
in.close();
}
}
} 当然,最重要的部分是my代码中的方法。如您所见,它包含用于调试目的的语句System.out.println(workItems[k].getWorkRecords());。该语句返回null,在该语句中替换时唯一不返回null的WorkItem方法是getUri()。另外,该方法中的try-catch块总是捕获NullPointerException,因为for循环包含temp.length,temp是一个应该包含getWorkRecords()方法返回的变量。
总结一下这里的主要问题是,我无法从getWorkRecords()或任何其他来自WorkItem类的getter方法返回任何内容。这令人费解,因为getUri()方法正在成功执行,因为我代码中的printWorkRecords()方法成功地打印了所有WorkItem对象的URI。
是否有波拉里的专家曾经遇到过这个问题?有人知道我做错了什么吗?我倾向于认为这是一个基于环境的缺陷。
发布于 2013-07-25 22:38:01
如果查看我对queryWorkItems()方法的调用,您会注意到,在查询参数之后,我指定了两个null参数。第一个指定如何对返回的工作项排序(目前这并不重要),但第二个是一个名为String的fields数组,用于指定希望与WorkItems本身一起返回的WorkItem字段中的哪个。显然,如果像我一样将其设置为null,则默认情况下只返回URI。对于其他事情,如作者、工作记录和类型,您必须将它们放在String数组中,并在调用该方法时传递该数组。
https://stackoverflow.com/questions/17821417
复制相似问题