/* * 短信发送接口 */ public String invokeRemoteFuc(String username, String mobile, String content, String uuid) { String endpoint = "http://10.1.5.244:8989/smsWebservice/services/smsMsg?wsdl"; String result = "no result!"; Service service = new Service(); Call call; try { call = (Call) service.createCall(); call.setTargetEndpointAddress(endpoint); // 远程调用路径 call.setOperationName("SendMsg"); // 调用的方法名 // // // 设置参数名: // call.addParameter("username", // 参数名 // XMLType.XSD_STRING,// 参数类型:String // ParameterMode.IN);// 参数模式:'IN' or 'OUT' // call.addParameter("mobile", XMLType.XSD_STRING, ParameterMode.IN); // call.addParameter("content", XMLType.XSD_STRING, ParameterMode.IN); // call.addParameter("uuid", XMLType.XSD_STRING, ParameterMode.IN); // // 设置返回值类型: // call.setReturnType(XMLType.XSD_STRING);// 返回值类型:String result = (String) call.invoke(new Object[] {username, mobile, content, uuid}); // 远程调用 } catch (ServiceException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } return result; }
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 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 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 static void main(String[] args) { try { String fileName = "/log4j.properties"; DataHandler dh = new DataHandler( new FileDataSource(FileSenderClient.class.getResource(fileName).getPath())); String url = "http://127.0.0.1:8080/axis1/services/FileReceiverServer"; Service serv = new Service(); Call call = (Call) serv.createCall(); call.setTargetEndpointAddress(url); call.setOperationName(new QName(url, "receive")); QName qn = new QName("DataHandler", "myNs:DataHandler"); call.registerTypeMapping( DataHandler.class, qn, JAFDataHandlerSerializerFactory.class, JAFDataHandlerDeserializerFactory.class); call.addParameter("s1", qn, ParameterMode.IN); call.addParameter("s2", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnClass(String.class); String returnStr = (String) call.invoke(new Object[] {dh, "server.txt"}); System.out.println("Server response: " + returnStr); } catch (ServiceException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } }
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 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; } }
/*参数 uuid : Sendmsg 输入的 uuid * 查询用户短信状态报告 * 返回值说明 :0:失败,1:成功 */ public int GetRes(String uuid) { String endpoint = "http://10.1.5.244:8989/smsWebservice/services/smsMsg?wsdl"; int result = 2; Service service = new Service(); Call call; try { call = (Call) service.createCall(); call.setTargetEndpointAddress(endpoint); // 远程调用路径 call.setOperationName("GetRes"); // 调用的方法名 result = (int) call.invoke(new Object[] {uuid}); // 远程调用 } catch (ServiceException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } return result; }
public static Document loadSiteList2(String session, String sakaiHost) { String endpoint; String siteList = null; Service service = null; Call call = null; String axisPoint = sakaiHost + "/sakai-axis/"; try { debugPrint("Retrieving Sites=" + session + " host=" + sakaiHost); // Retrieve Site List service = new Service(); call = (Call) service.createCall(); endpoint = axisPoint + "SakaiSite.jws"; debugPrint("Site Retrieval " + endpoint + " session=" + session); call.setTargetEndpointAddress(new java.net.URL(endpoint)); call.setOperationName("getToolsDom"); siteList = (String) call.invoke(new Object[] {session, "", new Integer(1), new Integer(9999)}); debugPrint(siteList); Document doc = Xml.readDocumentFromString(siteList); NodeList children = doc.getElementsByTagName("site"); debugPrint("There are " + children.getLength() + " child elements.\n"); if (children.getLength() < 1) { // pSession.setAttribute("error", "No sites available to you on " + sakaiHost); return null; } return doc; } catch (Exception e) { System.out.println("Exception:" + e.toString()); return null; } }
/** * @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; }
/** * This method is called when 'Finish' button is pressed in the wizard. We will create an * operation and run it using wizard as execution context. */ public boolean performFinish() { try { Options opts = new Options(new String[0]); opts.setDefaultURL(serverPage.getSelectedServer() + "/services/NMRShiftDB"); Service service = new Service(); Call call = (Call) service.createCall(); call.setOperationName("doSearch"); call.setTargetEndpointAddress(new URL(opts.getURL())); DocumentBuilder builder; builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); SOAPBodyElement[] input = new SOAPBodyElement[1]; Document doc = builder.newDocument(); Element cdataElem; cdataElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "doSearch"); Element reqElem; reqElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchstring"); /*DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Node node = db.parse(new ByteArrayInputStream(new Convertor(true,"").cdkAtomContainerToCMLMolecule(ac).toXML().getBytes()));*/ Node node = DOMConverter.convert( new nu.xom.Document(new Convertor(true, "").cdkAtomContainerToCMLMolecule(ac)), builder.getDOMImplementation()) .getFirstChild(); reqElem.appendChild(doc.importNode(node, true)); Element reqElem2; reqElem2 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchtype"); Node node2; node2 = doc.createTextNode("--"); reqElem2.appendChild(node2); Element reqElem3; reqElem3 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchfield"); Node node3; node3 = doc.createTextNode(NmrshiftdbUtils.replaceSpaces(serverPage.selectedOption())); reqElem3.appendChild(node3); cdataElem.appendChild(reqElem); cdataElem.appendChild(reqElem2); cdataElem.appendChild(reqElem3); input[0] = new SOAPBodyElement(cdataElem); Vector elems = (Vector) call.invoke(input); SOAPBodyElement elem = (SOAPBodyElement) elems.get(0); Element e = elem.getAsDOM(); CMLBuilder cmlbuilder = new CMLBuilder(); CMLElement cmlElement = (CMLElement) cmlbuilder.parseString(XMLUtils.ElementToString(e)); if (cmlElement.getChildCount() > 0) { IFolder folder = NmrshiftdbUtils.createVirtualFolder(); for (int i = 0; i < cmlElement.getChildCount(); i++) { net.bioclipse.specmol.Activator.getDefault() .getJavaSpecmolManager() .saveSpecmol( new JumboSpecmol((CMLCml) cmlElement.getChildCMLElements().get(i)), folder.getFile( ((CMLMolecule) cmlElement .getChildCMLElements() .get(i) .getChildCMLElement("molecule", 0)) .getId() + "." + SpectrumEditor.CML_TYPE)); } } else { MessageDialog.openInformation( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "No results", "No spectra in NMRShiftDB for this structure!"); } } catch (Exception ex) { LogUtils.handleException(ex, logger); } return true; }
public static String establishSession( String session, String sakaiHost, String sakaiId, String sakaiPw, String firstName, String lastName, String email, boolean doAuto) { String endpoint; String siteList = null; Service service = null; Call call = null; String axisPoint = sakaiHost + "/sakai-axis/"; debugPrint( "loadSiteList host=" + sakaiHost + " id=" + sakaiId + " pw=" + sakaiPw + " auto=" + doAuto); try { // Make sure this session is still active and alive - if for any reason we cannot validate // Including a pre-revision 14063 SakaiSession.jws, we just whack the session. try { if (session != null) { service = new Service(); call = (Call) service.createCall(); endpoint = axisPoint + "SakaiSession.jws"; debugPrint("Checking session" + endpoint); call.setOperationName("getSessionUser"); call.setTargetEndpointAddress(new java.net.URL(endpoint)); String sessionUser = (String) call.invoke(new Object[] {session}); if (!sakaiId.equals(sessionUser)) { debugPrint("Session user="******" does not match id=" + sakaiId); session = null; } } } catch (Exception e) { // We really, literally, absolutely do not care why this failed session = null; } // Must establish or have a session - Someday might want to validate session // each time over web services before simply accepting it. if (session == null) { service = new Service(); call = (Call) service.createCall(); // HACK FOR DEMO if ("tomcat".equals(sakaiId) && firstName == null) { firstName = "Tom"; lastName = "Cat"; email = "*****@*****.**"; } System.out.println( "firstname=" + firstName + ", lastName=" + lastName + ", email=" + email); if (doAuto && email != null && firstName != null && lastName != null) { endpoint = axisPoint + "SakaiPortalLogin.jws"; debugPrint("Portal Login and Create " + endpoint + " id=" + sakaiId + " pw=" + sakaiPw); call.setOperationName("loginAndCreate"); call.setTargetEndpointAddress(new java.net.URL(endpoint)); session = (String) call.invoke(new Object[] {sakaiId, sakaiPw, firstName, lastName, email}); } else if (doAuto) { endpoint = axisPoint + "SakaiPortalLogin.jws"; debugPrint("Portal Login " + endpoint + " id=" + sakaiId + " pw=" + sakaiPw); call.setOperationName("login"); call.setTargetEndpointAddress(new java.net.URL(endpoint)); session = (String) call.invoke(new Object[] {sakaiId, sakaiPw}); } else { endpoint = axisPoint + "SakaiLogin.jws"; debugPrint("Web Services Login " + endpoint + " id=" + sakaiId + " pw=" + sakaiPw); call.setOperationName("login"); call.setTargetEndpointAddress(new java.net.URL(endpoint)); session = (String) call.invoke(new Object[] {sakaiId, sakaiPw}); } } // End establishing Session return session; } catch (Exception e) { System.out.println("Exception:" + e.toString()); return null; } }
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; }
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String index = request.getParameter("index"); String query = request.getParameter("query"); String hits = request.getParameter("maxHits"); String field = request.getParameter("field"); String button = request.getParameter("button"); String[] fieldList = {"Error"}; String retXML; PrintWriter out = response.getWriter(); service = new Service(); try { call = (Call) service.createCall(); } catch (ServiceException e) { log.severe(e.toString()); } if (button != null) { response.setContentType("text/xml;charset=UTF-8"); try { call.setTargetEndpointAddress(endpoint + "SearcherWS"); call.setOperationName("search"); retXML = (String) call.invoke(new Object[] {index, query, hits, field}); out.println(retXML); } catch (RemoteException e) { log.severe("RemoteException: " + e.toString()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); log.severe(sw.toString()); } } else { File indexDir = new File("/scratch/emeij/indexes/"); File listIndexes[] = indexDir.listFiles(); Directory baselineIndex = FSDirectory.open(new File("/scratch/emeij/indexes/" + "baseline")); reader = DirectoryReader.open(baselineIndex); response.setContentType("text/html;charset=UTF-8"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet LuceneServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>LuceneServletAdvanced</h1>"); out.println("<form name=\"QCK\" method=\"get\">"); out.println("index:"); out.println("<br>"); out.println("<select name=\"index\" onchange=\"QCK.submit()\">"); out.println("<option value=\"baseline\">" + "Choose an index" + "</option>"); for (int k = 0; k < listIndexes.length; ++k) { Directory dir = FSDirectory.open(listIndexes[k]); if (DirectoryReader.indexExists(dir)) { if (index == null || !index.equals(listIndexes[k].getName())) { out.println("<option>" + listIndexes[k].getName() + "</option>"); } else { out.println("<option SELECTED>" + listIndexes[k].getName() + "</option>"); } } } out.println("</select>"); out.println("<br><br>"); try { out.println("Search field:<br>"); out.println("<select name=\"field\">"); if (index != null) { try { call.setTargetEndpointAddress(endpoint + "getFields"); call.setOperationName("listFields"); fieldList = (String[]) call.invoke(new Object[] {index}); } catch (Exception e) { log.info(e.toString()); } for (int k = 1; k < fieldList.length; ++k) { out.println("<option>" + fieldList[k] + "</option>"); // out.println("<b>" + fieldList[k] + "</b>, "); } } out.println("</select>"); out.println("<br><br>"); } catch (Exception e) { log.severe("LuceneClientServletAdvancedError: " + e.getMessage()); } out.println("query:"); out.println("<br>"); out.println("<input type=\"text\" name=\"query\" size=\"25\" value=\"\">"); out.println("<br><br>"); out.println("maxHits:"); out.println("<br>"); out.println("<input type=\"text\" name=\"maxHits\" size=\"5\" value=\"10\">"); out.println("<br><br>"); out.println("<input type=\"submit\" value=\"Submit\" name=\"button\">"); out.println("</form>"); out.println("</body>"); out.println("</html>"); } }
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String[] retArray = {""}; String ret = ""; String[] methodArray = { "getSynonyms", "listSynonyms", "listSynonymsXML", "updateSynonyms", "addSynonym", "deleteSynonym" }; String root = request.getContextPath(); String index = request.getParameter("index"); String term = request.getParameter("term"); String synonym = request.getParameter("synonym"); String button = request.getParameter("button"); String method = request.getParameter("method"); if (term == null) term = ""; if (synonym == null) synonym = ""; // Call XML service, special case if (button != null && method != null && method.equalsIgnoreCase("listSynonymsXML")) { response.setContentType("text/xml;charset=UTF-8"); PrintWriter writer = response.getWriter(); try { service = new Service(); call = (Call) service.createCall(); call.setTargetEndpointAddress(endpoint); call.setOperationName(method); ret = (String) call.invoke(new Object[] {index}); writer.println(ret); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.close(); log.severe(sw.toString()); } } else { // Print entry page log.fine("Checking for env. var. INDEXDIR"); if (indexLocation == null) { log.severe("***INDEXDIR not found!!!***"); indexLocation = ""; } else { log.fine("Found INDEXDIR: " + indexLocation); } File indexDir = new File(indexLocation); File listIndexes[] = indexDir.listFiles(); response.setContentType("text/html;charset=UTF-8"); PrintWriter writer = response.getWriter(); writer.println("<html>"); writer.println("<head>"); writer.println("<title>Synonym Webservice</title>"); writer.println("</head>"); writer.println("<body bgcolor=white>"); writer.println("<table border=\"0\">"); writer.println("<tr>"); writer.println("<td>"); writer.println("<img src=\"" + root + "/images/vlelogo.png\">"); writer.println("</td>"); writer.println("<td>"); writer.println("<h1>Synonym Webservice</h1>"); writer.println("</td>"); writer.println("</tr>"); writer.println("</table>"); writer.println("<table border=\"0\" width=\"100%\">"); writer.println("<form name=\"SynonymClientForm\" method=\"get\">"); writer.println("<tr>"); writer.println(" <td>Index:<br/>"); writer.println(" <select name=\"index\">"); writer.println(" <option value=\"QCK\"" + "> Choose an index" + "</option>"); for (int k = 0; k < listIndexes.length; ++k) { Directory dir = FSDirectory.open(listIndexes[k]); if (DirectoryReader.indexExists(dir)) { if (index == null || !index.equals(listIndexes[k].getName())) { writer.println( " <option id=index\"" + k + "\"><label for=\"index" + k + "\">" + listIndexes[k].getName() + "</label></option>"); } else { writer.println(" <option SELECTED>" + listIndexes[k].getName() + "</option>"); } } } writer.println(" </select>"); writer.println(" </td>"); writer.println("</tr>"); writer.println("<tr>"); writer.println(" <td>"); writer.println("action:<br>"); writer.println(" <select name=\"method\" onchange=\"SynonymClientForm.submit()\">"); writer.println("<option value=\"listSynonymsXML\">" + "Choose an action" + "</option>"); for (int k = 0; k < methodArray.length; ++k) { if (method == null || !method.equals(methodArray[k])) { writer.println("<option>" + methodArray[k] + "</option>"); } else { writer.println("<option SELECTED>" + methodArray[k] + "</option>"); } } writer.println(" </select>"); writer.println(" </td>"); writer.println("</tr>"); writer.println("<tr>"); writer.println(" <td>"); writer.println("Term:"); writer.println("<br>"); if (method == null) { writer.println("<input type=\"text\" name=\"term\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("addSynonym")) { writer.println( "<input type=\"text\" name=\"term\" " + "size=\"30\" value=\"" + term + "\">"); } else if (method.equalsIgnoreCase("deleteSynonym")) { writer.println( "<input type=\"text\" name=\"term\" " + "size=\"30\" value=\"" + term + "\">"); } else if (method.equalsIgnoreCase("updateSynonyms")) { writer.println("<input type=\"text\" name=\"term\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("listSynonyms")) { writer.println("<input type=\"text\" name=\"term\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("getSynonyms")) { writer.println( "<input type=\"text\" name=\"term\" " + "size=\"30\" value=\"" + term + "\">"); } else if (method.equalsIgnoreCase("listSynonymsXML")) { writer.println("<input type=\"text\" name=\"term\" " + "size=\"30\" value=\"\" DISABLED>"); } writer.println(" </td>"); writer.println("</tr>"); writer.println("<tr>"); writer.println(" <td>"); writer.println("Synonym:"); writer.println("<br>"); if (method == null) { writer.println( "<input type=\"text\" name=\"synonym\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("addSynonym")) { writer.println( "<input type=\"text\" name=\"synonym\" " + "size=\"30\" value=\"" + synonym + "\">"); } else if (method.equalsIgnoreCase("deleteSynonym")) { writer.println( "<input type=\"text\" name=\"synonym\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("updateSynonyms")) { writer.println( "<input type=\"text\" name=\"synonym\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("listSynonyms")) { writer.println( "<input type=\"text\" name=\"synonym\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("getSynonyms")) { writer.println( "<input type=\"text\" name=\"synonym\" " + "size=\"30\" value=\"\" DISABLED>"); } else if (method.equalsIgnoreCase("listSynonymsXML")) { writer.println( "<input type=\"text\" name=\"synonym\" " + "size=\"30\" value=\"\" DISABLED>"); } writer.println(" </td>"); writer.println("</tr>"); writer.println("<tr>"); writer.println(" <td>"); writer.println("<input type=\"submit\" value=\"Submit\" name=\"button\">"); writer.println(" </td>"); writer.println("</tr>"); writer.println("</form>"); writer.println("</table>"); writer.println("<br/> <br/>"); writer.println("<table border=\"0\" width=\"100%\">"); writer.println("<tr>"); writer.println(" <td colspan=\"2\">"); writer.println(" <b>Results</b>"); writer.println(" </td>"); writer.println("</tr>"); if (button != null) { try { service = new Service(); call = (Call) service.createCall(); call.setTargetEndpointAddress(endpoint); call.setOperationName(method); if (method.equalsIgnoreCase("addSynonym")) { ret = (String) call.invoke(new Object[] {index, term, synonym}); writer.println("<tr>"); writer.println(" <td colspan=\"2\">"); writer.println(ret); writer.println(" </td>"); writer.println("</tr>"); } else if (method.equalsIgnoreCase("deleteSynonym")) { ret = (String) call.invoke(new Object[] {index, term}); writer.println("<tr>"); writer.println(" <td colspan=\"2\">"); writer.println(ret); writer.println(" </td>"); writer.println("</tr>"); } else if (method.equalsIgnoreCase("updateSynonyms")) { ret = (String) call.invoke(new Object[] {index}); writer.println("<tr>"); writer.println(" <td colspan=\"2\">"); writer.println(ret); writer.println(" </td>"); writer.println("</tr>"); } else if (method.equalsIgnoreCase("listSynonyms")) { retArray = (String[]) call.invoke(new Object[] {index}); for (int j = 0; j < retArray.length; j++) { writer.println("<tr>"); writer.println(" <td colspan=\"2\">" + retArray[j] + "</td>"); writer.println("</tr>"); } } else if (method.equalsIgnoreCase("getSynonyms")) { retArray = (String[]) call.invoke(new Object[] {index, term}); for (int j = 0; j < retArray.length; j++) { writer.println("<tr>"); writer.println(" <td><b>" + term + ": </b></td>"); writer.println(" <td>" + retArray[j] + "</td>"); writer.println("</tr>"); } } } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.close(); log.severe(sw.toString()); } } writer.println("</table>"); writer.println("</body>"); writer.println("</html>"); } }
private void initCall() throws ReportException { try { // set up the call object Service service = new Service(); call = (Call) service.createCall(); call.setTargetEndpointAddress(new URL(webServiceEndPoint)); // Register type mappings // register the ItemData class QName itemData = new QName(BIP_NAMESPACE, "ItemData"); call.registerTypeMapping( ItemData.class, itemData, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the ParamNameValue class QName nmvals = new QName(BIP_NAMESPACE, "ParamNameValue"); call.registerTypeMapping( ParamNameValue.class, nmvals, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the ReportDefinition class QName reportDef = new QName(BIP_NAMESPACE, "ReportDefinition"); call.registerTypeMapping( ReportDefinition.class, reportDef, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the ReportRequest class QName reportReq = new QName(BIP_NAMESPACE, "ReportRequest"); call.registerTypeMapping( ReportRequest.class, reportReq, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the BIPReportResponse class QName reportRespqn = new QName(BIP_NAMESPACE, "ReportResponse"); call.registerTypeMapping( ReportResponse.class, reportRespqn, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the Schedule Request class QName scheduleReq = new QName(BIP_NAMESPACE, "ScheduleRequest"); call.registerTypeMapping( ScheduleRequest.class, scheduleReq, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the Delivery Request class QName deliveryReq = new QName(BIP_NAMESPACE, "DeliveryRequest"); call.registerTypeMapping( DeliveryRequest.class, deliveryReq, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the PrintDeliveryOption class QName printDeliveryOption = new QName(BIP_NAMESPACE, "PrintDeliveryOption"); call.registerTypeMapping( PrintDeliveryOption.class, printDeliveryOption, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the JobHistoryInfo class QName jobHistoryInfo = new QName(BIP_NAMESPACE, "JobHistoryInfo"); call.registerTypeMapping( JobHistoryInfo.class, jobHistoryInfo, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the JobInfo class QName jobInfo = new QName(BIP_NAMESPACE, "JobInfo"); call.registerTypeMapping( JobInfo.class, jobInfo, BeanSerializerFactory.class, BeanDeserializerFactory.class); // register the JobInfo class QName jobStatus = new QName(BIP_NAMESPACE, "JobStatus"); call.registerTypeMapping( JobStatus.class, jobStatus, BeanSerializerFactory.class, BeanDeserializerFactory.class); // TODO: Register new type mappings } catch (MalformedURLException e) { ReportException reportException = new ReportException(e); throw reportException; } catch (ServiceException e) { ReportException reportException = new ReportException(e); throw reportException; } }