1. 程式人生 > 其它 >axis2根據wsdl自動生成類和攜帶header引數

axis2根據wsdl自動生成類和攜帶header引數

技術標籤:javajavaaxis2

axis2根據wsdl自動生成類和攜帶header引數

更改一下指向路徑和包路徑後直接執行就會自動生成程式碼

package com.byttersoft.hibernate.erp;

import org.apache.axis2.wsdl.WSDL2Java;

import java.util.ArrayList;
import java.util.List;

public class ClientMain {

	public static void main(String[] args) throws Exception {
	    List<
String>
list=new ArrayList<String>(); list.add("-uri"); //指向你的wsdl檔案 list.add("D:\\payment.wsdl"); list.add("-o"); list.add("src"); list.add("-p"); //需要生成到那個包路徑下面 list.add("com.byttersoft.hibernate.erp"); //???????? list.
add("-t"); WSDL2Java.main(list.toArray(new String[0])); } }

這裡記錄一下攜帶header引數的方式,只貼出主題程式碼,因為檔案生成的類都不一樣,大家有個思路和方向就行

主要程式碼: headers.add(new Header(param.getKey(),param.getValue().toString()));
				PaymentServiceImplServiceStub.PushPaymentResult pushPaymentStub = new PaymentServiceImplServiceStub.
PushPaymentResult
(); PaymentServiceImplServiceStub stub=null; try { stub= new PaymentServiceImplServiceStub(); } catch (AxisFault axisFault) { axisFault.printStackTrace(); } PaymentServiceImplServiceStub.PushPaymentResultResponse pushPaymentResponse = null; //組裝xml值(傳輸你要傳遞的引數) pushPaymentStub = paymentStubService.strPushPaymentXml(reslutJson); //設定Header的資料資訊(這裡就是要傳遞的值,我這裡是以key、value的Map去封裝) Map<String,Object> headerParams = util.setHeaderMap(reslutJson,log); //新增Header引數物件(開始) Options options = stub._getServiceClient().getOptions(); List<Header> headers = (List<Header>) options .getProperty(HTTPConstants.HTTP_HEADERS); if (headers == null) { headers = new ArrayList<Header>(); } headers.add(new Header("Content-Type", "application/json")); options.setProperty(HTTPConstants.HTTP_HEADERS, headers); for (Map.Entry<String, Object> param : headerParams.entrySet()) { //迴圈Map把需要傳遞的Header引數名(key)和值(value)新增到Header中 headers.add(new Header(param.getKey(),param.getValue().toString())); } //結束 String message =""; if(null!=pushPaymentStub){ try { //推送資料 pushPaymentResponse = stub.pushPaymentResult(pushPaymentStub); } catch (RemoteException e) { e.printStackTrace(); log.info("推送資料失敗!"); } //返回資訊 message = pushPaymentResponse.get_return(); }

在這裡插入圖片描述