webservice客户端oauth2 Bearer 认证
发布时间:2020-12-16 22:13:22 所属栏目:安全 来源:网络整理
导读:1. axis2方式 ? ? ?a. 生成client端代码: ? ? ??wsdl2java -uri F:nantianPSSPSS_1.0_WSDL_FilesPSS_1.0_WSDL_FilesWSDLsInventoryService.wsdl -p -g -t -s -o F:temp2016-4-15axis2 这样就能生成Inventory的client和测试用例,打开InventoryServ
1. axis2方式 ? ? ?a. 生成client端代码: ? ? ??wsdl2java -uri F:nantianPSSPSS_1.0_WSDL_FilesPSS_1.0_WSDL_FilesWSDLsInventoryService.wsdl -p -g -t -s -o F:temp2016-4-15axis2 这样就能生成Inventory的client和测试用例,打开InventoryServiceTest测试,这个地方要部分修改 InventoryServiceStub stub = new InventoryServiceStub(); //认证开始----------- org.apache.axis2.client.ServiceClient client = null; org.apache.axis2.client.Options option = null; client = stub._getServiceClient(); option = client.getOptions(); List<org.apache.commons.httpclient.Header> list = new ArrayList<org.apache.commons.httpclient.Header>(); org.apache.commons.httpclient.Header header = new org.apache.commons.httpclient.Header(); header.setName("Authorization"); header.setValue("Bearer " + "t4wmagv86n8v8bt3y2k9kxvj"); list.add(header); option.setProperty( org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS,list); //认证结束------------ InventoryServiceStub.CustomerInventoryRequest customerInventoryRequest14 = (InventoryServiceStub.CustomerInventoryRequest) getTestObject(InventoryServiceStub.CustomerInventoryRequest.class); // TODO : Fill in the customerInventoryRequest14 here //传参数开始------------- CustomerIdsRequest ids = new CustomerIdsRequest(); ids.setCustomerIds(new String[] {}); customerInventoryRequest14.setCustomerInventoryRequest(ids);</span> //传参数结束------------- CustomersInventoryResponseE response = stub .getCustomersInventoryIds(customerInventoryRequest14); System.out.println(response); 2. CXF方式 ? ? a. 生成client端代码: ? ??wsdl2java -p com.client -d F:nantianworkspace3.7.2cxfsrc -client ? ? ?? ? ? ? ? ?F:nantianPSSPSS_1.0_WSDL_FilesPSS_1.0_WSDL_FilesWSDLsInventoryService.wsdl 生成后如下: 修改以http_Client结尾的java文件: InventoryServicePortType port = ss.getInventoryServiceSOAP11PortHttp(); //认证开始 Map<String,List<String>> headers = new HashMap<String,List<String>>(); headers.put("Authorization",Arrays.asList("Bearer g3ssxwhud5385bzjt37us946")); Client client = ClientProxy.getClient(port); client.getRequestContext().put(Message.PROTOCOL_HEADERS,headers); //认证结束 { System.out.println("Invoking getCustomersInventoryIds..."); com.cisco.inventoryservice.CustomerIdsRequest _getCustomersInventoryIds_parameters = null; _getCustomersInventoryIds_parameters = new CustomerIdsRequest(); _getCustomersInventoryIds_parameters.getCustomerIds();//调用add增加相应参数 com.cisco.inventoryservice.CustomersInventoryResponse _getCustomersInventoryIds__return = port .getCustomersInventoryIds(_getCustomersInventoryIds_parameters); System.out.println("getCustomersInventoryIds.result=" + _getCustomersInventoryIds__return); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |