Wednesday Oct 14, 2009

In these day, I am write a client to access web. But I met issue on one site who is using http redirection by returning http status code 302. It's common shortage for HTTPURLConnection which didn't put the cookie from response into new access request for the redirect url. 

I search solution from web and find one library jCookie. It's quite old project but it really solve my problem. Here is a sample code to use it's HTTPRedirectHandler to handle redirection case:

    String link = "http://xxx.com/xxx";
    URL url = new java.net.URL(link);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    connection.setRequestProperty("user-agent","    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; zh-CN; rv:1.9.1.3)   Gecko/20090824 Firefox/3.5.3");
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    StringBuffer sb = new StringBuffer();

    sb.append("xx=x&xx=x");

    OutputStream os = connection.getOutputStream();
    os.write(sb.toString().getBytes("US-ASCII"));
    os.close();

    HTTPRedirectHandler connection1 = new HTTPRedirectHandler(connection);
    connection1.connect();

    connection = connection1.getConnection();

    InputStream in = connection.getInputStream();
    BufferedReader breader = new BufferedReader(new InputStreamReader(in , "UTF8"));
    String str=breader.readLine();

    while(str != null) {
          //Analyse the html;
          str = breader.readLine();
    }

    breader.close();
    connection1.close()

There have one more thing  I did:  update one line in connection function for class HTTPRedirectHandler:

        huc.setFollowRedirects(false);  ->   huc.setInstanceFollowRedirects(false);

Tuesday Sep 01, 2009

In DocWeb 2.1, there have big feature: JavaFX API Doc Support.  Though JavaFX doclet api is kind of similiar to standard j2se doclet api, there still have some different.  We finally make it work by overcome following issues:

  • Run customized doclet class under web context. There have an issue if you try it in jdk 1.6.
  • Make sure JavaFX doclet api can work together with Java doclet.
  • Handle more tags for JavaFX

 Just like it shown in pic. User can choose 'JavaFX 1.2' from left frame. Then they can search or navigate APIs by 'Class', 'Variables/Fields', 'Functions/Methods' and 'Packages' . Finally, use will saw similiar doc interface in DocWeb as I shown below.

Now, we already release DocWeb 2.1. Please enjoy those features on DocWeb site and feel free to share us your feedback or suggestion. We will make more user friendly and absoluately we need your help!

Wednesday Aug 19, 2009

There are few features in coming DocWeb 2.1. And I just finish those features for DocWeb 2.1.  Actually I got some feedback from users that they like the whole style very much but found couldn't bookmark those APIs. So we put Ajax back/forward/bookmarks support as one of highest features in this release.

Now, we partial support that feature in coming DocWeb 2.1. User can bookmark their favorite APIs in DocWeb. They can also click browser's back/forward button to view the their history page. The only limitation here is that we only support package/class link in left frame current.  You couldn't bookmark pages got by clicking method/field link in left. You also couldn't bookmark pages got by clicking link in right frame of page. Those limitations will be disappear maybe in DocWeb 2.2.

BTW, we already support most of popular browser:

  • Internet Explorer
  • FireFox
  • Mozilla
  • Safari
  • Chrome
  • Opera
Please let me know if it didn't work in your browser.

Here is one of early picture for your reference:

 The few difference user may feel when using the new version in detail:

  • one is url change from 'DocWeb/#' to 'DocWeb/#r/CLDC 1.1/java.util.Random/columnMain'
  • Second is title changed from 'DocWeb' to 'DocWeb-CLDC 1.1-java.util.Random'
We will release it very soon. Please keep in tune and enjoy it at that time!

Monday Jul 27, 2009

Now, there already have NetBeans plugin for Android. You can following the instruction to setup Android development plugin in NetBeans.

The next step is downloading Android SDK from Google and zip it to your favorite directory.

The rest steps you can refer Troubleshooting page and Introducing Android Development with NetBeans

One thing need be attention:

there have a bug in Android emulator setup. You need use a workaround:

Go in console to <SDK Path>/tools and type "android create avd -n <name> -t <target>". You can get target id by running 'android list-targets'.

Here is running result on my Mac, I make it work in NetBeans 6.7:

By the way, the emulator starting up process seemed a little slow, you just need wait for a while when click 'Run' in NetBeans.

Monday Jun 22, 2009

最近去南京做关于Java EE 架构的讲座,期间有来自企业的同行问了很多问题。其中有些问题很有意思:

  • 如何从 structs 移植到 JSF

我问了他原因,其主要是对开源框架的迁移有担心。象 structs 的迁移,到 structs 2 就与 structs 1 完全不兼容。这样的情况对原有企业的应用带来很大的问题,谁也不知道什么时候 structs 1 就没人支持和维护了。而要去迁移,成本又太大了。

这也许是某些开源框架的特性,它们会去追求最新技术,会去力求自己的框架最优。那么其演化就会比较激进,就不得不牺牲兼容性。而统观 Java EE 标准的发展,每一次更新都很好的考虑的已有应用的迁移。比如 Java EE 1.4 支持 EJB 2.1,而 Java EE 5 支持 EJB 3.0。其跨越在某种程度上是比较大的,但其仍然提供了很好的途径给企业迁移应用。在 Java EE 6 中,在考虑将实体 bean 不列为必须支持的部分,但其也提了商业的 Container 仍然可选择继续支持。

可见,技术上的先进性是不错,但有时很多企业却宁愿选择一个比较稳定的东西。那么在架构自己的企业应用的时候,尽量选用 Java EE 标准支持的技术,就是一个比较好的选择了。记得在哪里看到 IBM 50% 的利润来自它的主框架系统,使得许多人都感到意外。我想也是因为喜欢稳健使这些客户这么多年仍然选用一个相当多人认为已经消失的技术。

会上还有人问了另外一个问题:

  • 现在企业应用运行在 JDK 1.4 上,他们往 JDK 5 或 6 上迁移要考虑些什么?同时他还抱怨 JDK 版本是不是升级得太快了。
其实 JDK 版本升级不能算太快吧。象 JDK 5 中加入 annotation,JDK 7 中加入对 OSGi 的支持。这些都已经是业界支持了好一段时间了,最后才加入 JDK 中。不管怎么样,JDK 的各个版本间都保持了很好的兼容性,相对与 .Net 的用户,应该是很幸福的了。

Wednesday Jun 17, 2009

Two weeks past after we officially release DocWeb 2.0 outside. Now, we have visit data in my hand. Here is just make a simple analysis base on those data:

  • We already have 3,600 unique users access system and total access number is 4,507. The new visitor is 3600 which is 80% of all. That means the returning visitor is 900, it's 20% of overall.
  • We got about 300 new visitors everyday in past 2 weeks. At the same time, we got about 50-100 returning visitor everyday. That's good news for us: DocWeb make some users keep in loop and continue to attract more new users.
  • Those users come from all over the world. And top 10 countries are China, United States, Japan, India,Germany,Brazil,France,Mexico,United Kingdom and South Korea.
  • Most of popular browser used are Internet Explorer and FireFox. 9% of visits use Chrome and Safari.
  • 92 % of visits have Java plugin ready in browser
  • Most of import features from feedback are: Doc translatable and searchable.

Welcome all users from the world!


Monday Jun 01, 2009

今天, 2009年6月1日,我们正式在 http://doc.java.sun.com  上发布的 DocWeb 2.0 版本。SDN 的用户可以直接登陆 DocWeb。

DocWeb 2.0 使用 SDN 的用户界面风格,独特的支持 SDN 单点登录,多语言的内容,丰富的用户交互形式:意见,代码示例,投票,错误参考等等... 对全球的 JavaSE, ME, EE开发者而言,希望这个版本将大大增强用户体验和引进更多的方便和实用。衷心的欢迎大家浏览 DocWeb 2.0 并提更多宝贵意见!

Friday May 22, 2009

In DocWeb 2.0 final release, we will follow same VOC gathering way used by Sun's website. There will have a float icon on webpage. User just need click it if they have some feedback for this application:

When user click on that icon, a dialog will popup to user to fill their feedback like this:

Please feel free to fill your feedback about DocWeb 2.0. We will try our best to make DocWeb 2.0 better!

Friday May 15, 2009

In past year, I use my spare time to work on this Java API doc community: DocWeb 2.0 . I still work hard to deliver it outside yestoday though the whole beijing site in under sad mood. I even join a fareware lunch a little delay cause of this. But I am so still exciting when I saw it is outside and work perfect as it is just like your baby. It's hard time and what we can do is do it best! We plan to release final version before JavaOne. And the schedule will be still tight as we still have lots things need be covered:

  • Existed user migration
  • SDN authentication module integration
  • Cluster support in application
  • Some bug fixings
  • Product running environment setup

Could you please let me know if you have any comment for DocWeb 2.0? Here is screenshot for your first view:

Monday May 11, 2009

Traditional Chinese handwriting is beautiful and elegant, and it is symbol of chinese traditional spirit. I am interesting in how we can emulate it in JavaFX. Here I create a simple demo to show it.

  • Make sure you have image editor like Adobe Illustrator or Photoshop
  • Download JavaFX 1.1 Production Suite and install it.
  • Create a serial of layers in photoshop which demo the whole chinese character writing process. Here I create 11 layers to show one chinese character.
  • Following tutorial: Getting Started With JavaFX 1.1 Production Suite, we can export our pictures into .fxz file which can be use in JavaFX. You need uncheck "Preserve 'JFX:' IDs only" during exporting to get an id for each node in exported file:


  • Create a new JavaFX project in NetBeans and copy that exported file into your project

In NetBeans project, I only need writing few line of code to make it work:


var content = FXDLoader.loadContent("{__DIR__}res/handwriting.fxz");
var x: Integer;

Timeline {
  repeatCount: Timeline.INDEFINITE
  keyFrames: [
    at(0s) { x => 1 },
    at(3s) { x => 11 tween Interpolator.LINEAR}
  ]
}.play();

var node = bind content.getNode("layer{x}");

Stage {
    title: "Application title"
    width: 425
    height: 425
    scene: Scene {
        content: bind [content.getNode("background"), node]
        }
}
      

Here is the demo:

Here is java web start way to run it as desktop: Traditional Chinese Handwriting Demo

Thursday May 07, 2009

There already have docs about customize API doc for Java SE: Doclet Overview. How about JavaFX doclet?

Actually, most of part in that Java SE doc can be applied to JavaFX's. You need download JavaFX sdk from JavaFX website. There have a file whose name is javafxdoc.jar. You need compile and run your customized doclet class with that library. You can use that simple example doclet provided in Doclet Overview and take a try to compile your doclet class:

javac -classpath javafxdoc.jar ListClass.java 

And then write some javafx code MyClass.fx and run it with your doclet:

javafxdoc -doclet ListClass -docletpath .  MyClass.fx

It will create output for MyClass.fx according to your doclet class.

 
  

Friday Apr 17, 2009

In previous article, we talk about how to create a new project in NetBeans. Here we will try to make it final work for App Engine.

Update build.xml

  • Put dependency class libraries for 'compile' task 
  • Copy all of those libraries to deploy directory
  • Create some task to make debug ready
  • Make those xml files ready for JDO/JPA enhancement

Here is my build.xml file, It worked on my environment. I map test action to 'debug' as there is no debug item there for map:

Please remember to update propery 'appengine.sdk' accourding to your environment, and keep in mind that I put third-party jar files under '<Project Base>/lib' directory.

Now, most of things are ready in NetBeans, you can create application and run/debug it in NetBeans now.

How to create Servlet

You can new a Servlet after right click on project. NetBeans couldn't auto generate information in web.xml for free-form and you just need go to web.xml and manully did servlet/url mapping like this:

That's different thing for Servlet support.

How to debug application for Google App Engine

Since we already map 'test' action to 'debug', we should right click on project and choose 'test' to do debug'. When system is running and listenning on Java remote debug port 5005, attach debugger under menu 'Debug':

Enhancement

I remove datanucleus-enhancer-1.1.1.jar under directory 'lib' as there have duplicated one under 'lib\user\orm'. It will cause duplicated registration error during enhancement.

How to stop running container

We need manully kill it outside of NetBeans. We can use 'kill' on Unix and 'Task Manager' on Windows to kill that java process. I bet you won't make mistake to kill NetBeans process as it use more memory than that container's. You need finish debugger session in NetBeans first if you are debugging it.

Now, we can easily debug Servlet/JDO/JPA in NetBeans. You can download NetBeans here!


Thursday Apr 16, 2009

Since there haven't so many articles talking about how to do job in NetBeans for Google App Engine, I take a try and here I will share you my way to make it work from scratch as a workaround. We still need NetBeans plugin for full support. Hope it will be ready very soon.

- Copy demos\new_project_template directory from that app engine SDK for java to your project home directory as your initial project pattern.

- Delete unecessary file and make it ready like this:


- Start NetBeans, new a project and choose 'Java Free-Form Project' under 'Java' Category. Just like following screenshot shown:


- Click 'Next' button and choose your template directory your just copy from SDK demo for 'location'

NetBeans will automatically fill rest of columns. You just need change your project name from default.

- Click 'Next' to map NetBeans action to customed build script, here what I did:

I mapped 'Build Project' to 'compile', 'Clean Project' to 'clean' and 'Run Project' to 'dev_appserver'. I will talk it later about how to debug in NeBeans and we will map 'test' to 'debug' at that time. Here we just skip that step.

- Last step for free-form project creation in NetBeans is put your source package folder here:

- After project creation in NetBeans, we need update project properties to include more lib. Right click on new project and click on 'properties'. Please put follow jar file into 'Java Sources Classpath':

  • appengine-api-1.0-sdk-1.2.0.jar under 'lib\user' from App Engine SDK
  • All jar files under directory 'lib\user\orm' from App Engine SDK
  • All jar files under directory 'lib\shared\' from App Engine SDK
  • Third-party jar if you program will be used. You can put those jars under <project>\lib

You don't need use all of those libs. You can reduce them according to your requirement. I didn't try it:

This step is making NetBeans editor know those classpath and make it work correctly on your code when your are writing. Compile process couldn't automatically reuse those classpath for compiling. We still need put those libs for compile process. Please check next article about update build.xml to make it work finally.

Saturday Apr 11, 2009

I saw Google release a early access for App Engine for java language and take try(It also support Python as well). I am fetching RSS feed from different blogs and show it locally on system. It works great! You can take a look on my trial page

Nowaday, Google only provide development plugin for Eclipse. I still prefer to code in NetBeans. So I use Netbeans to coding and it work:

  • Create a web project and choose any container during creation
  • Manually put Google's lib into project I need call it's service.
  • Manually create 'appengine-web.xml' file under directory 'WEB-INF' and remain 'sun-web.xml' as while.
  • Clean and build it in NetBeans(Please don't run it in NetBeans as Google app engine use a different container)
  • Run app engine in console 'dev_appserver.sh <project base>build/web' and access it in your browser by http://localhost:8080/
  • Upload it to your application by 'appcfg.sh update <project base>/build/web' after you already apply an application id on google(Please apply one from Google if you haven't)
  • Access your online application by http://<Application ID>.appspot.com/.

The only pity is I don't find a easy way to debug it directly in Netbeans.

Google give a quota for free trial. It is enough for me nowaday. I am just worry about upcoming quota change and not sure it can match user needs for free.

Monday Mar 30, 2009

There already have lots for page flipping components for flash. Seemed there is no for JavaFX. I take some times and create a prototype. You can take a try if you already installed jdk1.6.0 u12 or above on your machine to view this demo:

- Wait for program loading for a while

- Move mouse to one corner of slides, drag it to flip to another page till it's on end or beginning page.

Please let me know if you have more comments. I will put your suggestion into update version.

FlipPage Demo

Here is java web start way to run it as desktop: FlipPage Demo

This blog copyright 2009 by leonfan