webservices系列(二)——JAX-WS文件上傳下載

新建ImgData類,存放文件javabean

DataHandler:使用這個類型存放文件

@XmlRootElement(name="ImaData")
@XmlAccessorType(XmlAccessType.FIELD)
public class ImgData {private Integer id;@XmlMimeType("application/octet-stream")private DataHandler imgData;	//文件public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public DataHandler getImgData() {return imgData;}public void setImgData(DataHandler imgData) {this.imgData = imgData;}
}
Webservice接口,

@WebService(name="iHello2")
@SOAPBinding(style = SOAPBinding.Style.RPC)
@MTOM
public interface IHello2 {public void printContext();public ImgData getById(@WebParam(name="imgData")ImgData imgData);
}
實現類

@WebService(serviceName="HelloService",portName="HelloServicePort",
targetNamespace="http://service.lc.com/",endpointInterface="com.lc.service2.IHello2")
public class IHello2Imp implements IHello2 {@Resourceprivate WebServiceContext context;@Overridepublic void printContext() {MessageContext ctx = context.getMessageContext();Set<String> set = ctx.keySet();for(String key : set) {System.out.println("{" + key + "," + ctx.get(key) + "}");try {System.out.println("key.scope:" + ctx.getScope(key));} catch (Exception e) {System.out.println("scope not found");}}}@Overridepublic ImgData getById(ImgData custom) {if(custom.getId() == 1) {File file = new File("f:" + File.separator + "原文件.png");System.out.println(file.exists());custom.setImgData(new DataHandler(new FileDataSource(file)));}return custom;}}
這里需要在f盤下放一個“原文件.png”的文件,當然也可以改
創建webservice類SoapService2,運行

public class SoapService2 {public static void main(String[] args) {Endpoint.publish("http://localhost:8080/HelloService2", new IHello2Imp());System.out.println("run success");}}
生成客戶端代碼

在cmd使用wsimport -p com.lc.client2 -keep http://localhost:8080/HelloService2?wsdl


把文件拷到eclipse對應包下
創建客戶端類SoapClient.java,運行

public class SoapClient {public static void main(String[] args) throws MalformedURLException {QName qName = new QName("http://service.lc.com/", "HelloService");HelloService helloService = new HelloService(new URL("http://localhost:8080/HelloService2?wsdl"), qName);IHello2 hello2 = helloService.getPort(IHello2.class);hello2.printContext();ImgData imgData = new ImgData();imgData.setId(1);ImgData imgData2 = hello2.getById(imgData);DataSource ds = imgData2.getImgData().getDataSource();String ctt = ds.getContentType();System.out.println("ContentType:" + ctt);try {InputStream is = ds.getInputStream();OutputStream os = new FileOutputStream("F:" + File.separator + "t1.png");byte[] bytes = new byte[1024];//一次讀取1024byteint i = 0;while((i = is.read(bytes)) != -1){os.write(bytes, 0, i);}} catch (IOException e) {e.printStackTrace();}	}
}
運行結果




參考資料
[1].http://wuhongyu.iteye.com/blog/807470

[2].https://my.oschina.net/liu13430/blog/373940?fromerr=WmdtQOoY

[3].http://clq9761.iteye.com/blog/976029/


轉載于:https://www.cnblogs.com/marx-luo/p/6713068.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/254882.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/254882.shtml
英文地址,請注明出處:http://en.pswp.cn/news/254882.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

halcon sobel邊緣檢測sobel_amp

目錄sobel_amp&#xff08;算子&#xff09;描述參數sobel_amp&#xff08;算子&#xff09; sobel_amp - 使用Sobel算子檢測邊緣&#xff08;幅度&#xff09;。 sobel_amp&#xff08;圖片&#xff1a;邊緣圖像&#xff1a;濾波器方式&#xff0c;掩膜大小:) 描述 sobel_…

es中的一些知識點記錄

1. forcemerge接口 強制段合并&#xff0c;設置為1時&#xff0c;是期望最終只有1個索引段。但實際情況是&#xff0c;合并的結果是段的總數會減少&#xff0c;但仍大于1&#xff0c;可以多次執行強制合并的命令。 設置的的目標值越小。合并消耗的時間會越久。 curl -XPOST htt…

用live555和ffplay搭建流媒體環境

用live555和ffplay搭建流媒體環境 http://bbs.chinavideo.org/viewthread.php?tid12166

如何才能優雅地書寫JS代碼

第一&#xff1a;關于匿名函數的使用 要避免全局變量泛濫&#xff0c; 可以考慮使用匿名函數&#xff0c; 把不需要在外部訪問的變量或者函數限制在一個比較小的范圍內。 例如以下代碼&#xff1a; <script> function func1(){ var list ["a", "b",…

halcon hough_lines 霍夫直線變換

目錄hough_lines&#xff08;算子&#xff09;描述參數hough_lines&#xff08;算子&#xff09; hough_lines - 借助Hough變換檢測邊緣圖像中的線條并將其返回到HNF中。 hough_lines&#xff08;RegionIn :: AngleResolution&#xff0c;Threshold&#xff0c;AngleGap&…

通過border來實現各種三角符號

很長時間沒有動筆了&#xff0c;最近學的東西很雜很亂&#xff01;又有點丟了西瓜撿芝麻&#xff0c;走馬觀花&#xff0c;瞻前顧后的感覺&#xff01; 因此&#xff0c;我決定一步步來&#xff0c;化繁為簡&#xff0c;今天就從border入手。 很多時候我們都會需要一個三角形或…

MFC封裝API

一、Win32Application Architecture 一個Win32 Application Architecture的代碼結構如下&#xff1a; LRESULT CALLBACK WinWordsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //定義回調處理消息函數 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPr…

通過閱讀 Douglas Crockford 的源碼學習如何寫 JSON parser(一)

JSON-js Douglas Crockford 是 JSON 的發明者&#xff0c;所以通過 DC 的代碼來學習 JSON 和 parser 絕對是上乘之選。這個倉庫里面有四個 JS 文件&#xff0c;今天我們先研究 json_parse.js。 json_parse 定義了如下 API&#xff1a; json_parse(string) > object json_par…

halcon gen_region_hline 繪制霍夫變換提取直線

目錄gen_region_hline&#xff08;算子&#xff09;描述gen_region_hline&#xff08;算子&#xff09; gen_region_hline - 將霍夫變換提取直線以普通形式描述的輸入行存儲為區域。 gen_region_hline( : Regions : Orientation, Distance : ) 描述 運算符gen_region_hline…

H.264視頻RTP負載格式/NALU的類型

1. 網絡抽象層單元類型(NALU) NALU 頭由一個字節組成, 它的語法如下: |0|1|2|3|4|5|6|7| |F|NRI| Type | F: 1 個比特. forbidden_zero_bit&#xff1a;在H.264規范中規定了這一位必須為0。 NRI: 2 個比特. nal_ref_idc&#xff1…

4.10下午

轉載于:https://www.cnblogs.com/yanyuying/p/6690662.html

虛函數

1、基于向上類型轉換&#xff0c;基類通過虛函數可以對多個子類相似的功能實現統一管理。 2、例子&#xff1a; A為基類&#xff0c;B、C為A的同級子類。virtual只需在基類中標識一次&#xff0c;子類無需重復標識。class A {virtual void display(){cout<<"我是A&q…

Android繪制(一):來用shape繪出想要的圖形吧!

目錄 前言shape繪制矩形橢圓線環用shape繪制SeekBar最后前言 在沒有UI設計師的時候, 或者是想簡單看下效果的時候, 用shape進行快速繪制是極好的! 官方文檔. shape繪制 一共有四種shape: rectangle, oval, line, ring. 矩形 我們一個一個來看, 首先是矩形: <?xml version&q…

halcon sobel 邊緣檢測 sobel_dir

目錄sobel_dir&#xff08;算子&#xff09;描述參數sobel_dir&#xff08;算子&#xff09; sobel_dir - 使用Sobel算子檢測邊緣&#xff08;振幅和方向&#xff09;。 sobel_dir(Image : EdgeAmplitude, EdgeDirection : FilterType, Size : ) 描述 sobel_dir計算圖像的一…

靜態鏈接庫LIB和動態鏈接庫DLL的區別 創建和示例

1.什么是靜態連接庫&#xff0c;什么是動態鏈接庫靜態鏈接庫與動態鏈接庫都是共享代碼的方式&#xff0c;如果采用靜態鏈接庫&#xff0c;則無論你愿不愿意&#xff0c; lib 中的指令都全部被直接包含在最終生成的 EXE 文件中了。 但是若使用 DLL&#xff0c;該 DLL 不必被包含…

【譯】x86程序員手冊37-第10章 初始化

Chapter 10 Initialization 第10章 初始化 After a signal on the RESET pin, certain registers of the 80386 are set to predefined values. These values are adequate to enable execution of a bootstrap program, but additional initialization must be performed by s…

在ubuntu中安裝minicom時出現device /dev/tty8 is locked解決辦法

未正常關閉minicom yesaiduywf-ubuntu: ~$ ls /var/lock LCK..ttyS0 subsys yesaiduywf-ubuntu: ~$ kill 0 yesaiduywf-ubuntu: ~$ ls /var/lock subsys yesaiduywf-ubuntu: ~$ sudo minicom Welcome to minicom 2.3 或者刪除/var/lock下面以LCK開頭的文件轉載于:https://www.…

秒殺多線程第二篇 多線程第一次親密接觸 CreateThread與_beginthreadex本質區別

本文將帶領你與多線程作第一次親密接觸&#xff0c;并深入分析CreateThread與_beginthreadex的本質區別&#xff0c;相信閱讀本文后你能輕松的使用多線程并能流暢準確的回答CreateThread與_beginthreadex到底有什么區別&#xff0c;在實際的編程中到底應該使用CreateThread還是…

halcon get_image_pointer1獲取圖像指針

目錄get_image_pointer1&#xff08;算子&#xff09;描述參數get_image_pointer1&#xff08;算子&#xff09; get_image_pointer1 - 訪問單通道圖像的指針。 get_image_pointer1(Image : : : Pointer, Type, Width, Height) 描述 運算符get_image_pointer1返回指向圖像I…

如何傳輸文件到linux服務器?

我們知道&#xff0c;云主機文件傳輸是一件相對復雜的事情&#xff0c;經常需要搭建FTP服務器或者是借助其他工具來完成。下面為大家介紹一種簡單易操作的傳輸文件到Linux服務器的方法。 Linux文件傳輸同Windows文件傳輸一樣&#xff0c;我們為每一臺Linux主機配置了一個1G的網…