public static void main(String[] args) { try { String bwbh = "深建住保[2013]65号"; // 返回参数类型 Service service = new Service(); // String wsdlUrl = "http://localhost/services/WebServiceForSearch?wsdl";//请求服务的URL // String wsdlUrl = "http://192.168.0.72/services/WebServiceForSearch?wsdl"; String wsdlUrl = "http://192.168.53.89:7001/services/WebServiceForSearch?wsdl"; URL url = new URL(wsdlUrl); // 通过URL类的构造方法传入wsdlUrl地址创建URL对象 // 2.创建服务方法的调用者对象call,设置call对象的属性 Call call = (Call) service.createCall(); call.setTargetEndpointAddress(url); // 给call对象设置请求的URL属性 // String serviceName = "getFile"; // 文件标题、申请单位、办结时间(|分割,注意顺序),用null判断是否存在 String serviceName = "getWord"; // 只有内网用 call.setOperationName(serviceName); // 给call对象设置调用方法名属性 // 办文编号 参数 call.addParameter("bwbh", XMLType.XSD_STRING, ParameterMode.IN); // 给call对象设置方法的参数名、参数类型、参数模式 call.setReturnType(XMLType.XSD_STRING); // 设置调用方法的返回值类型 // 执行接口方法 // String i = (String)call.invoke(new Object[] {bwbh}) ; String i = (String) call.invoke(new Object[] {bwbh}); System.out.println("test.main()-->" + i); if (i != null) { byte[] b = new sun.misc.BASE64Decoder().decodeBuffer(i); } } catch (Exception e) { e.printStackTrace(); } }
public Object accessWGService( WebSession s, String serv, int port, String proc, String parameterName, Object parameterValue) { String targetNamespace = "WebGoat"; try { QName serviceName = new QName(targetNamespace, serv); QName operationName = new QName(targetNamespace, proc); Service service = new Service(); Call call = (Call) service.createCall(); call.setOperationName(operationName); call.addParameter(parameterName, serviceName, ParameterMode.INOUT); call.setReturnType(XMLType.XSD_STRING); call.setUsername("guest"); call.setPassword("guest"); call.setTargetEndpointAddress( "http://localhost:" + port + "/" + s.getRequest().getContextPath() + "/services/" + serv); Object result = call.invoke(new Object[] {parameterValue}); return result; } catch (RemoteException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
public static Float getQuote(String ticker, String username, String password) throws javax.xml.rpc.ServiceException, AxisFault { Float res = new Float(-1.0); Service service = new Service(new XMLStringProvider(wsdd)); // create a new Call object Call call = (Call) service.createCall(); call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "getQuote")); call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_FLOAT); try { java.net.URL jmsurl = new java.net.URL(sampleJmsUrl); call.setTargetEndpointAddress(jmsurl); // set additional params on the call if desired call.setUsername(username); call.setPassword(password); call.setTimeout(new Integer(30000)); res = (Float) call.invoke(new Object[] {ticker}); } catch (java.net.MalformedURLException e) { throw new AxisFault("Invalid JMS URL", e); } catch (java.rmi.RemoteException e) { throw new AxisFault("Failed in getQuote()", e); } return res; }
public String invoke(Object[] obj) throws Exception { String endpointURL = "http://localhost:5148/WebServer/services/receiveMediumAndLongTermOperationModeCountersignInfomationTest"; String nameSpaceURL = "http://oms.gd.soa.csg.cn"; String soapActionURL = "http://schemas.xmlsoap.org/wsdl/soap/"; String remoteMethod = "receiveMediumAndLongTermOperationModeCountersignInfomationTest"; String id = ""; Service service = new Service(); Call call = (Call) service.createCall(); call.addParameter( new QName( nameSpaceURL, "receiveMediumAndLongTermOperationModeCountersignInfomationTestRequest"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA); call.setUseSOAPAction(true); call.setSOAPActionURI(soapActionURL); call.setTargetEndpointAddress(new java.net.URL(endpointURL).toString()); QName qname = new QName(nameSpaceURL, remoteMethod); call.setOperationName(qname); Schema schema = (Schema) call.invoke(obj); String res = schema.get_any()[1].getAsString(); return res; }
public String scheduleReport(ScheduleRequest scheduleRequest, String userID, String userPassword) throws ReportException { try { initOperation(); QName scheduleReq = new QName(BIP_NAMESPACE, "ScheduleRequest"); // Default return type based on what we expect call.setOperationName(new QName(BIP_NAMESPACE, "scheduleReport")); call.addParameter("ScheduleRequest", scheduleReq, ParameterMode.IN); call.addParameter("userID", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_STRING); // Define only email delivery // DeliveryRequest delivery = new DeliveryRequest(email, null, null, null, null, null); // issue the request String result = (String) call.invoke(new Object[] {scheduleRequest, userID, userPassword}); return result; } catch (RemoteException e) { ReportException reportException = new ReportException(e); throw reportException; } }
public static String request( String operation, String namespace, String parameter, String uri, String arg) throws ServiceException, RemoteException { Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(endPoint); call.setOperationName(new QName(namespace, operation)); // WSDL里面描述的接口名称 call.addParameter(parameter, XMLType.SOAP_STRING, ParameterMode.IN); // 接口的参数 call.setReturnType(XMLType.SOAP_STRING); // 设置返回类型 call.setSOAPActionURI(uri); String result = (String) call.invoke(new Object[] {arg}); return result; }
/** * Main entry point. Tests a variety of echo methods and reports on their results. * * <p>Arguments are of the form: -h localhost -p 8080 -s /soap/servlet/rpcrouter */ public static void main(String args[]) throws Exception { // set up the call object Options opts = new Options(args); service = new Service(); call = (Call) service.createCall(); call.setTargetEndpointAddress(new URL(opts.getURL())); call.setUseSOAPAction(true); call.setSOAPActionURI("http://www.soapinterop.org/Bid"); // register the PurchaseOrder class QName poqn = new QName("http://www.soapinterop.org/Bid", "PurchaseOrder"); Class cls = PurchaseOrder.class; call.registerTypeMapping(cls, poqn, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the Address class QName aqn = new QName("http://www.soapinterop.org/Bid", "Address"); cls = Address.class; call.registerTypeMapping(cls, aqn, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the LineItem class QName liqn = new QName("http://www.soapinterop.org/Bid", "LineItem"); cls = LineItem.class; call.registerTypeMapping(cls, liqn, BeanSerializerFactory.class, BeanDeserializerFactory.class); try { // Default return type based on what we expect call.setOperationName(new QName("http://www.soapinterop.org/Bid", "Buy")); call.addParameter("PO", poqn, ParameterMode.IN); call.setReturnType(XMLType.XSD_STRING); LineItem[] li = new LineItem[2]; li[0] = new LineItem("Tricorder", 1, "2500.95"); li[1] = new LineItem("Phasor", 3, "7250.95"); PurchaseOrder po = new PurchaseOrder( "NCC-1701", Calendar.getInstance(), new Address("Sam Ruby", "Home", "Raleigh", "NC", "27676"), new Address("Lou Gerstner", "Work", "Armonk", "NY", "15222"), li); // issue the request String receipt = (String) call.invoke(new Object[] {po}); System.out.println(receipt); } catch (Exception e) { System.out.println("Buy failed: " + e); throw e; } }
public boolean hasReportServerAccess(String userID, String userPassword) throws ReportException { try { initOperation(); call.setOperationName(new QName(BIP_NAMESPACE, "validateLogin")); call.addParameter("userID", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_BOOLEAN); // issue the request Boolean hasAccess = (Boolean) call.invoke(new Object[] {userID, userPassword}); return hasAccess; } catch (RemoteException e) { ReportException reportException = new ReportException(e); throw reportException; } }
/** * @see RepositoryWfsClient#deleteRepositoryItem(hu.sztaki.lpds.wfs.com.RepositoryWorkflowBean) */ @Override public String deleteRepositoryItem(RepositoryWorkflowBean bean) { String ret = new String(""); try { Service service; Call call; QName qn; service = new Service(); call = (Call) service.createCall(); call.setTargetEndpointAddress(serviceURL + serviceID); call.setOperationName("deleteRepositoryItem"); qn = new QName("urn:BeanService", "RepositoryWorkflowBean"); call.registerTypeMapping( RepositoryWorkflowBean.class, qn, new BeanSerializerFactory(RepositoryWorkflowBean.class, qn), new BeanDeserializerFactory(RepositoryWorkflowBean.class, qn)); call.addParameter("arg1", qn, ParameterMode.IN); call.setReturnType(Constants.XSD_STRING); ret = (String) call.invoke(new Object[] {bean}); if (ret == null) { ret = new String("Not valid response ! ret = (" + ret + ")"); } return ret; } catch (Exception fault) { System.out.println("HIBA" + fault.toString()); fault.printStackTrace(); } return ret; }
public static String SendSMS(String[] mobileNum, int msgId, String msg) { Service service = new Service(); String ret = "-1"; String uc = Const.HWWebServiceUser; try { Call call = (Call) service.createCall(); call.setTargetEndpointAddress(Const.HWWebServiceRegisterURL); call.setOperationName("getRandom"); call.setReturnType(XMLType.XSD_STRING); call.getMessageContext().setUsername("test"); call.getMessageContext().setPassword("test"); ret = (String) call.invoke(new Object[0]); log.info("random= " + ret); String rand = ret; String pw = Md5.MD5(rand + Const.HWWebServiceUserPasswd + Const.HWWebServiceUserPasswd); call = (Call) service.createCall(); call.setTargetEndpointAddress(new URL(Const.HWWebServiceRegisterURL)); call.setOperationName("setCallBackAddr"); call.addParameter("uc", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("pw", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("rand", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("url", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_STRING); call.getMessageContext().setUsername("test"); call.getMessageContext().setPassword("test"); String myUrl = Const.CallBackURL; ret = (String) call.invoke(new Object[] {uc, pw, rand, myUrl}); log.info("connId:" + ret); String connId = ret; call = (Call) service.createCall(); call.setTargetEndpointAddress(Const.HWWebServiceRegisterURL); call.setOperationName("getRandom"); call.setReturnType(XMLType.XSD_STRING); call.getMessageContext().setUsername("test"); call.getMessageContext().setPassword("test"); ret = (String) call.invoke(new Object[0]); log.info("random:" + ret); rand = ret; pw = Md5.MD5(rand + Const.HWWebServiceUserPasswd + Const.HWWebServiceUserPasswd); call = (Call) service.createCall(); call.setTargetEndpointAddress(new URL(Const.HWWebServiceSMSURL)); call.setOperationName("sendSMS"); call.addParameter("uc", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("pw", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("rand", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("callee", XMLType.XSD_ANYTYPE, ParameterMode.IN); call.addParameter("isreturn", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("cont", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("msgid", XMLType.XSD_INTEGER, ParameterMode.IN); call.addParameter("connID", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_STRING); call.getMessageContext().setUsername("test"); call.getMessageContext().setPassword("test"); msg = new BASE64Encoder().encode(msg.getBytes("gb2312")); log.info("msg:" + msg); log.info("MSGID:" + msgId); ret = (String) call.invoke( new Object[] {uc, pw, rand, mobileNum, "1", msg, Integer.valueOf(msgId), connId}); log.info("status:" + ret); } catch (Exception e) { e.printStackTrace(); } return ret; }
public boolean enviarSMS( String numero_celular, String compania, String codigo_cliente, String codigo_mensaje, String fecha, String mensaje) { String endpoint = SantanderConstantesService.SERVICIO_MAIL; Service service = new Service(); org.apache.log4j.Logger.getLogger(this.getClass()).debug("SE intenta mandar mensaje"); // Variables medir tiempo long tiempoInicio = 0; long tiempoFin = 0; long tiempoTotal = 0; try { Call call = (Call) service.createCall(); // Se establece el tiempo de espera call.setTimeout(timeoutws); // Call cal2 = (Call) service.createCall(); // Establecemos la dirección en la que está activado el WebService call.setTargetEndpointAddress(new java.net.URL(endpoint)); // Establecemos el nombre del método a invocar call.setOperationName("enviarMensaje"); // Establecemos los parámetros que necesita el método // Observe que se deben especidicar correctamente tanto el nómbre como el tipo de datos.. // esta información se puede obtener viendo el WSDL del servicio Web call.addParameter("st0", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("st1", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("st2", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("st3", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("st4", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("st5", XMLType.XSD_STRING, ParameterMode.IN); // Especificamos el tipo de datos que devuelve el método. call.setReturnType(XMLType.XSD_STRING); /** VAOJ 17-05-2005 Informar tiempo de respuesta del webservice INICIO */ // calcular tiempo inicio org.apache.log4j.Logger.getLogger(this.getClass()) .debug("WSCliente_SMS::Incio -> " + new Date()); tiempoInicio = System.currentTimeMillis(); // Invocamos el método org.apache.log4j.Logger.getLogger(this.getClass()) .debug( "invoca con:" + numero_celular + "," + compania.trim() + "," + codigo_cliente + "," + codigo_mensaje + "," + fecha + "," + mensaje); String result1 = (String) call.invoke( new Object[] { numero_celular, compania.trim(), codigo_cliente, codigo_mensaje, fecha, mensaje }); // Calcular tiempo fin org.apache.log4j.Logger.getLogger(this.getClass()) .debug("WSCliente_SMS::Fin -> " + new Date()); tiempoFin = System.currentTimeMillis(); tiempoTotal = tiempoFin - tiempoInicio; org.apache.log4j.Logger.getLogger(this.getClass()) .debug("WSCliente_SMS::Diferencia(Milis) -> " + tiempoTotal); org.apache.log4j.Logger.getLogger(this.getClass()).debug("Respuesta = " + result1); // Imprimimos los resultados org.apache.log4j.Logger.getLogger(this.getClass()) .debug("El mensaje fue enviado Al parecer."); } catch (Exception e) { org.apache.log4j.Logger.getLogger(this.getClass()) .debug( "invoca con:" + numero_celular + "," + compania + "," + codigo_cliente + "," + codigo_mensaje + "," + fecha + "," + mensaje); org.apache.log4j.Logger.getLogger(this.getClass()).debug("El mensaje no se envio.", e); tiempoFin = System.currentTimeMillis(); tiempoTotal = tiempoFin - tiempoInicio; org.apache.log4j.Logger.getLogger(this.getClass()) .debug("WSPreguntasSecretas::Excepcion::Diferencia(Milis)-> " + tiempoTotal); e.printStackTrace(); } return false; }