0

I have written a web-service that returns 5 values:

String taskPresentationName_UWL = null; 
String taskActivationTime_UWL = null;   
String taskPriority_UWL = null; 
String taskStatus_UWL = null;   
String taskID_UWL = null;

My case is that I run a loop and I want to return a list or an array with these values.

As it is the code right now, I only get 1 line as an answer. For example:

taskPresentationName_test1, taskActivationTime_test1, taskPriority_test1, taskStatus_test1,taskID_test1

But the answer I want to return should look like below:

taskPresentationName_test1, taskActivationTime_test1, taskPriority_test1, taskStatus_test1,taskID_test1

taskPresentationName_test2, taskActivationTime_test2, taskPriority_test2, taskStatus_test2,taskID_test2

....

How can I return the answer to a List or an Xml???

My code is the below

@WebService(name = "getUWLTasks", portName = "getUWLTasksPort", serviceName = "getUWLTasksService", targetNamespace = "http://sap.com/tutorial/testAPI/")
@Stateless
public class getUWLTasks
{
   @WebMethod(operationName = "getTasks", exclude = false)
   public void getTasks(
      @WebParam(name = "taskPresentationName", mode = WebParam.Mode.OUT) Holder<String> taskPresentationName,
      @WebParam(name = "taskActivationTime", mode = WebParam.Mode.OUT) Holder<String> taskActivationTime,
      @WebParam(name = "taskPriority", mode = WebParam.Mode.OUT) Holder<String> taskPriority,
      @WebParam(name = "taskStatus", mode = WebParam.Mode.OUT) Holder<String> taskStatus,
      @WebParam(name = "taskID", mode = WebParam.Mode.OUT) Holder<String> taskID) {

      String taskPresentationName_UWL = null;
      String taskActivationTime_UWL = null;
      String taskPriority_UWL = null;
      String taskStatus_UWL = null;

      String taskID_UWL = null;

      try
      {    
         TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();
         HashSet<Status> statuses = new HashSet<Status>();
         statuses.add(Status.READY);
         statuses.add(Status.RESERVED);
         statuses.add(Status.IN_PROGRESS);

         Set<TaskAbstract> myTasks = taskInstanceManager.getMyTaskAbstracts(statuses);
         Iterator<TaskAbstract> taskIter = myTasks.iterator();

         while (taskIter.hasNext())
         {    
            TaskAbstract ta = taskIter.next();

            //Get the UWL as it appears        

            java.net.URI taskInstanceId = ta.getId();

            URL taskExecutionURL = taskInstanceManager.generateTaskExecutionUrl(taskInstanceId);
            TaskDetail taskDetail = taskInstanceManager.getTaskDetail(taskInstanceId);

            taskPresentationName_UWL = ta.getPresentationName();
            taskActivationTime_UWL = ta.getCreatedTime().toString();
            taskPriority_UWL = ta.getPriority().toString();
            taskStatus_UWL = ta.getStatus().toString();

            taskID_UWL = ta.getId().toString();

            taskPresentationName.value = taskPresentationName_UWL;
            taskActivationTime.value = taskActivationTime_UWL;
            taskPriority.value = taskPriority_UWL;
            taskStatus.value = taskStatus_UWL;

            taskID.value = taskID_UWL;    
         }
      }
      catch (BPMException e)
      {    
         // TODO Auto-generated catch block
         e.printStackTrace();    
      }
   }
}
Littm
  • 4,923
  • 4
  • 30
  • 38

1 Answers1

0

I write simple WS, and all works like you want

@WebMethod(operationName = "getTasks", exclude = false)
   public void getTasks(
      @WebParam(name = "taskPresentationName", mode = WebParam.Mode.OUT) Holder<String[]> taskPresentationName,
      @WebParam(name = "taskActivationTime", mode = WebParam.Mode.OUT) Holder<String[]> taskActivationTime,
      @WebParam(name = "taskPriority", mode = WebParam.Mode.OUT) Holder<String[]> taskPriority,
      @WebParam(name = "taskStatus", mode = WebParam.Mode.OUT) Holder<String[]> taskStatus,
      @WebParam(name = "taskID", mode = WebParam.Mode.OUT) Holder<String[]> taskID)
          {
             taskPresentationName.value = new String[]{"a1", "a2"}; 
             taskActivationTime.value = new String[]{"b1", "b2"};
             taskPriority.value = new String[]{"c1", "c2"};
          }  

response contains

 <taskPresentationName>a1</taskPresentationName>
 <taskPresentationName>a2</taskPresentationName>
     <taskActivationTime>b1</taskActivationTime>
 <taskActivationTime>b2</taskActivationTime>
     <taskPriority>c1</taskPriority>
 <taskPriority>c2</taskPriority>  

EDIT

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Task 
{
   String taskPresentationName_UWL;
   //...
   String taskID_UWL;

   // getters, setters
}  

tasks

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Tasks
{
   @XmlElement
   private List<Task> tasks = new ArrayList<Task>(); 

   public List<Task> getTasks()
   {
      return tasks;
   }
}  

web-method

@WebMethod(operationName = "getTasks", exclude = false)
@WebResult(name = "tasks")
public Tasks getTasks() {  
//...  
}
Ilya
  • 29,135
  • 19
  • 110
  • 158
  • my problem is that I have to achieve the desired result using only ONE class because of some restriction of the environment I am developing – user1630426 Aug 28 '12 at 15:11
  • Use String[] instead of Holder – Ilya Aug 28 '12 at 15:52
  • Yes. @WebParam with out mode, doesn't support non-holder classes – Ilya Aug 29 '12 at 07:56
  • I am totally confused from your anwser :( I can return with the holder for example, 5 variables but the anwser of the webservice is a list of 5 variables like (var11,var12,var13,var14,var15) (var21,var22,var23,var24,var25) etc etc. I can also return 5 different ArrayLists with the anwser but what I cannot do is to return the anwser like a complex type. I dont know how to describe it. The demand is to have an anwser in a xml format like for example Tasks[(var11,var12,var13,var14,var15),(var21,var22,var23,var24,var25)...] Is there any easy way to achieve it? Thanks in advance – user1630426 Aug 29 '12 at 08:05
  • For complex type you need more than "ONE class" – Ilya Aug 29 '12 at 08:15
  • Thank you very very much for your help. Can you please help me with an example how can I create the above example as a complex type, even with more than one class? I mean how is it possible to get an xml anwser in a format like lets say Tasks[(var11,var12...),(va21,var22..)...] – user1630426 Aug 29 '12 at 08:29
  • I found the way using this example http://stackoverflow.com/questions/5514752/xml-element-with-attribute-and-content-using-jaxb...I wanted to thank you again for your help – user1630426 Aug 29 '12 at 11:57