Sunday, December 18, 2016

告诉你外语学习的真实方法及误区分析 笔记

一、早期(Early Stage)
看图识音
这一过程结束时,应该达到1000个左右的词汇+短语量。
这样几十小时一个级就能完。大家一定不要拖,非得“全会”不可那就麻烦了。觉得70分以上就好了。第二级如果从零基础直接这么上来有点费力,但有一点基础的同学没问题。一共两个月,每天也就一小时吧,我们的(Early Stage)就成功了。
大家在这阶段,不要试图说,同时不要打开字幕,把“说”和“阅读”练习部分统统跳过。大家最多在听时小声重复一下就好。再有就是大家不要“想中文”。(所以建议大家尽量不用中文菜单的界面,它可选用英文界面)
1. 避免使用中文翻译,充分建立条件反射;
  2. 不要试图说英语,只练听力;(还在沉默期内);
  3. 不要看任何拼写,把拼写的学习完全放弃;(不认识字母又和妨?)
  4. 如果有外教参与,外教可多用肢体语言或用手画图协助这一过程,不要教课;
  5. 不要怕听错,要放松和有信心;

二、提高期(Upping the Ante)
  Upping the Ante?这可是第四阶段的词。没办法,Greg Thomson用这个词代表第二阶段,看着喜欢,继续沿用。
   经过两三个月的“图象+声音思维”训练,已经掌握了1000个左右的“声音”,它们会在很多英语句子中频繁出现,而且大部分是句子的“骨架”。虽然这时听整句子还不懂,但已经不再是完全莫名其妙的声音了。而且经过了TPR等条件反射式的训练,对很多“声音”的反应速度还是相当好的。这时,我们要开始提高了。首先明确目标:
  1. 要学会听懂单句子,建立整句的英文思维;
  2. 达到能听懂简单的,可能是慢语速的整段英文;
  3. 在提高期后期开始尝试简单“说”英语,实现简单沟通;
   美国、加拿大有一电视节目“Yan Can Cook”,一个著名华裔电视厨师Yan教大家做中国菜。他一边幽默地叨唠一边切菜、炒菜,几乎把每个菜、原料,制作过程的每个动作等,全部同步地用英文仔细地叙述一遍,当时惊叹为理想的“可理解性输入”体系!
回到根本上就是一个原则:能否提供在本人现有水平上的“可理解性输入i+1”的条件。
回复红螺:老友记能不能看,要看对你适不适和.高级阶段的同学很适合看,判断标准是基本能听懂七八成,并通过剧情发展和听到的语言,大致"预测"得出部分原本不能懂(写下来可能都不懂)的语言.
  如果是这些语言写下来都懂而只是听着费力,那是另外的原因,当然也可以继续听这个。而听的技巧我们在下阶段探讨.
第二期的总时间跨度每个人会比较不同。如果能够达到理想状态,专家分析应该是三到六个月可以完成。我们还是保守一些,至少六个月吧。在进入第二期的后段,我们可以开始可以试着说一点我们熟悉的外语了(错了没关系,既不要着急,也不要忙着更正)。

大家可以参考蒋争老师那本258个词根9000多单词的那本英语词汇奥秘
至于传教士门在传教过程中,是被教会禁止使用英语或教英语的,原因是为了避免移民以学英语为理由接近教会而并不真信教。所以他们自己不教外语。但因这些人普遍比较善良,在不违反教会规定的情况下,让大家免费使用教会的教室并且也不禁止其他人去辅导大家外语。

三、增长期 Getting Serious 
这一时期的主要任务是语言难度和量增长。重点还是听力,但可以开始有针对性地说英文,同时需要进行阅读(但主要并不是为了学习如何阅读)。这一阶段结束时,可以说已经能够进行正常交流和阅读了。(外企一般职位面试,出国求学,国外生活和从事一般技术型工作等可以应付。一般听英语新闻困难不大,看原版电影可听个大概)。在这一阶段初、中期的中国同学数量比较多,但往往时间拖得过长,同时遇到的困惑也比较多。我们前面刚提到,尤其在这一阶段,每个人必须根据自己的情况,制定最适合自己的学习策略。学习策略的好坏,直接关系到学习效率和成功与否。
问:听英文广播学习效果是否好?
  
   我们已经会分析了。听广播本身并没有好坏之分(当然您可千万别苦练听写),而且Audio Learner也很适合这种形式。关键是是否有足够“可理解性输入”,所以需要具体分析。基本经验是:
  
  1, 听力材料的速度和句子难度是否适合?如果能理解一半以上才可以听,否则基本上是在浪费时间。原则上听不懂的东西应该是“无效输入”,永远也不懂。
  
  2, 在适当的难度前提下,如果又对听的话题或内容非常了解,而且从前文可以预测后面的意思,语音清晰(建议带耳机),速度适合,那会是比较有效的方式。特别是有些同学平时就喜欢听新闻,对时势的变化很熟悉。听英语新闻时,不久前刚听到的头条新闻可能一天之后又以另一非头条,而简短形式重复出现,效果更好。最好能快速慢速结合听,这样做效果显然比较显著。
  
  3, 没懂的部分别着急。在调查过很多用这种方式提高听力的同学的普遍经验是,个别没听懂的地方不要急,先放下,也许换一种方式再出现时就自然理解了。如果出现次数很多,再想办法查一下吧,否则就放过。其实母语学习的过程也是如此,怎么能每碰到一个不懂的就非过不去呢?非都搞懂并没什么害处,可学习效率就没了。
  如果做得不得法,很多同学听了很久,提高都不大。有的同学没事儿就开着英语新闻听,其实几小时过去了,几乎没有听进去。
对于大部分Visual Learner来说,一个重要可行手段是看电影前,先提前读英文剧本(很多可以下载)。这样会大幅度提高听力的理解性。这里阅读的用处开始显现,主要是在帮助听力理解,不是在学阅读。注意的是要提前读,不会的可以问或查字典。阅读如果有困难,也先放过,不要停下来仔细研究剧本中的难点。
开始看影片的时候不可以一边看一边翻看剧本,当然也不要开英文字幕,否则会养成依赖看字的习惯,特别是Visual Learner。
  
  4,最好是同一个电影看几遍。在看某个影片熟了之后,甚至可以随电影同时念叨台词,能象我们小时候跟着电影里老松井那样同时念“李向阳又进城啦?”那样就更好了。

A Sample Acquisition Cycle
  
  1, 先听整段原文,段落长短控制在正常速度10钟内放完。难度选择应该是控制在第一遍能听懂的程度是70%上下。不要看文字或字幕。这步的目的主要是先熟悉要学的内容或说是该内容的声音。
  2, 开始分句模仿跟读,每句约三遍,(听一遍跟一遍,不是听一遍读三遍)不懂的也跟读,别着急查意思。是否全对或是否全会不必太介意,可以看字幕但尽量不看,一边模仿,一边猜测不明白部分的含义。关键技巧是“猜测”。
  3, 不看字幕分句跟读一遍,把原声和自己读的声音都录下来。
  4, 放第3步的录音,努力听每句自己读的和原文有何区别并再次感受刚才的过程,可看字幕帮助核对。
  5, 分句自己先说,然后再听原文。第一次可看字幕,后两次尽量不看字幕。
  6, 自己回想该段剧情,试着复述说刚才每部分的句子。
  7, 如果有测试题,可以测试一下自己对上一段掌握的程度,还是80分就好。
  8, 下一段开始,重复上面同样的程序。

知道连读的原理也就可以了,不知道也没关系,跟语法知识的道理一样,大家千万不要有意识地记住连读原理并试图理性地应用它,那样又适得其反,更加深听力障碍和造成不会说话。无论掌握听、说的连读,都是个自然的过程,不要主动地学习连读和练习连读。
不是机械地背诵,而是根据英语描述的故事,在理解的基础上,联想和思考故事情节发展和句子的含义进行记忆。每次背出来时,明显从他们的表情变化甚至情绪起伏都能感觉到他们的思维是随所背内容的故事发展而变化。
夹克小猪问工作的成年人从基础到高级,如果学习方法科学有效,用多久:现在的最佳的实践情况是,在中、英文这种差距大的语言之间,实现时间大约总共1000小时左右,但需要一两年左右,不可以把1000小时压缩到几个月。如果从英语法语之间,300-500小时就很好了。意大利语和西班牙语之间,太容易了,不学也可以,反正听得懂对方。有个最佳实现方式下时间和水平的曲线图,找机会在后面贴出来。

第三阶段完成就可以达到能够进行正常的交流和沟通,开始在英文环境工作和学习没有太大困难,看英文电影能理解大部分。尽管对复杂的英文理解有困难或还有些听不懂的部分,说的英文大多是大白话,但如果听说的反应迅速,已经可以定义为流利的英文了。第三阶段的跨越是最具挑战的,情况很复杂(第四阶段反而简单)而且每个人成功跨越该阶段的具体实现手段都不同,不能要求大家都用同一具体方法。所以大家也发现我们在第三阶段并没有给大家明确指定一个具体的技术手段让大家执行。但凡高效率取得成功的人,尽管具体策略不同,但都是某种手段符合了正确的学习原理。

半年多后,开始尝试听整点播放的快速英语。一开始很不适应,但发现如果先听一遍慢速的,再听快速的会好些,因为内容差不多,对内容已经先有些了解,听个大概还是可以的。另外广播员是同一个人(至今还记得播音员的名字是Alan,声音浑厚而有磁性),语气语调相同好适应。开始听慢速时,还试图在脑子里转成中文去理解,听快速时根本不可能,后来慢慢习惯听英文时不再想中文了。
-作为非母语学习,是永远也不可能完全达到母语水平比如用英文写诗歌和小说的,除非有人帮忙改写。另外作为非母语的语言学习,最高境界也就是听力达几乎10分满分,说永远会落后,最高达9分。(想不起哪里有这个10制的语言能力评测系统了)
比较好的阅读方式是出声阅读,主要是为了在阅读的同时还能听到英语的声音,同时尽量将自己融入阅读的故事情节中。到了英文高水平后,就不用出声阅读了,因为这样阅读速度慢。我们在这里建议出声是为了练习。
第三阶段到这里讲得差不多了。这一阶段的突破难度大,不得要领有可能一直无法突破或拖很长时间。应该说在描述此阶段时,文章结构很散乱,也失去了系统性。
 “YOU CAN COOK”中文叫“食得是福快靓正”,也叫“甄能煮”


四、 高级期(Scaling Everest)
一般在第三阶段花了多少时间,自己都说不清楚了,效率再高至少也得有一年多吧,好在并不是每天都要花大量时间,平均每天一小时就好了。终于到了该向珠峰Mount Everest顶冲击了。先把一个不幸的消息告诉大家:我们的外语永远也不可能达到母语的水平(除非12岁以下就能实现流利交流,那本身形成的就是母语,不算外语)。我们可以将听,读达到近乎完美,写作也可以达到非常高的水平,虽然不大可能写诗歌或小说。但说外语的水平还是会跟母语有些差距。可以达到非常流利的程度,但在真实场景的时间压力和精神压力下,出现错误再所难免。

克林顿的演讲应该是非常好的听力素材。(不建议找以前名人的演讲,不是语言过时,而是文字太古板了。)
韩国郑博士的《千万别学英语》是非常值得中日韩三国同学一读的好书。其题目就点明了英语不应该是学得,而应该是悉得。
 郑博士的书阅读对象主要是经过多年英语学习还是哑巴英语同学,不是完全的初学者。所以按他的设计,从这水平起在理想的状态下每天90分钟,6个月到1年就可以突破。

摘录一段释迦牟尼讲的话和大家分享:
  
   不要相信只凭听说的任何事物。不要相信世世代代流传下来的传统。不要因为众人都这么说而相信它。不要因为经典上的记载而相信它。不要相信权威、导师或长辈的教导。当你经过观察和分析后,认为事物与原则一致,并有助于个人和大家的善行与利益,才接受实行。


Selinker在70年代正式提出了中介语的“石化现象”(fossilization)。他总结道:“学习外语的成年人,尽管有机会长期暴露在外语环境中,但是大部分( 95%)的人的外语水平,会在某个时期被固化在一个特定的水平层面,很难再提高”( Selinker,1972)。

。前面提到的三种石化水平(秀水街英语、留学生英语、工作英语)的同学,出现石化的原因是很多的,但他们有一个共同点就是:石化时的外语水平,跟他们开始大量使用外语交流时的外语水平非常有关。开始使用外语交流时自己的外语水平越低,石化出现的就越早,且被石化的水平也越低。

Wednesday, November 23, 2016

偏头痛

丙戊酸镁缓释片
尼麦角林片
复方天麻蜜环糖肽片
CT、磁共振、脑电图、心电图、血糖、血脂均检查过,没问题
拍颈椎片,4至6椎骨质增生
黎刚大夫诊断为偏头痛,上次开了三种药:丙戊酸镁缓释片、尼麦角林片、复方天麻蜜环糖肽片。吃一个月之后头痛头晕好像更严重。20161021
但是吃药前头晕呕吐,现在仅头晕,不呕吐了
http://shengming.haodf.com/thread/finish?threadId=4863099055

黛立新

不能控制的话可以考虑 艾司唑仑

Tuesday, November 22, 2016

websphere note

A node is an administrative grouping of application servers for configuration and operational
management within one operating system instance (virtualization allows multiple operating
systems on one machine).

A cell is a grouping of nodes into a single administrative domain.
 In the Base and Express
configurations, a cell contains one node. That node contains one server.
yment managers
The deployment manager is the central administration point of a cell, which consists of
multiple nodes and node groups in a distributed server configuration.

A proxy server is a specific type of application server that routes requests to content servers
that perform the work.

The web server plug-in
will send the request to the application server using the host name and port number in the
transport setting for that server.

An unmanaged node does not have a node agent to manage its servers.

 If your web server is the IBM HTTP Server, you can
configure the server on an unmanaged node, and still be able to administer the web server
using the WebSphere administrative tools. This unmanaged node does not need a node
agent on the web server machine.
A managed node has a node agent for managing web servers.

Thursday, November 10, 2016

Programming in Scala 16/

1.
List(1, 2, 3) creates the list1 :: (2 :: (3 :: Nil)).
2.
List(List(1, 2), List(3), List(), List(4, 5)).flatten
The zip operation takes two lists and forms a list of pairs
3.
The operation xs map f takes as operands a list xs of type List[T] and a function f of type T => U. It
returns the list that results from applying the function f to each list element in xs. For instance:
scala> List(1, 2, 3) map (_ + 1)
res32: List[Int] = List(2, 3, 4)


Saturday, November 5, 2016

iPhone 7 model for China Mobile 4G

From the below official website, iPhone 7 Plus Model A1661 works for ChinaMobile 4G while A1784 does not.
https://support.apple.com/en-ca/HT201296
https://support.apple.com/en-us/HT202909

Thursday, November 3, 2016

Live and learn

Mahatma Gandhi: “Live as if you were to die tomorrow. Learn as if you were to live forever.”

Wednesday, November 2, 2016

Programming in Scala 11/12/13/14/15

1.
Any is a superclass of every other class, Nothing is a subclass of every other class.
== and !=, are declared final in class Any, so they cannot be overridden in subclasses.
2.
Class Null is the type of the null reference; it is a subclass of every reference class (i.e., every class that
itself inherits from AnyRef). Null is not compatible with value types. You cannot, for example, assign

a null value to an integer variable.
Type Nothing is at the very bottom of Scala's class hierarchy; it is a subtype of every other type.
you can
do anything in a trait definition that you can do in a class definition, and the syntax looks exactly the
same, with only two exceptions.
First, a trait cannot have any "class" parameters.
The other difference between classes and traits is that whereas in classes, super calls are statically
bound, in traits, they are dynamically bound. If you write "super.toString" in a class, you know exactly
which method implementation will be invoked. When you write the same thing in a trait, however, the
method implementation to invoke for the super call is undefined when you define the trait.
3.
Using the modifier case makes the
Scala compiler add some syntactic conveniences to your class.
First, it adds a factory method with the name of the class.
The second syntactic convenience is that all arguments in the parameter list of a case class implicitly
get a val prefix, so they are maintained as fields.
Finally, the compiler adds a copy method to your class for making modified copies.
However, the biggest advantage
of case classes is that they support pattern matching.
4.
Constant patterns:
def describe(x: Any) = x match {
case 5 => "five"
case true => "truth"
case "hello" => "hi!"
case Nil => "the empty list"
case _ => "something else"
}
Scala uses a simple lexical rule for disambiguation: a simple
name starting with a lowercase letter is taken to be a pattern variable; all other references are taken to
be constants.

If that
does not work (because pi is a local variable, say), you can alternatively enclose the variable name in
back ticks. For instance, `pi` would again be interpreted as a constant, not as a variable




Saturday, October 29, 2016

Programming in Scala 7/8/9/10

1.

scala> val someNumbers = List(-11,2,-12,8,9)
scala> someNumbers.filter( x=>x<8 )
scala> someNumbers.filter(_>0)
scala> val f= (_: Int)+(_: Int)
scala> someNumbers.foreach(println _)
 equals
 someNumbers.foreach(x => println(x))
2. closure

 def makeIncreaser(more: Int) = (x: Int) => x + more
3.
 scala> def twice(op: Double => Double, x: Double) = op(op(x))
 scala> twice(_ + 1, 5)
4.
In Scala it is forbidden to define a field and method with the same name in the same class, whereas this is
allowed in Java.
Generally, Scala has just two namespaces for definitions in place of Java's four. Java's four namespaces
are fields, methods, types, and packages. By contrast, Scala's two namespaces are:
• values (fields, methods, packages, and singleton objects)
• types (class and trait names)

Tuesday, October 25, 2016

Programming in Scala Note 4/5/6

1.

The way you make members public in Scala is by not explicitly specifying any access modifier.
Public is Scala's default access level.
2.
one way in which Scala is more object-oriented than Java is that classes in
Scala cannot have static members. Instead, Scala has singleton objects. A singleton object definition
looks like a class definition, except instead of the keyword class you use the keyword object.
A singleton object is more than a holder of static methods, however. It is a first-class object.
One difference between classes and singleton objects is that singleton objects cannot take parameters,
whereas classes can. Because you can't instantiate a singleton object with the newkeyword, you have
no way to pass parameters to it.
3.
in Scala, you
can name .scala files anything you want, no matter what Scala classes or code you put in them.
4. ==First check the left side for null. If it is not null,

call the equals method.
scala> 1==1.0

res8: Boolean = true
5. 
In Java, classes have
constructors, which can take parameters; whereas in Scala, classes can take parameters directly. The

Scala notation is more concise—class parameters can be used directly in the body of the class
6.
 class Rational(n: Int, d: Int) {
require(d != 0)
override def toString = n + "/" + d
}
7. 
In Scala, every auxiliary constructor must invoke another constructor of the same class as its first
action. In a Scala class, only the primary
constructor can invoke a superclass constructor.
8.
 scala> implicit def intToRational(x: Int) = new Rational(x)

Programming in Scala Note Chapter 1/2/3

Chapter 1/2/3
1.

def factorial(x: BigInt): BigInt =
    if (x == 0) 1 else x * factorial(x - 1)
2.
A val is similar to a final variable in Java. Once
initialized, a val can never be reassigned. A var, by contrast, is similar to a non-final variable in Java. 
3.
Sometimes the Scala compiler will require you to specify the result type of a function. If the function
is recursive,[7] for example, you must explicitly specify the function's result type.
If a function consists of just one statement, you can optionally leave off the curly braces.
scala> def max(x: Int, y: Int) = if (x > y) x else y
4.
scala> def greet() = println("Hello, world!")
greet: ()Unit
A result type of Unit indicates the function returns no interesting value.
5.
Note that Java's + +i and i++ don't work in Scala. To increment in Scala, you need to say either i = i + 1 or i += 1.
6.
args.foreach(arg => println(arg))
or   
args.foreach((arg: String) => println(arg))
or
args.foreach(println)
or
for(arg <- args) println(arg)
7.
If the method name ends in a colon, the
method is invoked on the right operand.
8.
The time it takes to append to a list grows linearly with the size of the
list, whereas prepending with :: takes constant time. If you want to build a list efficiently by appending
elements, you can prepend them and when you're done call reverse. Or you can use a ListBuffer, a
mutable list that does offer an append operation, and when you're done call toList.
9.
Once you have a tuple instantiated, you can access its elements individually with a dot,
underscore, and the one-based index of the element.
val pair = (99, "Luftballons")
println(pair._1)
10.
This -> method, which you can invoke on any
object in a Scala program, returns a two-element tuple containing the key and value.
import scala.collection.mutable
val treasureMap = mutable.Map[Int, String]()
treasureMap += (1 -> "Go to island.")
11.
if code contains any vars, it is probably in an imperative style. If the code contains no vars at all—i.e., it
contains only vals—it is probably in a functional style.

Friday, September 30, 2016

My SOAP based web service client development and test note

My SOAP based web service client development and test note:
1. If wsdl is available, SOAP UI is a good tool for the test. If there's error, then use local wsdl file and it could be fixed
2. If SOAP request file is available (you can get it from the server side or SOAP UI), then Apache Common http client is good to post the SOAP request
    to the end point directly:
String strURL = "https://...";
String strSoapAction = "retrieve";
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
RequestEntity entity = new FileRequestEntity(input,
"text/xml; charset=UTF-8");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", strSoapAction);
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);
...
Still, the response could be parsed by JAXB like (Use the regular expression "<soapenv:Body>(.*?)</soapenv:Body>" to get the body part retrieveResponseStr):
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(retrieveResponseStr);
RetrieveResponse retrieveResponse = ((JAXBElement<RetrieveResponse>) unmarshaller
.unmarshal(reader)).getValue();


3. Or SAAJ could be used to construct the SOAP message as this link shows
http://stackoverflow.com/questions/15940234/how-to-do-a-soap-web-service-call-from-java-class
4. The most common way is to generate the client by invoking "wsimport -keep ...", and then
   If need customize SOAP header, then implement javax.xml.ws.handler.soap.SOAPHandler, call service's method setHandlerResolver before getPort
   Be careful not to introduce WAS_V7JAXWS_WEBSERVICES_THINCLIENT if you use IBM RAD. Or you may get error "WSWS7130E: No Secure Sockets Layer (SSL) configuration is available"
   or "IOException: Connection close: Read failed.  Possible end of stream encountered".

TCP/IP monitor in Eclipse cannot support https monitor
I cannot enable Fiddler to monitor Java web service client for https

A weird java web service client error

When I developed web service client in Rational Application Developer, I got the below error:
Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.axis2.AxisFault: WSWS7130E: No Secure Sockets Layer (SSL) configuration is available for the https://... endpoint.

After searching the google, got a useful article "Using Secure Web Services HTTPs (SSL)":
http://btarlton.blogspot.ca/2013/03/ever-have-trouble-using-ssl-to-call-web.html
So I exported the certificate and add the below to VM arguments:
-Djavax.net.ssl.trustStore=C:\temp\myTrustStore -Djavax.net.ssl.trustStorePassword=changeit
Then the error "No Secure Sockets Layer ... " is gone.
However, another error is raised: "java.io.IOException: Connection close: Read failed.  Possible end of stream encountered. "

I searched a lot and tried some ways like setting com.ibm.websphere.webservices.http.requestResendEnabled but still got the error.

Finally I decided to regenerate the client from scratch using wsimport -keep, and copy them into RAD7.5, Phew, everything works perfect.

So what's the problem? I compared the two projects source code until they are all identical through WinMerge. But their behavior are still different.
Then I checked the projects setting in RAD and removed the auto introduced WAS_V7JAXWS_WEBSERVICES_THINCLIENT, now both of them works like a charm.

It's so misleading and confusing for the IDE especially if it involves IBM product. Under such case, should remove the dependency on IDE as much as possible
so that we can isolate the issue.

Sunday, September 25, 2016

My Plan

1. Sleep before/at 11:00 and get up at 6:30
2. Play basketball at Monday & Wednesday evening, 8:15 - 09:45
    swim at Saturday morning 7:00-8:30
3. Push-up and other physical exercise at Tuesday, Thursday and Saturday evening
Runtastic 6 packs and push-up at Tuesday and Thursday
4. Improve English
a. Watch TV more and surf the web less
b. Read English news instead of Chinese news
c. Jerry English 

Saturday, June 18, 2016

Notepad++ replace with regular expression

(\w+),$
logger.info\("\1="+\1\);

aomBeforeChildItemCode,
aomByitmcat,

to

logger.info("aomBeforeChildItemCode="+aomBeforeChildItemCode);
logger.info("aomByitmcat="+aomByitmcat);


Friday, May 27, 2016

Scala SBT error: sun.security.validator.ValidatorException: PKIX path building failed

Environment: 
Windows 7 in the company, no proxy
No installation on Scala SDK

When run "sbt" from command line, got the error:
sun.security.validator.ValidatorException: PKIX path building failed Error ...

The reason is that Java cannot access https website without trusted key store.
The below two articles explained very well and have the detailed solution, after put the key file to folder jre\lib\security, and rerun "sbt", the error is gone. (my concern, why "mvn" has no such error?)

http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/
https://github.com/escline/InstallCert

Thursday, May 19, 2016

mvn archetype:generate does not work-no plugin found

When run the below:
mvn archetype:generate
got the below error:

mvn archetype:generate does not work-no plugin found for prefix 'archetype'

add -X and search metadata.xml:
mvn -X archetype:generate
It cannot get the *metadata.xml from the central repository because of the firewall/certification
although from the web browser the link is accessible:
Two solutions:
1. add settings.xml in the mvn .m2 folder:
<settings>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>securecentral</activeProfile>
  </activeProfiles>
  <profiles>
    <profile>
      <id>securecentral</id>
      <!--Override the repository (and pluginRepository) "central" from the
         Maven Super POM -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
</settings>
2. get and set the certificate file
See:
http://stackoverflow.com/questions/25911623/problems-using-maven-and-ssl-behind-proxy

Monday, May 9, 2016

健身

心肺能力的提高,靠的是长时间的低强度运动,俗称有氧运动,也就是长跑、游泳等。 
我认识一个人,只做俯卧撑,一天做3种变式的俯卧撑,共12组,每组15个,胸肌腹肌分离度和形状都非常棒
【无氧运动的时间】如果是力量训练,实际上时间控制在1小时为最佳,因为男性在进行力量训练的时候,会分泌睾酮,但是睾酮在训练后半小时大幅减少,所以无氧锻炼是前半小时的效率是最高的,因此时间控制在30~60min最好。

蛋清可以多吃,蛋黄一天一个或者两个就够了

https://www.zhihu.com/question/20687290/answer/15853608
最简单的锻炼计划
1.慢跑3~5分钟。总之达到身体微微出汗或者发热的效果即可停止。
2.做仰卧起坐和俯卧撑。
3.然后出去跑5公里,两天或者三天一次。


要保证每天至少7小时的睡眠,让肌肉在睡眠中得到充分的增长。而且每块大肌肉(胸背肩腿)每周练到力竭不要超过两次,小肌肉(手臂、腹部)每周练到力竭不要超过三次。这样能够保证最好的增长。

https://www.zhihu.com/question/19850561/answer/91268580

https://www.zhihu.com/question/29083850/answer/44593248

Sunday, May 1, 2016

How to trace SOAP message in Eclipse IDE

http://www.mkyong.com/webservices/jax-ws/how-to-trace-soap-message-in-eclipse-ide/

1. Endpoint publish
public class HelloWorldPublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorldImpl());
}
}

2. Soap client
public class HelloClient {
public static void main(String[] args) throws Exception {

URL url = new URL("http://localhost:8080/ws/hello?wsdl");
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString("test"));
}
}

3. Eclipse configuration
Hostname: localhost:9999
Local port: 8080

4. Response message:
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.mkyong.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.mkyong.com/" name="HelloWorldImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.mkyong.com/" schemaLocation="http://localhost:9999/ws/hello?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="getHelloWorldAsString">
<part name="parameters" element="tns:getHelloWorldAsString"></part>
</message>
<message name="getHelloWorldAsStringResponse">
<part name="parameters" element="tns:getHelloWorldAsStringResponse"></part>
</message>
<portType name="HelloWorld">
<operation name="getHelloWorldAsString">
<input wsam:Action="http://ws.mkyong.com/HelloWorld/getHelloWorldAsStringRequest" message="tns:getHelloWorldAsString"></input>
<output wsam:Action="http://ws.mkyong.com/HelloWorld/getHelloWorldAsStringResponse" message="tns:getHelloWorldAsStringResponse"></output>
</operation>
</portType>
<binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="getHelloWorldAsString">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="HelloWorldImplService">
<port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
<soap:address location="http://localhost:9999/ws/hello"></soap:address>
</port>
</service>
</definitions>

Wednesday, April 20, 2016

TD Benifit

If you select a registered account:
• your contributions are made with ‘before-tax’ dollars each pay.
• TD’s contributions will go into a Deferred Profit Sharing Plan or DPSP and you will receive a tax
receipt showing TD’s contributions as part of your Pension Adjustment. This amount will reduce
your RSP contribution room for the next year.
If you direct either your own or TD’s contributions into a registered account, you need to ensure you
have available RSP contribution room.
If you select a non registered account…
• your contributions are made with ‘after tax’ dollars.
• TD’s contributions are considered taxable income and you will receive a T4PS slip at tax time.
The Employee Ownership Plan provides flexibility to make changes each calendar quarter.

If you withdraw from an RSP account,
 The amount withdrawn is taxable.
 You’ll receive a tax receipt for your withdrawal amount and you’ll need to report this as
taxable income for the year.
If you withdraw from a non-registered account no tax slip is issued.
• You are responsible for calculating and reporting any capital gains or losses on your TD
Bank shares on your income tax return.
• Please refer to HR Self Service for your annual statements, transaction history and your
withdrawal statement for the information you need to calculate and report you capital gains
or losses.

If you leave TD and…
have been employed by TD for 2 continuous years, you’re entitled
to your total Employee Ownership Plan balance
 have not been employed by TD for 2 continuous years, you can
withdraw your contributions only. TD’s contributions are forfeited.
 If you return to TD within 3 months, you can participate in the
Employee Ownership Plan immediately.

Oracle pl/sql note

DBMS_METADATA
BEGIN DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY', true); END;
DBMS_METADATA.GET_DDL

Oracle 11g new features:
continue support
virtual column
disabled triggers
result cache

The advantage to using RAISE_APPLICATION_ERROR instead of RAISE is that you can associate
an error message with the exception.

SQLERRM will return is 512 bytes, Oracle recommends DBMS_UTILITY.FORMAT_ERROR_STACK
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE --see the error line number

System exception
An exception that is defined by Oracle and is usually raised by the PL/SQL runtime
engine when it detects an error condition. Some system exceptions have names,
such as NO_DATA_FOUND, while many others simply have numbers and
descriptions.
Programmer-defined exception
An exception that is defined by the programmer and is therefore specific to the
application at hand. You can associate exception names with specific Oracle errors
using the EXCEPTION_INIT pragma (a compiler directive, requesting a specific
behavior), or you can assign a number and description to that error using
RAISE_APPLICATION_ERROR.

Associative arrays:
 like hash table
Nested tables:
 unbounded
 become sparse through deletions
 no inherent order to the elements
varrays:
 must specify the max number of elements
 never sparse
 element order is preserved

python note

Java is a statically typed language, i.e. the types are checked and enforced at compile time. In contrast, Python is dynamic which means that the types are checked only at runtime.
Python also supports a rich set of functional programming features and idioms. In Python, functions are first-class objects that can be created, manipulated and passed around just
like any other object.

== is for value equality.
is is for reference equality.

The // operator is also provided for doing floor division no matter what the operands are.
>>> 17 / 3.0  # int / float -> float
5.666666666666667
>>> 17 // 3.0  # explicit floor division discards the fractional part
5.0

Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary.
The interpreter can be used interactively.

ensures they are always cleaned up promptly and correctly.
with open("myfile.txt") as f:
    for line in f:
        print line

comments:
# or """ """


write file:
>>> out=open("data.out","w")
>>> print("Its a write test for Python",file=out)
>>> out.close

try/except/finally
try:
data = open('its.txt', "w")
print("It's...", file=data)
except IOError as err:
print('File error: ' + str(err))
finally:
if 'data' in locals():
data.close()

Sunday, April 17, 2016

在成长的过程中丢弃了最初的美好

很多人都在成长的过程中丢弃了最初的美好,当初执拗的相信童话的孩子永远的走向了成年,抛却了一切童真,行走于这纷扰的世间,为各种各样的事奔波劳碌,但心里总归还是相信美好,周星驰用独特的方式,在俗世中维护了曾经我们每个人那颗纯真的心。

Wednesday, April 13, 2016

Design Patters example in JDK

Swing
EventListener: Observer
BorderFactory: Factory
Look and feel: Abstract Factory


1. Creational Patterns
Factory
BorderFactory.createLineBorder
BorderFactory.createTitledBorder
Factory Method
Calendar.getInstance()
Abstract Factory
SWT control (or JDK look & feel)
IGUIFactory (WinFactory, OSXFactory ...)
IButton (WinButton, OSXButton ...)
if(Win)
createWinButton
Builder (too many parameters)
StringBuffer.append
StringBuilder.append
ProtoType (reduce the class number)
Object.clone() (Cloneable)
Singleton
Runtime.getRuntime()
lazy initialization
eager initialization
static block initialization
static class holder
enum way
NullObject

2. Structural Patterns (Structural patterns are concerned with how classes and objects arecomposed to
form larger structures.Structural class patterns use inheritance to compose
interfacesor implementations.)
Adapter (Convert the interface of a class into another interface clients expect)
InputStreamReader(InputStream): returns a Reader
Arrays.asList
Bridge (TODO):
Composite (Compose objects into tree structures to represent part-whole hierarchies.
Composite lets clients treat individual objects and compositions of object uniformly.)
Container.add: return Component
Decorator (Attach additional responsibilities to an object dynamically. Decorators provide
a flexible alternative to subclassing for extending functionality.):
1. All subclasses of java.io.InputStream, OutputStream, Reader and Writer have a constructor taking an instance of same type.
2. java.util.Collections, the synchronizedXXX() and unmodifiableXXX() methods.
Facade
My example: ACUtils.getResult(String queryStr) return List<String>
Flyweight
Integer.valueOf, Boolean.valueOf
proxy (Provide a surrogate or placeholder for another object to control access to it.)
java.lang.reflect.Proxy (InvocationHandler.newInstance())
rmi/web service

3. Behavioral Patterns (Behavioral patterns are concerned with algorithms and theassignment of
responsibilities between objects. Behavioral patternsdescribe not just patterns
of objects or classes but also the patternsof communication between them.)
Chain of Responsibility (giving morethan one object a chance to handle the request.)
java exception handling, set the processor request
Command (the toolkit can't implement the request
explicitly in the buttonor menu, because only applications that use the toolkit
know whatshould be done on which object.)
java.lang.Runnable
javax.swing.Action
Interpreter
java.text.Format
java.util.Patterns
JavaCC
Iterator
Iterator (has remove method and has a shorter/better method name)
Enumeration
Mediator
Executor.execute
Momento (capture and externalize an object'sinternal state so that the object can be restored to this state later.)
All implementations of java.io.Serializable
xml marshal/unmarshal
Observer
EventListner
State(TODO)
Strategy:
Comparator.compare
Template method
All non-abstract methods of java.util.AbstractList or other class
Visitor
SimpleFileVisitor

Monday, April 11, 2016

晚上打篮球后吃什么

之前不要吃太饱,运动回来后喝一杯温牛奶+香蕉/苹果

一般以减脂塑形为目的,无需很夸张速效地增肌的话,你基本不用理会各种蛋白粉健饮什么的,在健身前1小时吃两根香蕉足以补充热量提供体力支持,而且它的完美之处还在于运动过程中不知不觉保健肠胃,你从心理上更不会觉得摄入过多的糖分和热量,不会还没健身先顶了一身压力。+运动结束以后重点是补水和少量补糖,但是也不要立即这样做,建议在40分钟以后吃一只不那么高糖的水果,喝一杯牛奶。切忌咖啡、茶饮这种消肿利尿加速脱水的饮料,也不要碰那些高糖的碳酸或者果汁饮料&rlz=1C1CAFB_enCA684CA684&oq=一般以减脂塑形为目的,无需很夸张速效地增肌的话,你基本不用理会各种蛋白粉健饮什么的,在健身前1小时吃两根香蕉足以补充热量提供体力支持,而且它的完美之处还在于运动过程中不知不觉保健肠胃,你从心理上更不会觉得摄入过多的糖分和热量,不会还没健身先顶了一身压力。++运动结束以后重点是补水和少量补糖,但是也不要立即这样做,建议在40分钟以后吃一只不那么高糖的水果,喝一杯牛奶。切忌咖啡、茶饮这种消肿利尿加速脱水的饮料,也不要碰那些高糖的碳酸或者果汁饮料

如果是晚饭后再运动的话,且体脂比较高减肥意愿比较强烈,那么:+1、两根香蕉完全可以取代晚餐,并尽量在17:00以前吃,对于大多数人的作息来说,17%3A00以后吃水果(特别是高糖水果,事实上水果都是比较高糖的)都没有太大意义了,而且这些糖分很难解决掉,所以有些东西即便好,也不是怎么吃随时吃都好。+2、18:00~20%3A00之间解决你今天以内所剩的运动量,不要再拖后,否则得不偿失,原因说过了如果你已经长时间习惯晚睡,那么运动时间最多可以拖到21%3A00.+3、晚练过后不比白天,没有多久就睡觉了,运动完40分钟以后你只需要一杯补养助眠的温牛奶,如果你实在饿到不行了,牛奶根本欺骗不了你的胃,那么,你最好也只吃一些水煮的蔬菜(胡萝卜、花椰菜、白菜等),少许。&rlz=1C1CAFB_enCA684CA684&oq=如果是晚饭后再运动的话,且体脂比较高减肥意愿比较强烈,那么:+1、两根香蕉完全可以取代晚餐,并尽量在17:00以前吃,对于大多数人的作息来说,17%3A00以后吃水果(特别是高糖水果,事实上水果都是比较高糖的)都没有太大意义了,而且这些糖分很难解决掉,所以有些东西即便好,也不是怎么吃随时吃都好。+2、18:00~20%3A00之间解决你今天以内所剩的运动量,不要再拖后,否则得不偿失,原因说过了如果你已经长时间习惯晚睡,那么运动时间最多可以拖到21%3A00.+3、晚练过后不比白天,没有多久就睡觉了,运动完40分钟以后你只需要一杯补养助眠的温牛奶,如果你实在饿到不行了,牛奶根本欺骗不了你的胃,那么,你最好也只吃一些水煮的蔬菜(胡萝卜、花椰菜、白菜等),少许。

根据描述,楼主是一位运动爱好者,爱好各种体育锻炼,但是很少进入健身房进行大重量的肌肉刺激生长训练,那像蛋白质粉、大量鸡蛋清这类高蛋白食品并不适合楼主,并且,楼主的锻炼时间偏晚,如果晚上12睡觉的话,运动之后2小时就要睡觉,此时非常不适合摄入大量蛋白质,身体短时间内无法消化吸收这么多蛋白质,而且睡眠中残留在肠胃的食物对消化系统有损伤。+楼主的锻炼时间正好在晚饭后2小时,并不需要额外摄入能量,晚饭多吃点碳水化合物主食和高蛋白食物就可以了,碳水化合物可以提供充足的能量供应,高蛋白食物(瘦肉、鱼类、鸡蛋)可以确保你的肌肉中的蛋白质含量充足,在剧烈运动时蛋白质的消耗也是很大的,如果蛋白质补充不足,越练越瘦也是可能的。+运动之后食用一些水果,比如香蕉,短时间内提供能量,苹果、草莓、梨什么的家常水果提供充足矿物质和维生素帮助你的身体恢复,调节体内PH值。不要喝果汁、咖啡、巧克力和碳酸饮料,那里面的成分除了糖之外,剩下的维生素含量没多少。如果哪天运动量很大,饿的不行,吃一些低脂的能量食物,如全麦面包,少量鸡蛋清也OK,+睡前一包牛奶,提高睡眠质量,提供适量钙质、蛋白质,利于身体恢复,防止肌肉抽筋。&rlz=1C1CAFB_enCA684CA684&oq=根据描述,楼主是一位运动爱好者,爱好各种体育锻炼,但是很少进入健身房进行大重量的肌肉刺激生长训练,那像蛋白质粉、大量鸡蛋清这类高蛋白食品并不适合楼主,并且,楼主的锻炼时间偏晚,如果晚上12睡觉的话,运动之后2小时就要睡觉,此时非常不适合摄入大量蛋白质,身体短时间内无法消化吸收这么多蛋白质,而且睡眠中残留在肠胃的食物对消化系统有损伤。+楼主的锻炼时间正好在晚饭后2小时,并不需要额外摄入能量,晚饭多吃点碳水化合物主食和高蛋白食物就可以了,碳水化合物可以提供充足的能量供应,高蛋白食物(瘦肉、鱼类、鸡蛋)可以确保你的肌肉中的蛋白质含量充足,在剧烈运动时蛋白质的消耗也是很大的,如果蛋白质补充不足,越练越瘦也是可能的。+运动之后食用一些水果,比如香蕉,短时间内提供能量,苹果、草莓、梨什么的家常水果提供充足矿物质和维生素帮助你的身体恢复,调节体内PH值。不要喝果汁、咖啡、巧克力和碳酸饮料,那里面的成分除了糖之外,剩下的维生素含量没多少。如果哪天运动量很大,饿的不行,吃一些低脂的能量食物,如全麦面包,少量鸡蛋清也OK,+睡前一包牛奶,提高睡眠质量,提供适量钙质、蛋白质,利于身体恢复,防止肌肉抽筋。

Tuesday, April 5, 2016

中山大学公开课 头痛

中山大学公开课 头痛
闫振文 中山大学孙逸仙纪念医院  神经科 

http://yanzhenwen.haodf.com/
yanzhw@mail.sysu.edu.cn

http://gangli2008.haodf.com/payment/newintro

跟月经期没关系,每年发作一两次或更多,每次疼痛持续一个月或更长。前额头附近疼痛,全身无力,双腿发软发抖

原发性头痛 78%
     找不到病因,偏头痛、紧张性头痛、丛急性头痛
继发性头痛 13%  (头痛只是一部分)
     颅内肿瘤、过度使用药物等引起
其它头痛
    三叉神经痛等

1. 偏头痛,几十年反复发作,伴有呕吐,呕吐之后会缓解
大部分是偏侧,但也有很多是双侧。偏爱于女性
40岁较多,60岁后极少
月经前后易发作,头痛期 4-72小时,发作期有没有什么先兆?(怕吵,眼发麻,言语不流利,锯齿形闪光或视觉扭曲)
2. CT:检查方便,安全快速,外伤
   MRI(磁共振):看到的病灶更加清晰,可检测脑白质异常、肿瘤等

丛急性头痛,较少见,很有规律,剧痛,男性为多
紧张性头痛:轻到中度,日常活动不加重,无恶心和呕吐,畏光畏声,一般为双侧头痛,布袋子捂住一样的痛
偏头痛:
      有时候有先兆,有时候无先兆,中到重度
       痛的时候捂住太阳穴这个地方,畏声畏光,活动会加重,搏动性头痛(一跳一跳的痛),恶心或呕吐(有的不呕吐),劳动能力下降

       偏头痛患者的体格检查往往没有异常发现
       偏头痛是目前无法根治但可以有效控制的疾患

慢性每日头痛,每月超过15天,每天超过4小时



诱发因素,头痛日记,以前吃过什么药
有无抑郁,焦虑,睡眠问题
(睡眠问题引起头痛,还是头痛引起失眠)
头痛部位,头痛时间与分布
上次就诊时间,何时做过哪些检查
头痛的性质程度怎样,如刀割样、烧灼样、刺痛、跳痛、胀痛、还是爆裂样痛;头痛加重和缓解的因素。

同时要提供与头痛伴发的症状,也即各种原发病的应有症状:如有无伴随引起颅内严重病变的恶心、呕吐、意识障碍、神经系统症状(肢体无力、麻木、抽搐、视力障碍)等,有无引起头颈部病变的五官症状(流泪、鼻阻、流涕)等,有无发热等全身性疾病的症状,有无失眠、多梦、多虑、焦虑、恐惧、抑郁等神经官能症症状,防止遗漏早期的严重病变。

Web service summary

JAVA 中共有三种WebService 规范,分别是JAXM&SAAJ、JAX-WS(JAX-RPC)、JAX-RS
1. JAX-WS:
JAX-WS(Java API For XML-WebService),JDK1.6 自带的版本为JAX-WS2.1,其底层支
持为JAXB。
JAX-WS(JSR 224)规范的API 位于javax.xml.ws.*包,其中大部分都是注解,提供API 操
作Web 服务(通常在客户端使用的较多,由于客户端可以借助SDK 生成,因此这个包中的
API 我们较少会直接使用)。
WS-MetaData(JSR 181)是JAX-WS 的依赖规范,其API 位于javax.jws.*包,使用注解配
置公开的Web 服务的相关信息和配置SOAP 消息的相关信息。
2. JAXM&SAAJ:
JAXM(JAVA API For XML Message)主要定义了包含了发送和接收消息所需的API,相当
于Web 服务的服务器端,其API 位于javax.messaging.*包,它是JAVA EE 的可选包,因此
你需要单独下载。
SAAJ(SOAP With Attachment API For Java,JSR 67)是与JAXM 搭配使用的API,为构建
SOAP 包和解析SOAP 包提供了重要的支持,支持附件传输,它在服务器端、客户端都需要
使用。这里还要提到的是SAAJ 规范,其API 位于javax.xml.soap.*包。
JAXM&SAAJ 与JAX-WS 都是基于SOAP 的Web 服务,相比之下JAXM&SAAJ 暴漏了SOAP
更多的底层细节,编码比较麻烦,而JAX-WS 更加抽象,隐藏了更多的细节,更加面向对
象,实现起来你基本上不需要关心SOAP 的任何细节。那么如果你想控制SOAP 消息的更
多细节,可以使用JAXM&SAAJ,目前版本为1.3。
3. JAX-RS:
JAX-RS 是JAVA 针对REST(Representation State Transfer)风格制定的一套Web 服务规范,
由于推出的较晚,该规范(JSR 311,目前JAX-RS 的版本为1.0)并未随JDK1.6 一起发行,
你需要到JCP 上单独下载JAX-RS 规范的接口,其API 位于javax.ws.rs.*包。
这里的JAX-WS 和JAX-RS 规范我们采用Apache CXF 作为实现,默认CXF
是依赖于Spring 的,Bus 都有一个ID,默认的BUS 的ID 是cxf。你要注意的是Apache CXF
2.2 的发行包中的jar 你如果直接全部放到lib 目录,那么你必须使用JDK1.6,否则会报
JAX-WS 版本不一致的问题。对于JAXM&SAAJ 规范我们采用JDK 中自带的默认实现。


1. JAX-WS:
@WebService
public interface IHelloService
...
使用类级别注解@WebService 就标注了这个接口的方法
将公开为Web 服务,使用了这个注解的接口的所有方法都将公开为Web 服务的操作,如果
你想屏蔽某个方法,可以使用方法注解@Method 的exclude=true。我们也通常把公开为Web
服务的接口叫做SEI(Service EndPoint Interface)服务端点接口。

public class HelloServiceImpl implements IHelloService
这个实现类没有任何特殊之处,但是如果你的实现类还实现了其他的接口,那么你需要在实
现类上使用@WebService 注解的endpointInterface 属性指定那个接口是SEI(全类名)

Endpoint.publish("http://127.0.0.1:8080/helloService",
new HelloServiceImpl());
你可能会差异,我们没有
借助Tomcat 这样的Web 服务器,直接运行一个main 方法是怎么发布的Web 服务呢?其实
CXF 内置了Jetty(Servlet 容器),因此你不需要将你的程序部署到Tomcat 等Web 服务器
也可以正常发布Web 服务。

如果你的某些注解的header=true,那么它将被放到
<soap:Header …中传输,而不是SOAP 消息正文
如果是OUT、INOUT 类型的参数类型,这样的方法参数将会被当做返回值在Web 服务调
用完成后返回给你,客户端生成代码时会被转变为javax.xml.ws.Holder<T>类

JAX-WS 中的服务端的自定义异常使用javax.xml.ws.WebFault 注解来完成,这样的异常会在
WSDL 文件中的<wsdl:operation …中的子元素生成<wsdl:fault …

2. JAVA的 WebService规范 JAX-RS
REST 是一种软件架构模式,只是一种风格,不是像SOAP 那样本身承载着一种消息协议,
(两种风格的Web 服务均采用HTTP 做传输协议是因为HTTP 协议能穿越防火墙,JAVA
的远程调用RMI 等是重量级协议,不能穿越防火墙)
。REST 中重要的两个概念就是资源定位和资源操作,而HTTP 协议恰好完
整的提供了这两个要点,HTTP 协议中的URI 可以完成资源定位,GET、POST、OPTION
等方法可以完成资源操作,因此REST 完全依赖HTTP 协议就可以完成Web 服务,而不像
SOAP 协议那样只利用HTTP 的传输特性,定位与操作由SOAP 协议自身完成,也正是由于
SOAP 消息的存在,使得SOAP 笨重。你也可以说REST 充分利用了HTTP 协议的特性,而
不是像SOAP 那样只利用了其传输这一特性
REST 简单易用,
效率高,SOAP 成熟度较高,安全性较好。
REST 提供的网络服务叫做OpenAPI,它不仅把HTTP 作为传输协议,也作为处理数据的工
具,可以说对HTTP 协议做了较好的诠释,充分体现了HTTP 技术的网络能力。目前Google、
Amazon、淘宝都有基于REST 的OpenAPI 提供调用。
JAX-RS 的API 在javax.ws.rs.*包中,其中大部分也是注解。
访问REST 风格的Web 服务很简单,你完全不需要像SOAP 使用SDK 生成客户端代码,因
为REST 完全依赖HTTP 协议, 从这里可见REST 是轻量级的。
你可
以用((HttpURLConnection)new URL(“***”).openConnection()).getInputStream()获取,然
后使用程序处理这个接收到的结果。为了更加好的使用HTTP 访问REST 服务,推荐你使用Apache HttpComponents-Client 组件进行HTTP 操作,因为这里使用的示例是GET 方法的请
求,你是用URL 直接访问或者使用java.net.URL 类来访问很容易,但是如果Web 服务的方
法使用@PUT 等注解,那么你就需要费一番头脑来在请求报头中加入要请求的方法类型等
信息,这些是很繁琐的事情
前面我们都是使用了HTTP-Components-Client 的API 来访问REST 服务,这也是比较干净
的方式,所谓干净就是完全依赖HTTP 的API(其实更加干净的方式就是使用JAVA 自带的
HTTP 的API 操作) , 但是过于干净的调用方式总会很麻烦( 很明显使用
HTTP-Components-Client 要比java.net.*下面的API 要来得简单),其实CXF 自带的
org.apache.cxf.jaxrs.client.WebClient 用起来更加简单。
常用的安全策略机制:
I.传统的用户名令牌机制:
Apache WSS4J(WebService Security For Java)实现了JAVA 语言的WS-Security,CXF 中使
用WSS4J 也是很容易的,WSS4J 依赖于SAAJ。
II.数字签证方法:
除了UsernameToken 这种传统的安全机制,常用的验证动作还有一个就是使用数字签证技
术(X.509 Certificates),
III.混合验证方法:
WSS4J 支持如下几种验证模式:
XML Security
XML Signature
XML Encryption
这两种验证模式都是使用数字签证技术。
Tokens
Username Tokens
Timestamps
SAML Tokens

Web 服务的调用默认都是阻塞调用,但是JAX-WS 也支持异步调用。
因为在Future 的get()方法被调用之前,它不会产生阻
塞,这样你可以在方法执行的最后再去获取异步计算的结果。那么你可能会问,这样整个方
法还是不能算作完全的异步调用,因为最后要返回值的时候还是会阻塞哦!其实有返回值的
Web 服务调用本就不应该使用异步调用,因为返回值通常你都是要拿回来立即使用的。这
种异步调用机制适合于无返回值的Web 服务调用,这样你就不需要再调用Future 的get()方
法了。
如果你想有返回值的时候也进行异步调用,那么就只能使用最原始的开启新的线程的方法,
也就是将Web 服务方法的调用放在run()方法中执行。

实SAAJ 提供的API 就是用于组装和解构
SOAP 消息的。

使用JAXM发布Web服务:
JAXM 的API 实际上就是用来将一个Servlet 发布成WebService 的地址,它要求你的Servlet
继承javax.xml.messaging.JAXMServlet 并实现javax.xml.messaging.ReqRespListener 接口(如
果Web 服务是单向的, 也就是没有返回值给客户端, 那么可以实现
javax.xml.messaging.OnewayListener 接口),其实这一个抽象类和两个接口是我们可以使用
的三个JAXM 的API,其余的基本上都是JAXM 底层实现需要使用的API,我们并不需要
关心。
在实际应用中,你可以把你的业务层放在onMessage()方法中调用,相当于把业务层的方法
用这个Servlet 包装成了Web 服务,这个Servlet 不可以使用普通的方式访问,只能使用
SoapConnection 的call()方法调用。
实际上你可以看出来,JAXM 发布的Web 服务比较简单,完全省略了WSDL,这也就是说,
你用这种方式发布Web 服务,必须把要接收的Soap 消息的内容说明发布出来(有点儿类似
于REST 风格的OpenAPI),这样客户端才知道如何组装你想要的SOAP 消息。从这里你也
可以看出来,HTTP 协议与SOAP 消息是基于SOAP 的基本组成,WSDL 是完全可以没有的,
WSDL 的作用是异构平台为了方便使用自己的语言特性的中间桥梁。




Sunday, April 3, 2016

健身计划

每周日总结一下
11:00睡觉,6:30起床
  1. 周一、周三打篮球
回来立即泡衣服洗澡,11:30前睡觉

  1. 周二、周四深蹲
  2. 周五游泳或跑步
  3. 周六健步或深蹲

Tuesday, March 22, 2016

Design patterns example in JDK and work experience

Creational:
1. Abstract Factory
Swing pluggable look-and-feel classes
2. Builder
StringBuilder.append
3. Factory Method
Calendar.getInstance()
ResourceBundle.getBundle()
4. Prototype
Object.clone()
5. Singleton
Runtime.getRuntime()
Desktop.getDesktop()

Structural:
1. Adapter
Arrays.asList()
InputStreamReader
2. Bridge
3. Composite
nested containers in AWT/Swing
4. Decorator
BufferedInputStream (FileInputStream)
5. Facade

6. Flyweight
Integer.valueOf (-128 -127)
connection pool
7. Proxy
java.lang.reflect.Proxy
java.rmi.*

Behavioral
1. Chain of Resonsibility
Logger.log
Servlet filters
2. Command
Runnable
3. Interpreter
JavaCC
4. Iterator
All implementations of Iterator
5. Mediator
Executor.execute
Method.invoke
6. Memento

7. Observer
Observable
EventListener
8. State
9. Strategy
Comparator.compare()
Layout Managers in AWT/Swing
10.Template Method
non-abstract methods of AbstractList
11. Visitor
SimpleFileVisitor

Tuesday, March 15, 2016

JQuery

1. ID selector and class selector in jQuery:

$("#LoginTextBox") -- Returns element wrapped as jQuery object with id="LoginTextBox" $(".active") -- Returns all elements with CSS class active.
2. How do you find all selected options of HTML select tag?
You can use following jQuery selector to retrieve all selected options of <select> tag with multiple=true :
$('[name=NameOfSelectedTag] :selected')

$('[name=NameOfSelectedTag] :selected').each(function(selected){
        alert($(selected).text());
});

3.
What is difference between detach() and remove() method in jQuery? (answer)
Though both detach() and remove() method is used to remove a DOM element,Main difference between them is that detach() keep track of the last element detached, so that it can be reattached, while remove() method does keep reference of last removed method. This is one of the many jQuery interview question from DOM manipulation. You can also take a look on appendTo() for adding element into DOM.
4.
How do you add and remove CSS classes to an element using jQuery? (answer)
By using addClass() and removeClass() jQuery methods. 

5.
What is difference between jQuery.get() and jQuery.ajax() method?
ajax() method is more powerful and configurable, allows you to specify how long to wait and how to handle error, get() is a specialization to over ajax just to retrieve some data.