//queryservice.java
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;
import javax.xml.registry.*; 
import javax.xml.registry.infomodel.*; 
import javax.xml.registry.ConnectionFactory.*;public class QueryService implements Serializable {   
    public static void main(String[] args) {
          
      String RegistryURL = "http://localhost:8080/RegistryServer";
      String RPCDistributor = "JAXRPCCoffeeDistributor";
      JAXRQueryByName jq = new JAXRQueryByName();
      Connection connection =  jq.makeConnection(RegistryURL, RegistryURL);
      Collection orgs = jq.executeQuery(RPCDistributor);
      Iterator orgIter = orgs.iterator();  
      try {
        while (orgIter.hasNext()) {
          Organization org = (Organization) orgIter.next();
          System.out.println("Org name: " + jq.getName(org));
          System.out.println("Org description: " + jq.getDescription(org));
          System.out.println("Org key id: " + jq.getKey(org));          Collection services = org.getServices();
          Iterator svcIter = services.iterator();
          while (svcIter.hasNext()) {
            Service svc = (Service) svcIter.next();
            System.out.println(" Service name: " + jq.getName(svc));
            System.out.println(" Service description: " + jq.getDescription(svc));
            Collection serviceBindings = svc.getServiceBindings();
            Iterator sbIter = serviceBindings.iterator();
            while (sbIter.hasNext()) {
              ServiceBinding sb = (ServiceBinding) sbIter.next();
              String distributor = sb.getAccessURI();
              System.out.println("  Binding Description: " + jq.getDescription(sb));
              System.out.println("  Access URI: " + distributor);
            }
          }     
          System.out.println(" --- ");
        } 
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println("no data found");
      } finally  {     
        if (connection != null) {
          try {
           connection.close();
          } catch (JAXRException je) {}
        }
      }
  } 
}
错误提示:
C:\webservices\0428>ant run-query
Buildfile: build.xmlbuild:run-query:
     [java] javax.xml.registry.JAXRException: Unable to create ConnectionFactory
: Provider com.sun.xml.registry.common.ConnectionFactoryImpl not found
     [java]     at javax.xml.registry.ConnectionFactory.newInstance(Unknown Sour
ce)
     [java]     at JAXRQueryByName.makeConnection(Unknown Source)
     [java]     at QueryService.main(Unknown Source)
     [java] java.lang.NullPointerException
     [java]     at JAXRQueryByName.executeQuery(Unknown Source)
     [java]     at QueryService.main(Unknown Source)
     [java] java.lang.NullPointerException
     [java]     at QueryService.main(Unknown Source)
     [java] Exception in thread "main"
     [java] Java Result: 1BUILD SUCCESSFUL
Total time: 3 seconds

解决方案 »

  1.   

    其实我也是在学习。
    是不是xml没有。
      

  2.   

    邦我分析一下这个代码吧:现在我不懂得是,当我请求http://localhost:8080/cbserver/orderForm这个地址的时候,他来的显示内容格式这种代码我怎么没有发现阿?他这里好像是取得数据阿,没有显示阿,他怎么显示的呢?还有
    request.getRequestDispatcher("/template.jsp").forward(request, response);
    这行代码试什么意思??//Dispatcher.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.math.BigDecimal;public class Dispatcher extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response) {   
          HttpSession session = request.getSession();
          ResourceBundle messages = (ResourceBundle)session.getAttribute("messages");
          if (messages == null) {
             Locale locale=request.getLocale();
             messages = ResourceBundle.getBundle("com.sun.cb.messages.CBMessages", locale); 
             session.setAttribute("messages", messages);
          }    ServletContext context = getServletContext();
        RetailPriceList rpl = (RetailPriceList)context.getAttribute("retailPriceList");
        if (rpl == null) {
          try {
              rpl = new RetailPriceList();
              context.setAttribute("retailPriceList", rpl);
            } catch (Exception ex) {
              context.log("Couldn't create price list: " + ex.getMessage());
            }
        }
        ShoppingCart cart = (ShoppingCart)session.getAttribute("cart");
        if (cart == null) {
            cart = new ShoppingCart(rpl);
            session.setAttribute("cart", cart);
        }
        String selectedScreen = request.getServletPath();
        request.setAttribute("selectedScreen", selectedScreen);    if (selectedScreen.equals("/checkoutForm")) {
          CheckoutFormBean checkoutFormBean = new CheckoutFormBean(cart, rpl, messages);      request.setAttribute("checkoutFormBean", checkoutFormBean);
          try {
            checkoutFormBean.setFirstName(request.getParameter("firstName"));
            checkoutFormBean.setLastName(request.getParameter("lastName"));
            checkoutFormBean.setEmail(request.getParameter("email"));
            checkoutFormBean.setAreaCode(request.getParameter("areaCode"));
            checkoutFormBean.setPhoneNumber(request.getParameter("phoneNumber"));
            checkoutFormBean.setStreet(request.getParameter("street"));
            checkoutFormBean.setCity(request.getParameter("city"));
            checkoutFormBean.setState(request.getParameter("state"));
            checkoutFormBean.setZip(request.getParameter("zip"));
            checkoutFormBean.setCCNumber(request.getParameter("CCNumber"));
            checkoutFormBean.setCCOption(Integer.parseInt(request.getParameter("CCOption")));
          } catch (NumberFormatException e) {
            // not possible
          }
        }
        try {
            request.getRequestDispatcher("/template.jsp").forward(request, response);
        } catch(Exception ex) {
          ex.printStackTrace();
        }
      }
      public void doPost(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        ResourceBundle messages = (ResourceBundle)session.getAttribute("messages");
        String selectedScreen = request.getServletPath();
        request.setAttribute("selectedScreen", selectedScreen);    ServletContext context = getServletContext();
        RetailPriceList rpl = (RetailPriceList)context.getAttribute("retailPriceList");
        if (rpl == null) {
          try {
              rpl = new RetailPriceList();
              context.setAttribute("retailPriceList", rpl);
            } catch (Exception ex) {
              context.log("Couldn't create price list: " + ex.getMessage());
            }
        }
        ShoppingCart cart = (ShoppingCart)session.getAttribute("cart");
        if (cart == null ) {
            cart = new ShoppingCart(rpl);
            session.setAttribute("cart", cart);
        }
     
        if (selectedScreen.equals("/orderForm")) {
          cart.clear();
          for(Iterator i = rpl.getItems().iterator(); i.hasNext(); ) {
            RetailPriceItem item = (RetailPriceItem) i.next();
            String coffeeName = item.getCoffeeName();
            BigDecimal pounds = new BigDecimal(request.getParameter(coffeeName + "_pounds"));
            BigDecimal price = item.getRetailPricePerPound().multiply(pounds).setScale(2, BigDecimal.ROUND_HALF_UP);
            ShoppingCartItem sci = new ShoppingCartItem(item, pounds, price);
            cart.add(sci);
          }    } else if (selectedScreen.equals("/checkoutAck")) {
          CheckoutFormBean checkoutFormBean = new CheckoutFormBean(cart, rpl, messages);      request.setAttribute("checkoutFormBean", checkoutFormBean);
          try {
            checkoutFormBean.setFirstName(request.getParameter("firstName"));
            checkoutFormBean.setLastName(request.getParameter("lastName"));
            checkoutFormBean.setEmail(request.getParameter("email"));
            checkoutFormBean.setAreaCode(request.getParameter("areaCode"));
            checkoutFormBean.setPhoneNumber(request.getParameter("phoneNumber"));
            checkoutFormBean.setStreet(request.getParameter("street"));
            checkoutFormBean.setCity(request.getParameter("city"));
            checkoutFormBean.setState(request.getParameter("state"));
            checkoutFormBean.setZip(request.getParameter("zip"));
            checkoutFormBean.setCCNumber(request.getParameter("CCNumber"));
            checkoutFormBean.setCCOption(Integer.parseInt(request.getParameter("CCOption")));
          } catch (NumberFormatException e) {
            // not possible
          }
          if (!checkoutFormBean.validate())
            request.setAttribute("selectedScreen", "/checkoutForm");
        }    try {
            request.getRequestDispatcher("/template.jsp").forward(request, response);
        } catch(Exception e) {
        }
      }
    }