2008年11月24日 星期一

JDK 6.0自帶web service

JAVA 6.0之後,其中JDK自帶有個輕量級的web service服務器。如果你比較細心一定發現在你安裝java的路徑下,有java webservice的示例代碼。

我 以前也用java開發過web service ,但是當初用了一個apache下axis開源項目。如果axis夜進化了,反正我不認識了。不過java自帶有何必捨近求遠呢。今天我就把自己創建的最 簡單java webservice範例過程記錄下來,與大家分享。

我用的是netbeans 6,首先建立一個java應用程序工程,名為WebServices。建立一個服務端程序。
package WebServices;

import javax.jws. * ;
import javax.xml.ws.Endpoint;

/**
* @author hecm
*/
@WebService(targetNamespace = " http://www.blogjava.net/JAVA-HE " , serviceName = " HelloService " )
public class WSProvider
{

// @WebResult(name = "Greetings") //自定義該方法返回值在WSDL中相關的描述
@WebMethod(action = " sayHi " , operationName = " sayHi " )
public String sayHi(@WebParam(name = " MyName " ) String name)
{
return " Hi, " name; // @WebParam是自定義參數name在WSDL中相關的描述

}

@Oneway //表明該服務方法是單向的,既沒有返回值,也不應該聲明檢查異常

@WebMethod(action = " printSystemTime " , operationName = " printSystemTime " ) //自定義該方法在WSDL中相關的描述
public void printTime()
{
System.out.println(System.currentTimeMillis());
}

public static void main(String[] args)
{
Thread wsPublisher = new Thread( new WSPublisher());
wsPublisher.start();
}

private static class WSPublisher implements Runnable
{

public void run()
{
//發布WSProvider到http: // localhost:8888/hechangmin/WSProvider這個地址,之前必須調用wsgen命令
//生成服務類WSProvider的支持類,命令如下:
// wsgen -cp . WebServices.WSProvider
Endpoint.publish("http://localhost:8888/JAVA-HE/WSProvider", new WSProvider());
}
}
}

當然建立對應的包,就不用說了。
然後編譯文件。
進入命令提示符下,進入classes目錄,運行:wsgen -cp . WebServices.WSProvider

可以看到將剛才的class生成了幾個java文件和class文件。

現在要做的是發布ws到http://localhost:8888/chinajash/WSProvider
而實際上的動作就是:Endpoint.publish("http://localhost:8888/chinajash/WSProvider",new WSProvider());
當然直接運行WSProvider 。

然後輸入http://localhost:8888/JAVA-HE/WSProvider?wsdl

就已經查看到生成的wsdl (webservice描述語言)。

也就是服務端就OK了。

保持運行。編寫一個測試客戶端:

首先選擇項目,右鍵新建web服務客戶端。其中ws url填入剛才生成的wsdl地址:
http://localhost:8888/JAVA-HE/WSProvider?wsdl

(實際上:和wsimport http://localhost:8888/JAVA-HE/WSProvider?wsdl一樣的效果)


產生一個效果:在classes下按照之前指定的名字空間產生的包下(目錄結構)生成了7個幫助class。

然後我們建立一個包client建立測試文件:



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package client;

import net.blogjava.java_he. * ;
/**
*
*
@author hecm
*/
public class Test {
public static void main(String args[])
{
HelloService hs
= new HelloService();
WSProvider ws
= hs.getWSProviderPort();
System.out.println(ws.sayHi(
" hechangmin " ));
ws.printSystemTime();
}

}







運行這個測試類:
Hi,hechangmin

輸出了。順利完成!

一點個人經驗,你發布的地址最好寫成可配置。還有就是wsdl中會嚴格按照你指定的url來訪問,比如你指定的127.0.0.1那麼你用本機IP的時候也許並不能順利訪問。

Source: http://www.blogjava.net/JAVA-HE

2008年11月16日 星期日

How To Develop iPhone Applications in Java

Phone is a great phone to develop applications for. Unfortunately Apple decided to restrict developing iPhone applications in a less known language called Objective C, which is used pretty much within Apple (and by Apple developers) and almost noweher else. Only Steve Jobs knows the reason behind this strange decision. Java ( J2ME) is the most popular language & platform for mobile development. So Java developers need a way to develop applications for iPhone too by leveraging their core competency.


Previously I have provided two ways how Java developers can install, compile and run iPhone applications on Java. Today I will present a third method.

Apple's SDK for the iPhone, as you know, is based on Objective-C as the development language as well as Cocoa for the GUI.
Unfortunately Apple's super-restrictive license agreement for the iPhone SDK prohibits the porting of the Java virtual machine to the iPhone. Today we will talk about how we can use Open Source Java to run applications which will run on Apple's iPhone. The open source project by
Arno Puder, Associate Professor at the San Francisco State University, uses a cross-compiler to convert Open Source Java code to Objective-C and provide a Java-based implementation of the Cocoa library. With the help of these tools, iPhone applications can be written in pure Java.

Using the Java version of Cocoa, it is possible to run a Java-based iPhone application as a Java desktop/applet application that can be cross-compiled to run natively on the iPhone.

You can find more details about the software from http://www.xmlvm.org/

XmlVM's SourceForge.net Subversion repository can only be checked out through SVN with the following instruction set:

svn co https://xmlvm.svn.sourceforge.net/svnroot/xmlvm xmlvm

Warning: This is a generic Subversion checkout command which will pull all modules, tags and/or branches of the project. In most cases, you will want to add '/trunk' to the HTTPS URL above to check out only trunk (main development line).

Each of the boxes in the diagram above represents an artifact while the arrows denote the various transformations between those artifacts. The input to the XMLVM toolchain is either a Java class file or a .NET executable. A Java class file is translated to XMLVMJVM which is an XML-document describing the contents of that class file. Likewise XMLVMCLR is an XML-document describing the contents of a .NET executable. XMLVMCLR can be cross-compiled to XMLVMJVM with the help of a data flow analysis (DFA) which is shown as XMLVMCLR-DFA in the figure below. XMLVMJVM serves as a canonical representation as it acts as a boundary between the front- and back-end of the cross-compiler. Once XMLVMJVM has been generated, it can be mapped to various high-level programming languages. It is also possible to map XMLVMJVM to a Java class file again.

Check it out. Also don't forget to read the detailed guide on how to install, compile & run Java applications on iPhone.

2008年11月4日 星期二

Digital Signal Processing (DSP) Tutorial

1468 Plotting Engineering and Scientific Data using Java
1489 Plotting 3D Surfaces using Java
1492 Plotting Large Quantities of Data using Java

100 Periodic Motion and Sinusoids
104 Sampled Time Series
108 Averaging Time Series

400 Processing Image Pixels using Java, Getting Started
402 Processing Image Pixels using Java, Creating a Spotlight
404 Processing Image Pixels Using Java: Controlling Contrast and Brightness
406 Processing Image Pixels, Color Intensity, Color Filtering, and Color Inversion
408 Processing Image Pixels, Performing Convolution on Images
410 Processing Image Pixels, Understanding Image Convolution in Java
412 Processing Image Pixels, Applying Image Convolution in Java, Part 1
414 Processing Image Pixels, Applying Image Convolution in Java, Part 2
416 Processing Image Pixels, An Improved Image-Processing Framework in Java
418 Processing Image Pixels, Creating Visible Watermarks in Java
450 A Framework for Experimenting with Java 2D Image-Processing Filters
452 Using the Java 2D LookupOp Filter Class to Process Images
454 Using the Java 2D AffineTransformOp Filter Class to Process Images
456 Using the Java 2D LookupOp Filter Class to Scramble and Unscramble Images
458 Using the Java 2D BandCombineOp Filter Class to Process Images
460 Using the Java 2D ConvolveOp Filter Class to Process Images
462 Using the Java 2D ColorConvertOp and RescaleOp Filter Classes to Process Images

1478 Fun with Java, How and Why Spectral Analysis Works
1482 Spectrum Analysis using Java, Sampling Frequency, Folding Frequency, and the FFT Algorithm
1483 Spectrum Analysis using Java, Frequency Resolution versus Data Length
1484 Spectrum Analysis using Java, Complex Spectrum and Phase Angle
1485 Spectrum Analysis using Java, Forward and Inverse Transforms, Filtering in the Frequency Domain
1486 Fun with Java, Understanding the Fast Fourier Transform (FFT) Algorithm
1487 Convolution and Frequency Filtering in Java
1488 Convolution and Matched Filtering in Java
1490 2D Fourier Transforms using Java
1491 2D Fourier Transforms using Java, Part 2
1510 A Recursive Filtering Workbench in Java
1511 The Driver Class for the Recursive Filtering Workbench in Java
1512 The User Input GUI for the Recursive Filtering Workbench in Java
1513 The Recursive Filtering Workbench in Java, Putting it all Together

...
Adaptive Filtering

2350 Adaptive Filtering in Java, Getting Started
2352 An Adaptive Whitening Filter in Java
2354 A General-Purpose LMS Adaptive Engine in Java
2356 An Adaptive Line Tracker in Java
2358 Adaptive Identification and Inverse Filtering using Java
2360 Adaptive Noise Cancellation using Java
2362 Adaptive Prediction using Java

...
2444 Understanding the Discrete Cosine Transform in Java
2446 Understanding the 2D Discrete Cosine Transform in Java
2448 Understanding the 2D Discrete Cosine Transform in Java, Part 2




http://www.dickbaldwin.com/tocdsp.htm