billingsystemsimulator.java

来自「考勤管理系统源码」· Java 代码 · 共 83 行

JAVA
83
字号
package com.wiley.compBooks.EJwithUML.Clients;

import javax.naming.*;
import javax.ejb.*;
import java.rmi.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import java.net.*;
import java.io.*;
import java.text.ParseException;
import com.wiley.compBooks.EJwithUML.TimeCardDomain.*;
import com.wiley.compBooks.EJwithUML.Base.EjbUtil.*;
import com.wiley.compBooks.EJwithUML.TimeCardWorkflow.*;
import com.wiley.compBooks.EJwithUML.Base.ApplicationExceptions.*;
import com.wiley.compBooks.EJwithUML.Base.DateUtil;

/**
 * This class simulates the behavior of a BillingSystem and works as test driver
 * for ExtractTimeEntryServlet.
 */
public class BillingSystemSimulator
{
  public static void main(String[] args) throws Exception
  {
    try
    {
      if (args.length < 4)
      {
        System.out.println(
        "Usage: java comwiley.compBooks.EJwithUML.Clients.BillingSystemSimulator"
        +"serverurl clientName startDate endDate <a list of user names(optional)>");
        System.exit(1);
      }
      StringBuffer request = new StringBuffer(500);
      request.append("<env:Envelope xmlns:env=\"http://www.w3c.org/2002/06/soap-envelope\""
                     + " xmlns:tcapp=\"http://com.wiley.compBooks/EJwithUML2e\">");
      request.append("<env:Header>" +
      "<tcapp:Requester env:mustUnderstand=\"1\">");
      request.append("com.wiley.compBooks.EJwithUML2e.BillingSystem</tcapp:Requester></env:Header>");
      request.append("<env:Body><tcapp:GetTimeEntryReport><tcapp:ClientName>");
      request.append(args[1]+"</tcapp:ClientName>");
      request.append("<tcapp:StartDate>" + args[2] + "</tcapp:StartDate>");
      request.append("<tcapp:EndDate>" + args[3] + "</tcapp:EndDate>");
      if (args.length == 4)
      {
        request.append("<tcapp:AllUser/></tcapp:GetTimeEntryReport></env:Body></env:Envelope>");
      }
      else
      {
        request.append("<tcapp:Users>");
        for(int i=4; i < args.length;i++)
        {
          request.append("<tcapp:UserName>" + args[i] + "</tcapp:UserName>");
        }
        request.append("</tcapp:Users></tcapp:GetTimeEntryReport></env:Body></env:Envelope>");
      }
      System.out.println("request:");
      System.out.println(request);
      URL url = new URL(args[0]);
      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
      connection.setDoOutput(true);
      connection.setDoInput(true);
      connection.setRequestMethod("POST");
      PrintWriter writer = new PrintWriter(connection.getOutputStream());
      writer.print(request);
      writer.flush();
      writer.close();
      System.out.println("response:");
      BufferedReader reader = new BufferedReader(new InputStreamReader(
                              connection.getInputStream()));
      String line= null;
      while((line=reader.readLine()) != null)
      {
        System.out.println(line);
      }
    }
    catch (Exception e)
    {
      System.err.println("e:" +e);
      e.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?