//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
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
解决方案 »
- weblogic启动web工程包java.lang.NoSuchMethodError
- C3P0数据库连接池的问题
- CMPP项目求帮助
- 急求:session问题!!!
- lili830209 D调的河马 进来接分。。。。
- 如何使用axis调用WebServices自定义类型(不使用client.jar)包
- 那位大哥能告诉我使用EJB的理由吗?
- 急急!!类的问题,解决了就给50分(50分)@@@@@@@@
- 为什么用sqlserverjdbc读取text字段值到1596个字符后,后面变乱码了?
- ejb开发工具(除了jbuilder)
- weblogic我受不了了,我快对weblogic失望透了
- interface和abstract interface有何区别!
是不是xml没有。
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) {
}
}
}