Java 类javax.xml.rpc.ServiceFactory 实例源码

项目:parabuild-ci    文件:HelloClient.java   
public static void main(String[] args) throws Exception {
    String UrlString = "http://localhost:8080/axis/services/HelloPort?wsdl";
    String nameSpaceUri = "http://hello.jaxrpc.samples/";
    String serviceName = "HelloWorld";
    String portName = "HelloPort";

    URL helloWsdlUrl = new URL(UrlString);
    ServiceFactory serviceFactory = ServiceFactory.newInstance();
    Service helloService = serviceFactory.createService(helloWsdlUrl,
            new QName(nameSpaceUri, serviceName));

    java.util.List list = helloService.getHandlerRegistry().getHandlerChain(new QName(nameSpaceUri, portName));
    list.add(new javax.xml.rpc.handler.HandlerInfo(ClientHandler.class,null,null));

    Hello myProxy = (Hello) helloService.getPort(
            new QName(nameSpaceUri, portName),
            samples.jaxrpc.hello.Hello.class);

    System.out.println(myProxy.sayHello("Buzz"));
}
项目:parabuild-ci    文件:EmployeeClient.java   
public static void main(String[] args) throws Exception {
    Options opts = new Options(args);
    String uri = "http://faults.samples";
    String serviceName = "EmployeeInfoService";
    ServiceFactory serviceFactory = ServiceFactory.newInstance();
    Service service = serviceFactory.createService(new QName(uri, serviceName));

    TypeMappingRegistry registry = service.getTypeMappingRegistry();
    TypeMapping map = registry.getDefaultTypeMapping();

    QName employeeQName = new QName("http://faults.samples", "Employee");
    map.register(Employee.class, employeeQName, new BeanSerializerFactory(Employee.class, employeeQName), new BeanDeserializerFactory(Employee.class, employeeQName));

    QName faultQName = new QName("http://faults.samples", "NoSuchEmployeeFault");
    map.register(NoSuchEmployeeFault.class, faultQName, new BeanSerializerFactory(NoSuchEmployeeFault.class, faultQName), new BeanDeserializerFactory(NoSuchEmployeeFault.class, faultQName));

    Call call = service.createCall();
    call.setTargetEndpointAddress(new URL(opts.getURL()).toString());
    call.setProperty(Call.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
    call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://faults.samples");
    call.setOperationName( new QName(uri, "getEmployee") );

    String[] args2 = opts.getRemainingArgs();
    System.out.println("Trying :" + args2[0]);
    Employee emp = (Employee) call.invoke(new Object[]{ args2[0] });
    System.out.println("Got :" + emp.getEmployeeID());
}
项目:parabuild-ci    文件:GetInfo.java   
public static void main(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null || args.length % 2 != 0) {
        System.err.println("Usage: GetInfo <symbol> <datatype>");
        System.exit(1);
    }

    String  symbol  = args[0];
    Service service = ServiceFactory.newInstance().createService(null);
    Call    call    = service.createCall();

    call.setTargetEndpointAddress(opts.getURL());
    call.setOperationName(new QName("urn:cominfo", "getInfo"));
    call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter("info", XMLType.XSD_STRING, ParameterMode.IN);
    call.setReturnType(XMLType.XSD_STRING);
    if(opts.getUser()!=null)
        call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    if(opts.getPassword()!=null)
        call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    String res = (String) call.invoke(new Object[] {args[0], args[1]});

    System.out.println(symbol + ": " + res);
}
项目:parabuild-ci    文件:GetQuote1.java   
/**
 * This method does the same thing that getQuote1 does, but in
 * addition it reuses the Call object to make another call.
 */
public float getQuote3(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null) {
        System.err.println("Usage: GetQuote <symbol>");
        System.exit(1);
    }

    /* Define the service QName and port QName */
    /*******************************************/
    QName servQN = new QName("urn:xmltoday-delayed-quotes",
            "GetQuoteService");
    QName portQN = new QName("urn:xmltoday-delayed-quotes", "GetQuote");

    /* Now use those QNames as pointers into the WSDL doc */
    /******************************************************/
    Service service = ServiceFactory.newInstance().createService(
            new URL("file:samples/stock/GetQuote.wsdl"), servQN);
    Call call = service.createCall(portQN, "getQuote");

    /* Strange - but allows the user to change just certain portions of */
    /* the URL we're gonna use to invoke the service.  Useful when you  */
    /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
    /********************************************************************/
    opts.setDefaultURL(call.getTargetEndpointAddress());
    call.setTargetEndpointAddress(opts.getURL());

    /* Define some service specific properties */
    /*******************************************/
    call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    /* Get symbol and invoke the service */
    /*************************************/
    Object result = call.invoke(new Object[] {symbol = args[0]});

    /* Reuse the Call object for a different call */
    /**********************************************/
    call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "test"));
    call.removeAllParameters();
    call.setReturnType(XMLType.XSD_STRING);

    System.out.println(call.invoke(new Object[]{}));
    return ((Float) result).floatValue();
}
项目:parabuild-ci    文件:AddressClient.java   
public static void main(String[] args) throws Exception {
    URL urlWsdl = new URL("http://localhost:8080/axis/services/Address?wsdl");
    String nameSpaceUri = "http://address.jaxrpc.samples";
    String serviceName = "AddressServiceService";
    String portName = "Address";

    ServiceFactory serviceFactory = ServiceFactory.newInstance();
    Service service = serviceFactory.createService(urlWsdl, new
            QName(nameSpaceUri, serviceName));
    AddressService myProxy = (AddressService) service.getPort(new
            QName(nameSpaceUri, portName), AddressService.class);
    AddressBean addressBean = new AddressBean();
    addressBean.setStreet("55, rue des Lilas");
    System.out.println(myProxy.updateAddress(addressBean, 75005));
}
项目:class-guard    文件:LocalJaxRpcServiceFactory.java   
/**
 * Create a JAX-RPC Service according to the parameters of this factory.
 * @see #setServiceName
 * @see #setWsdlDocumentUrl
 * @see #postProcessJaxRpcService
 */
public Service createJaxRpcService() throws ServiceException {
    ServiceFactory serviceFactory = getServiceFactory();
    if (serviceFactory == null) {
        serviceFactory = createServiceFactory();
    }

    // Create service based on this factory's settings.
    Service service = createService(serviceFactory);

    // Allow for custom post-processing in subclasses.
    postProcessJaxRpcService(service);

    return service;
}
项目:class-guard    文件:LocalJaxRpcServiceFactory.java   
/**
 * Create a JAX-RPC ServiceFactory, either of the specified class
 * or the default.
 * @throws ServiceException if thrown by JAX-RPC methods
 * @see #setServiceFactoryClass
 * @see javax.xml.rpc.ServiceFactory#newInstance()
 */
protected ServiceFactory createServiceFactory() throws ServiceException {
    if (getServiceFactoryClass() != null) {
        return (ServiceFactory) BeanUtils.instantiateClass(getServiceFactoryClass());
    }
    else {
        return ServiceFactory.newInstance();
    }
}
项目:class-guard    文件:LocalJaxRpcServiceFactory.java   
/**
 * Actually create the JAX-RPC Service instance,
 * based on this factory's settings.
 * @param serviceFactory the JAX-RPC ServiceFactory to use
 * @return the newly created JAX-RPC Service
 * @throws ServiceException if thrown by JAX-RPC methods
 * @see javax.xml.rpc.ServiceFactory#createService
 * @see javax.xml.rpc.ServiceFactory#loadService
 */
protected Service createService(ServiceFactory serviceFactory) throws ServiceException {
    if (getServiceName() == null && getJaxRpcServiceInterface() == null) {
        throw new IllegalArgumentException("Either 'serviceName' or 'jaxRpcServiceInterface' is required");
    }

    if (getJaxRpcServiceInterface() != null) {
        // Create service via generated JAX-RPC service interface.
        // Only supported on JAX-RPC 1.1
        if (getWsdlDocumentUrl() != null || getJaxRpcServiceProperties() != null) {
            return serviceFactory.loadService(
                    getWsdlDocumentUrl(), getJaxRpcServiceInterface(), getJaxRpcServiceProperties());
        }
        return serviceFactory.loadService(getJaxRpcServiceInterface());
    }

    // Create service via specified JAX-RPC service name.
    QName serviceQName = getQName(getServiceName());
    if (getJaxRpcServiceProperties() != null) {
        // Only supported on JAX-RPC 1.1
        return serviceFactory.loadService(getWsdlDocumentUrl(), serviceQName, getJaxRpcServiceProperties());
    }
    if (getWsdlDocumentUrl() != null) {
        return serviceFactory.createService(getWsdlDocumentUrl(), serviceQName);
    }
    return serviceFactory.createService(serviceQName);
}
项目:parabuild-ci    文件:GetQuote1.java   
/**
 * This will use the WSDL to prefill all of the info needed to make
 * the call.  All that's left is filling in the args to invoke().
 */
public float getQuote1(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null) {
        System.err.println("Usage: GetQuote <symbol>");
        System.exit(1);
    }

    /* Define the service QName and port QName */
    /*******************************************/
    QName servQN = new QName("urn:xmltoday-delayed-quotes",
            "GetQuoteService");
    QName portQN = new QName("urn:xmltoday-delayed-quotes", "GetQuote");

    /* Now use those QNames as pointers into the WSDL doc */
    /******************************************************/
    Service service = ServiceFactory.newInstance().createService(
            new URL("file:samples/stock/GetQuote.wsdl"), servQN);
    Call call = service.createCall(portQN, "getQuote");

    /* Strange - but allows the user to change just certain portions of */
    /* the URL we're gonna use to invoke the service.  Useful when you  */
    /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
    /********************************************************************/
    opts.setDefaultURL(call.getTargetEndpointAddress());
    call.setTargetEndpointAddress(opts.getURL());

    /* Define some service specific properties */
    /*******************************************/
    call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    /* Get symbol and invoke the service */
    /*************************************/
    Object result = call.invoke(new Object[] {symbol = args[0]});

    return ((Float) result).floatValue();
}
项目:parabuild-ci    文件:GetQuote1.java   
/**
 * This will do everything manually (ie. no WSDL).
 */
public float getQuote2(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null) {
        System.err.println("Usage: GetQuote <symbol>");
        System.exit(1);
    }

    /* Create default/empty Service and Call object */
    /************************************************/
    Service service = ServiceFactory.newInstance().createService(null);
    Call call = service.createCall();

    /* Strange - but allows the user to change just certain portions of */
    /* the URL we're gonna use to invoke the service.  Useful when you  */
    /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
    /********************************************************************/
    opts.setDefaultURL("http://localhost:8080/axis/servlet/AxisServlet");

    /* Set all of the stuff that would normally come from WSDL */
    /***********************************************************/
    call.setTargetEndpointAddress(opts.getURL());
    call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    call.setProperty(Call.SOAPACTION_URI_PROPERTY, "getQuote");
    call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY,
            "http://schemas.xmlsoap.org/soap/encoding/");
    call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "getQuote"));
    call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN);
    call.setReturnType(XMLType.XSD_FLOAT);

    /* Define some service specific properties */
    /*******************************************/
    call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    /* Get symbol and invoke the service */
    /*************************************/
    Object result = call.invoke(new Object[] {symbol = args[0]});

    return ((Float) result).floatValue();
}
项目:class-guard    文件:LocalJaxRpcServiceFactory.java   
/**
 * Return the specified ServiceFactory instance, if any.
 */
public ServiceFactory getServiceFactory() {
    return this.serviceFactory;
}
项目:windup-rulesets    文件:RPC.java   
public static void main(String argv[]) {
    ServiceFactory sf = new ServiceFactory();
    XmlRpcClient client = new XmlRpcClient();
    XmlRpcParser parse = new XmlRpcParser();
}
项目:class-guard    文件:LocalJaxRpcServiceFactory.java   
/**
 * Set the ServiceFactory class to use, for example
 * "org.apache.axis.client.ServiceFactory".
 * <p>Does not need to be set if the JAX-RPC implementation has registered
 * itself with the JAX-RPC system property "SERVICEFACTORY_PROPERTY".
 * @see javax.xml.rpc.ServiceFactory
 */
public void setServiceFactoryClass(Class serviceFactoryClass) {
    if (serviceFactoryClass != null && !ServiceFactory.class.isAssignableFrom(serviceFactoryClass)) {
        throw new IllegalArgumentException("'serviceFactoryClass' must implement [javax.xml.rpc.ServiceFactory]");
    }
    this.serviceFactoryClass = serviceFactoryClass;
}
项目:class-guard    文件:LocalJaxRpcServiceFactory.java   
/**
 * Set the ServiceFactory instance to use.
 * <p>This is an alternative to the common "serviceFactoryClass" property,
 * allowing for a pre-initialized ServiceFactory instance to be specified.
 * @see #setServiceFactoryClass
 */
public void setServiceFactory(ServiceFactory serviceFactory) {
    this.serviceFactory = serviceFactory;
}