📄 netstorewebservicedelegate.java
字号:
package netstore.service;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.encoding.ser.BeanDeserializerFactory;import org.apache.axis.encoding.ser.BeanSerializerFactory;import javax.xml.namespace.QName;import javax.xml.rpc.ParameterMode;import java.rmi.RemoteException;import java.util.Hashtable;import java.util.List;import java.util.Date;import javax.servlet.ServletContext;import netstore.catalog.view.ItemDetailView;import netstore.catalog.view.ItemSummaryView;import netstore.customer.view.UserView;import netstore.framework.exceptions.*;import netstore.service.INetstoreService;/*** This class is a business delegate that supports the implementation of the* INetstoreService interface using the Netstore session bean.*/public class NetstoreWebServiceDelegate implements INetstoreService { private Service netstoreService; ServletContext servletContext = null; String endpoint=null; public NetstoreWebServiceDelegate( ) { init( ); } private void init( ) { try { endpoint = "http://localhost:8080/axis/services/netstoreservice"; netstoreService = new Service(); } catch (Exception e) { throw new RuntimeException(e.getMessage( )); } } public UserView authenticate( String email, String password ) throws InvalidLoginException, ExpiredPasswordException, AccountLockedException, DatastoreException { try { Call call = (Call) netstoreService.createCall(); QName qn = new QName("urn:BeanService","UserView"); Class cls = UserView.class; call.registerTypeMapping(cls, qn, new org.apache.axis.encoding.ser.BeanSerializerFactory(cls, qn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(cls, qn)); QName dateqn = new QName("urn:BeanService","Date"); Class datecls = Date.class; call.registerTypeMapping(datecls, dateqn, new org.apache.axis.encoding.ser.BeanSerializerFactory(datecls, dateqn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(datecls, dateqn)); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("urn:netstoreservice", "authenticate") ); call.addParameter( "arg1", org.apache.axis.encoding.XMLType.XSD_STRING , ParameterMode.IN ); call.addParameter( "arg2", org.apache.axis.encoding.XMLType.XSD_STRING , ParameterMode.IN ); call.setReturnType(qn,UserView.class); return (UserView) call.invoke( new Object[] { email,password } ); } catch (javax.xml.rpc.ServiceException e) { throw DatastoreException.datastoreError(e); }catch (java.net.MalformedURLException e) { throw DatastoreException.datastoreError(e); }catch(java.rmi.RemoteException e){ throw DatastoreException.datastoreError(e); } } public List getFeaturedItems( ) throws DatastoreException { try { Call call = (Call) netstoreService.createCall(); QName sumqn = new QName("urn:BeanService","ItemSummaryView"); Class sumcls = ItemSummaryView.class; call.registerTypeMapping(sumcls, sumqn, new org.apache.axis.encoding.ser.BeanSerializerFactory(sumcls, sumqn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(sumcls, sumqn)); QName dateqn = new QName("urn:BeanService","Date"); Class datecls = Date.class; call.registerTypeMapping(datecls, dateqn, new org.apache.axis.encoding.ser.BeanSerializerFactory(datecls, dateqn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(datecls, dateqn)); QName qn = new QName("urn:BeanService","List"); Class cls = List.class; call.registerTypeMapping(cls, qn, new org.apache.axis.encoding.ser.BeanSerializerFactory(cls, qn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(cls, qn)); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("urn:netstoreservice", "getFeaturedItems") ); call.setReturnType(qn,List.class); return (List) call.invoke(new Object[] {} ); } catch (javax.xml.rpc.ServiceException e) { throw DatastoreException.datastoreError(e); }catch (java.net.MalformedURLException e) { throw DatastoreException.datastoreError(e); }catch(java.rmi.RemoteException e){ e.printStackTrace(); throw DatastoreException.datastoreError(e); } } public ItemDetailView getItemDetailView( String itemId ) throws DatastoreException { try { Call call = (Call) netstoreService.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); QName dateqn = new QName("urn:BeanService","Date"); Class datecls = Date.class; call.registerTypeMapping(datecls, dateqn, new org.apache.axis.encoding.ser.BeanSerializerFactory(datecls, dateqn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(datecls, dateqn)); QName qn = new QName("urn:BeanService","ItemDetailView"); Class cls = ItemDetailView.class; call.registerTypeMapping(cls, qn, new org.apache.axis.encoding.ser.BeanSerializerFactory(cls, qn), new org.apache.axis.encoding.ser.BeanDeserializerFactory(cls, qn)); call.setOperationName(new QName("urn:netstoreservice", "getItemDetailView") ); call.addParameter( "arg1", org.apache.axis.encoding.XMLType.XSD_STRING , ParameterMode.IN ); call.setReturnType(qn,ItemDetailView.class); return (ItemDetailView) call.invoke( new Object[]{ itemId } ); } catch (javax.xml.rpc.ServiceException e) { throw DatastoreException.datastoreError(e); }catch (java.net.MalformedURLException e) { throw DatastoreException.datastoreError(e); }catch(java.rmi.RemoteException e){ throw DatastoreException.datastoreError(e); } } public void logout( String email ) { // Do nothing for this example } public void destroy( ) { // Do nothing for this example } public void setServletContext( ServletContext ctx ){ this.servletContext = ctx; } public ServletContext getServletContext(){ return servletContext; } public static void main(String args[])throws Exception{ NetstoreWebServiceDelegate service=new NetstoreWebServiceDelegate(); List l=service.getFeaturedItems(); ItemDetailView view2= service.getItemDetailView("110"); System.out.println(view2.getDescription()+";"+view2.getProductFeature()); UserView view3=service.authenticate("weiqin@yahoo.com","weiqin"); System.out.println(view3.getFirstName()+view3.getLastName()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -