⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validate_values.java

📁 OpenWeb-UDDI是UDDI V2标准的实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				System.out.println("validateKeyReference 1");
				if(!rs1.next()){
					rs1.close();
					stmt1.close();
					System.out.println("validateKeyReference 12");
					continue;
				}
		
				System.out.println("validateKeyReference 2");
				//先去valid_values中检查
				String query2="select * from valid_values where tModelKey='"+standardkey +"'and keyValue='"+keyvalue+"'";
				stmt1 = con.createStatement();
				ResultSet rs2 = stmt1.executeQuery(query2);
				boolean t=rs2.next();
				if(t){
					System.out.println("true");
					rs2.close();
					stmt1.close();
					continue;
				}else{
					System.out.println("false");
					rs2.close();
					stmt1.close();
					valid=false;
				}
				
				if(!valid){
					return valid;
				}
				
				System.out.println("validateKeyReference 3");
				//以下就会调用外部的验证服务了。
				String query = "select * from Valid_Services where tModelKeyforValid_Service='" + standardkey + "'";
				System.out.println(query);
				stmt1=con.createStatement();
				ResultSet rs = stmt1.executeQuery(query);
				if(rs.next()){
					String servicePort="";
					servicePort=getServicePort(rs.getString("accesspoint"),rs.getString("hostingRedirector"));
					String wsdlURL=rs.getString("tModelKeyforWSDL");
					resp=invokeValidService(servicePort,wsdlURL,rs.getString("servicetype"),keyname,keyvalue,obj);
					if(resp.getClass().getName().equals("org.huihoo.openweb.uddi.DispositionReport")){
						valid=false;
					}
				}
				if(!valid){
					rs.close();
					stmt1.close();
					return valid;
				}
				rs.close();
				stmt1.close();
			}	
		}catch(SQLException e){
		}
//		Statement stmt1;
//		boolean valid=true;
//		UddiObject resp=null;
//		for(; keyedref.hasMoreElements(); stmt1.close())
//		{
//			KeyedReference keyedreference = (KeyedReference)keyedref.nextElement();
//			String keyname = "";
//			if(keyedreference.getKeyName() != null)
//				keyname = keyedreference.getKeyName();
//			String keyvalue = "";
//			if(keyedreference.getKeyValue() != null)
//				keyvalue = keyedreference.getKeyValue();
//			String standardkey = "";
//			if(keyedreference.getTModelKey().getValue() != null)
//				standardkey = keyedreference.getTModelKey().getValue();
//			stmt1 = con.createStatement();
//			String query = "select * from Valid_Services where tModelKeyforValid_Service='" + standardkey + "'";
//			System.out.println(query);
//			ResultSet rs = stmt1.executeQuery(query);
//			if(rs.next()){
//				String servicePort="";
//				servicePort=getServicePort(rs.getString("accesspoint"),rs.getString("hostingRedirector"));
////				String servicePort=rs.getString("accesspoint");
////				if(servicePort==""){
////					servicePort=rs.getString("hostingRedirector");
////				}
//				String wsdlURL=rs.getString("tModelKeyforWSDL");
//				resp=invokeValidService(servicePort,wsdlURL,rs.getString("servicetype"),keyname,keyvalue,obj);
//				if(resp.getClass().getName().equals("org.huihoo.openweb.uddi.DispositionReport")){
//					valid=false;
//				}
//			}
//			if(!valid){
//				rs.close();
//				stmt1.close();
//				return valid;
//			}
//			rs.close();
//			stmt1.close();
//		}	
		return true;
	}
	
	private static UddiObject invokeValidService(String servicePort,String wsdlURL,String serviectype,
		String keyName,String keyValue,UddiObject obj)
//		throws WSDLException,MalformedURLException,IOException,
//		ServiceException,RemoteException
		{
		//sentDoc
		Document sentDoc=getSendDocment(obj);
		Definition def=getWSDLDefinition(null,wsdlURL);
		String nameSpaceURI=def.getTargetNamespace();//目标命名空间
		Object[] portTypes=def.getPortTypes().entrySet().toArray();
		PortType pt=(PortType)portTypes[0];
		//serviceQName
		QName serviceQName=pt.getQName();
		//portType
		String portType=serviceQName.getLocalPart();
		Object[] operations=pt.getOperations().toArray();
		Operation op=(Operation)operations[0];
		//operation
		String operation = op.getName();
		
		//soapAction
		String soapAction="";
		Object[] bingdings=def.getBindings().entrySet().toArray();
		Binding binding=(Binding)bingdings[0];
		BindingOperation bindingOp=(BindingOperation)binding.getBindingOperations().get(0);
		Iterator extElements = bindingOp.getExtensibilityElements().iterator();
		for(;extElements.hasNext();){
			Element el=(Element)extElements.next();
			String name=el.getNodeName();
			if(name.endsWith(":operation")){
				soapAction=el.getAttribute("soapAction");
			}
		}
		//wsdlDesc
  		InputStream wsdlDesc=null;
		try{
			URL url = new URL( wsdlURL );
			wsdlDesc = new BufferedInputStream(url.openStream());
		}catch (MalformedURLException e){
			
		}catch (IOException e){
			
		}
		
		Document resp=sendMessage(nameSpaceURI, serviceQName,portType,operation,null,wsdlDesc,sentDoc);
		Element element=resp.getDocumentElement();
		DispositionReport response=new DispositionReport(new UddiObject(element));
		return response;
//		Enumeration result=response.getResult();
//		Result r=(Result)result.nextElement();
//		if(r.getAttribute("errno").equals("0")){
//			return true;
//		}else {
//			return false;
//		}
	}
	
	private static org.w3c.dom.Document sendMessage(String nameSpaceURI, QName serviceQName, String portType,
		String operation, String soapAction, InputStream wsdlDesc,
		org.w3c.dom.Document sentDoc) {
		
		org.apache.axis.client.Service service=null;
		try{
			service = new org.apache.axis.client.Service(wsdlDesc, serviceQName);
		}catch(ServiceException e){
			
		}

		//org.apache.axis.client.Service service = new org.apache.axis.client.Service();//modify
		QName portQName = new QName(nameSpaceURI, portType);
		Call call=null;
		try{
			call = (Call)service.createCall(portQName, operation);
		}catch(ServiceException e){
			
		}

	
		//call.setTargetEndpointAddress();
		call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
		if (soapAction != null) call.setProperty(Call.SOAPACTION_URI_PROPERTY, soapAction);
	
		org.apache.axis.message.SOAPBodyElement[] input = new org.apache.axis.message.SOAPBodyElement[1];
		input[0] = new org.apache.axis.message.SOAPBodyElement(sentDoc.getDocumentElement());
		Vector results=null;
		try{
			results = (Vector) call.invoke(input);
		}catch(RemoteException e){
			
		}

	
		org.w3c.dom.Document result = null;
		try {
			result = ((org.apache.axis.message.SOAPBodyElement) results.get(0)).getAsDocument();
		} catch (ServiceException e) {
			
		}catch(Exception e){
			
		}
		return result;
	}
	
	private static org.w3c.dom.Document getSendDocment(UddiObject obj){
		Document sentdoc=DocBuilder.getNewDocument();
		
		Node node = sentdoc.createElement("validate_values");
		((Element)node).setAttribute("generic","2.0");
		((Element)node).setAttribute("xmlns","urn:uddi-org:api-v2");
		if(obj instanceof BusinessEntity){
			((Element)node).appendChild(((BusinessEntity)obj).getElement());
		}else if(obj instanceof BusinessService){
			((Element)node).appendChild(((BusinessService)obj).getElement());
		}else if(obj instanceof TModel){
			((Element)node).appendChild(((TModel)obj).getElement());
		}
		sentdoc.appendChild(node);
		
		return sentdoc;
	}
	
	private static Definition getWSDLDefinition(String contextURL, String wsdlLoc){
		try {
			WSDLFactory factory = WSDLFactory.newInstance();
			WSDLReader wsdlReader = factory.newWSDLReader();

			Definition def = wsdlReader.readWSDL(contextURL, wsdlLoc);
			return def;
		} catch (WSDLException e) {
			return null;
		}
	}
	
	private static String getServicePort(String accesspoint,String hostingRedirector){
		if(accesspoint!=""){
			return accesspoint;
		}else{
			String query="select * from BindingTemplate where bindingkey = '"+hostingRedirector+"'";
			try{
				Statement stmt = con.createStatement();
				ResultSet rs=stmt.executeQuery(query);
				if(rs.next()){
					String access=rs.getString("accesspoint");
					String hosting=rs.getString("hostingRedirector");
					rs.close();
					stmt.close();
					return getServicePort(access,hosting);
				}
			}catch(SQLException e){
				
			}
		return "";
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -