Commit 2473230de8afe34798ed85982baaecb074efefc7
1 parent
cf74bb31
运管处路单上传BUG修改
Showing
1 changed file
with
42 additions
and
4 deletions
src/main/java/com/bsth/service/traffic/impl/YgcBasicDataServiceImpl.java
| @@ -7,6 +7,7 @@ import org.apache.axiom.om.*; | @@ -7,6 +7,7 @@ import org.apache.axiom.om.*; | ||
| 7 | import org.apache.axis2.addressing.EndpointReference; | 7 | import org.apache.axis2.addressing.EndpointReference; |
| 8 | import org.apache.axis2.client.Options; | 8 | import org.apache.axis2.client.Options; |
| 9 | import org.apache.axis2.client.ServiceClient; | 9 | import org.apache.axis2.client.ServiceClient; |
| 10 | +import org.apache.axis2.rpc.client.RPCServiceClient; | ||
| 10 | import org.apache.commons.codec.digest.DigestUtils; | 11 | import org.apache.commons.codec.digest.DigestUtils; |
| 11 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
| @@ -18,6 +19,7 @@ import org.w3c.dom.Document; | @@ -18,6 +19,7 @@ import org.w3c.dom.Document; | ||
| 18 | import org.w3c.dom.NodeList; | 19 | import org.w3c.dom.NodeList; |
| 19 | 20 | ||
| 20 | import javax.activation.DataHandler; | 21 | import javax.activation.DataHandler; |
| 22 | +import javax.xml.namespace.QName; | ||
| 21 | import javax.xml.parsers.DocumentBuilder; | 23 | import javax.xml.parsers.DocumentBuilder; |
| 22 | import javax.xml.parsers.DocumentBuilderFactory; | 24 | import javax.xml.parsers.DocumentBuilderFactory; |
| 23 | import java.io.*; | 25 | import java.io.*; |
| @@ -42,14 +44,17 @@ public class YgcBasicDataServiceImpl implements YgcBasicDataService{ | @@ -42,14 +44,17 @@ public class YgcBasicDataServiceImpl implements YgcBasicDataService{ | ||
| 42 | JdbcTemplate jdbcTemplate; | 44 | JdbcTemplate jdbcTemplate; |
| 43 | 45 | ||
| 44 | private static String IP = "218.242.195.76:9091"; | 46 | private static String IP = "218.242.195.76:9091"; |
| 45 | - private static String targetEndpoint = "http://" + IP +"/ygc.TransManager.Basicdown?wsdl"; | 47 | + private static String downTargetEndpoint = "http://" + IP +"/ygc.TransManager.Basicdown?wsdl"; |
| 48 | + private static String upTargetEndpoint = "http://" + IP +"/ygc.TransManager.BasicUpload?wsdl"; | ||
| 46 | private static String namespace = "http://service.shygc.com"; | 49 | private static String namespace = "http://service.shygc.com"; |
| 47 | private static String userName = "admin"; | 50 | private static String userName = "admin"; |
| 48 | private static String passWord = "000000"; | 51 | private static String passWord = "000000"; |
| 49 | - private static EndpointReference targetEPR; | 52 | + private static EndpointReference downTargetEPR; |
| 53 | + private static EndpointReference upTargetEPR; | ||
| 50 | { | 54 | { |
| 51 | try { | 55 | try { |
| 52 | - targetEPR = new EndpointReference(targetEndpoint); | 56 | + downTargetEPR = new EndpointReference(downTargetEndpoint); |
| 57 | + upTargetEPR = new EndpointReference(upTargetEndpoint); | ||
| 53 | } catch (Exception e) { | 58 | } catch (Exception e) { |
| 54 | e.printStackTrace(); | 59 | e.printStackTrace(); |
| 55 | } | 60 | } |
| @@ -102,7 +107,7 @@ public class YgcBasicDataServiceImpl implements YgcBasicDataService{ | @@ -102,7 +107,7 @@ public class YgcBasicDataServiceImpl implements YgcBasicDataService{ | ||
| 102 | ServiceClient sender = new ServiceClient(); | 107 | ServiceClient sender = new ServiceClient(); |
| 103 | Options options = sender.getOptions(); | 108 | Options options = sender.getOptions(); |
| 104 | options.setProperty("SO_TIMEOUT", Integer.valueOf(1800000)); | 109 | options.setProperty("SO_TIMEOUT", Integer.valueOf(1800000)); |
| 105 | - options.setTo(targetEPR); | 110 | + options.setTo(downTargetEPR); |
| 106 | sender.setOptions(options); | 111 | sender.setOptions(options); |
| 107 | System.out.println("The data in method download: " + data); | 112 | System.out.println("The data in method download: " + data); |
| 108 | data.build(); | 113 | data.build(); |
| @@ -280,4 +285,37 @@ public class YgcBasicDataServiceImpl implements YgcBasicDataService{ | @@ -280,4 +285,37 @@ public class YgcBasicDataServiceImpl implements YgcBasicDataService{ | ||
| 280 | flag = true; | 285 | flag = true; |
| 281 | return flag; | 286 | return flag; |
| 282 | } | 287 | } |
| 288 | + | ||
| 289 | + /** | ||
| 290 | + * 调用方法 | ||
| 291 | + * @param methodName 方法名 | ||
| 292 | + * @param param 参数 | ||
| 293 | + * @return | ||
| 294 | + */ | ||
| 295 | + public String invokeMethod(String methodName,String param){ | ||
| 296 | + String result = null; | ||
| 297 | + try { | ||
| 298 | + // 获得客户端 | ||
| 299 | + RPCServiceClient serviceClient = new RPCServiceClient(); | ||
| 300 | + // 可以在该对象中设置服务端的验证信息 | ||
| 301 | + Options options = serviceClient.getOptions(); | ||
| 302 | + options.setTo(upTargetEPR); | ||
| 303 | + // 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,也就是<wsdl:definitions>元素的targetNamespace属性值 | ||
| 304 | + QName opAddEntry = new QName(namespace,methodName); | ||
| 305 | + // 参数,如果有多个,继续往后面增加即可,不用指定参数的名称 | ||
| 306 | + Object[] opAddEntryArgs = new Object[] {param }; | ||
| 307 | + // 返回参数类型,这个和axis1有点区别 | ||
| 308 | + // invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象,表示要调用的方法名; | ||
| 309 | + // 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[]; | ||
| 310 | + // 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。 | ||
| 311 | + // 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{} | ||
| 312 | + // 如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法, | ||
| 313 | + // 该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同 | ||
| 314 | + Class[] classes = new Class[] { String.class }; | ||
| 315 | + result = serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[0].toString(); | ||
| 316 | + }catch (Exception e){ | ||
| 317 | + e.printStackTrace(); | ||
| 318 | + } | ||
| 319 | + return result; | ||
| 320 | + } | ||
| 283 | } | 321 | } |