??xml version="1.0" encoding="utf-8" standalone="yes"?>
1.下蝲
http://activemq.apache.org/download.html
2.解压
下载下来的apache-activemq-5.2.0-bin.tar.gz攄?usr/local
cd /usr/local/
tar xvfz apache-activemq-5.2.0-bin.tar.gz
则ActiveMQ的安装目录ؓQ?usr/local/apache-activemq-5.2.0
3.修改activemqq行文g的权?br />
cd /usr/local/apache-activemq-5.2.0/bin
chmod 755 activemq
4.q行
(1).普通启?br />
bin/activemq
(2).指定日志文g的启动方?br />
bin/activemq >/tmp/smlog 2>&1 &
(3)后台启动方式
nohup bin/activemq >/tmp/smlog 2>&1 &
q里需要注意:前两U启动方式在linix命o行或者通过ssh客户端启动时在关闭对应的H口时activemq会关闭,甚至直接ctrl+c也会Dactivemq退出;W三U则不会出现q种情况?br />
5.验证服务端是否开启,有几U方?br />
(1).查看控制台输出或者日志文?br />
(2).直接讉Kactivemq的管理页面:http://localhost:8161/admin/
6.关闭activemq
如果开启方式是使用(1)?2)Q则直接ctrl+c或者关闭对应的l端卛_
如果开启方式是(3),则稍微麻烦一点:
先查扑ֈactivemq对应的进E:
ps -ef | grep activemq
然后把对应的q程杀掉,假设扑ֈ的进E编号ؓ 168168
kill 168168
]]>
]]>
在CXF服务端配|WEB SERVICEӞ通常会包含一些来此cxf.jar里面的XML文gQ用于自动配|需要用到的BEAN
例如Q?/p>
但是在客L配置的时候这些文件是不需要的Q甚至配|会引发错误Q详l的l过见下文?/p>
l过Q?/font>
今天在配|客L的时候,步骤和内定w是和往怸LQ但?/p>
出现一个NullPointerException 的错误,只知道这个错误是在创建客Lservice的时候出的错Q但是原因找不到?/p>
错误堆栈Q?/p>
直到后来我单独加载了创徏客户端service的applicationContextӞ初始化是正常的,所以就怀疑配|文件出了问题;
当上面提到的几个被包含进来的文g的配|被删除后,一切就正常了?/p>
现象Q?/p>
在Web harvest中用httph去获取某个远E的XMLQ此XML的特征是无文件头(x有编码描q等关键信息)Q采用了多种办法去获取,出现qQ无法解析成我们需要的数据?/p>
办法Q?/p>
(1)最原始办法Q?/font>使用Java中的URLConnectionQInputStream{类d字节,构造字W串Q?/p>
(2)最好的办法Q?/font>直接使用dom4j中的SAXReader 非常单,q编码都不用! 其中Qlink为需要获取XML的地址
]]>
最q这几天都在使用CXF作ؓwebservice的组Ӟ试图公开的webservice加入C护的范围内?/p>
dC护的Ҏ(gu)有三U:
(1)指定地址讉KQ即指定一些IP地址Q只有这些地址的请求我们的接口才处理?/font>
q种Ҏ(gu)我在开发中有用到Q可以通过WEB容器中的FiltercL实现Q?/p>
只需要检查请求的地址是否在我们指定的地址列表中就可以了?/p>
优点:处于h响应铄前端Q响应非常迅速,所以消耗的资源很少?/p>
~端Q?/font>使用q种Ҏ(gu)只能查指定地址的请求,通常只能应用的小范围内,如局域网?/p>
另外使用q种验证Ҏ(gu)Q无法进行权限的查,一旦通过验证可以执行所有公开的接口?/p>
(2)用户?密码寚w证,使用指定的用户名密码q行验证
q种Ҏ(gu)适合于具体用L查,q而可以检查其是否有权限执行其h的操?
优点Q?/span>可以只准地查用P甚至验证权限?/p>
~点Q?/span>q种方式不能和WEB应用的登录一P只需要验证一ơ就可以了;必须 每个h都检查,如果需要用这U方法去做,q需要处理好cMd/退出机制?/p>
(3)使用HTTPSq行验证Q这U方法应该也可以具体的验证证书来自哪个用Pq而检查其权限?/font> 优点Q?/font>安全更有保证 ~点Q?/font>配置复杂Q对客户端程序员要求很比较高?/p>
注意事项Q?/font> 使用CXFq行WEBService交互Ӟ特别是进行客L工作Ӟ最好将服务端和客户端的环境剥离开来?/p>
q几天的工作教会了我q个事情(今天上午在测试客L代码时出现莫名其妙的错,最后发现是JAR包冲H, 在服务器的环境中q行客户端程序时Q程序加载了q时的JAR)?/p>
其媄响主要表现在两方面:
(1)Ҏ(gu)E确定过E的影响
在通过分析|站地图的方式去定程Q对专业化程度不是那么高的网站而言Q其|站分类、列表方式基本基本都采用链接的方式,q样在流E实现是很容易就可获取需要的链接Q而对专业化程度较高的|站而言Q在分类下往往通过搜烦、javascript(包括AJAX)页的方式来陈列同类记录Q这在流E实现的时候,需要程序员d析一些javascript函数所做的操作Q去猜度相关列表方式的URL(如搜索的表单如何提交、翻函数如何处理翻늭)?/p>
(2)对获取详l信息过E的影响
在获取详l信息的时候,基本都是通过分心详细信息面的结构出发的?/p>
对专业化E度高的|站而言Q详l信息页面的的制作也是投入了一些精力的Q通常都规定和面特定的位|显C特定的信息Q这样就便于在分析过E中获取指定的数据?/p>
而对专业化程度稍低的|站而言Q详l页面的内容很多都是用HTML~辑器直接编辑出来的内容Q在同一频道的不同分cȝ详细信息面中存在着很大的差异,q得获取详l信息部分的分析E序复杂度倍增?/p>
个h的美好愿望:宁愿分析的是专业化程度高一点的站点Q因为流E的定及具体实现L可以惛_办法解决的;详细信息的分析存在太多页面结构的话,在获取详细信息付出太大代h(hun)Q?/p>
q里需要注意的有几个地?/strong>:
1:需要指定http-conf名称I间 xmlns:http-conf=http://cxf.apache.org/transports/http/configuration
2:指定模式位置: http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
3:http-conf:conduit中的name属?指定讄生效的服?如例子中,只对服务名ؓ{http://impl.service.product.sww.com/}ProjectService的服务生?
使用下面的设|则会对所有服务生?br />
更详l的配置请参考CXF官方文档:
http://cwiki.apache.org/CXF20DOC/client-http-transport-including-ssl-support.html
Whether you program regularly in Java, and know it like the back of your hand, or whether you're new to the language or a casual programmer, you'll make mistakes. It's natural, it's human, and guess what? You'll more than likely make the same mistakes that others do, over and over again. Here's my top ten list of errors that we all seem to make at one time or another, how to spot them, and how to fix them.
Many programmers, particularly when first introduced to Java, have problems with accessing member variables from their main method. The method signature for main is marked static - meaning that we don't need to create an instance of the class to invoke the main method. For example, a Java Virtual Machine (JVM) could call the class MyApplication like this :-
MyApplication.main ( command_line_args );
This means, however, that there isn't an instance of MyApplication - it doesn't have any member variables to access! Take for example the following application, which will generate a compiler error message.
public class StaticDemo { public String my_member_variable = "somedata";
public static void main (String args[]) { // Access a non-static member from static method System.out.println ("This generates a compiler error" + my_member_variable ); } }
If you want to access its member variables from a non-static method (like main), you must create an instance of the object. Here's a simple example of how to correctly write code to access non-static member variables, by first creating an instance of the object.
public class NonStaticDemo { public String my_member_variable = "somedata"; public static void main (String args[]) { NonStaticDemo demo = new NonStaticDemo(); // Access member variable of demo System.out.println ("This WON'T generate an error" + demo.my_member_variable ); } }
Overriding allows programmers to replace a method's implementation with new code. Overriding is a handy feature, and most OO programmers make heavy use of it. If you use the AWT 1.1 event handling model, you'll often override listener implementations to provide custom functionality. One easy trap to fall into with overriding, is to mistype the method name. If you mistype the name, you're no longer overriding a method - you're creating an entirely new method, but with the same parameter and return type.
public class MyWindowListener extends WindowAdapter { // This should be WindowClosed public void WindowClose(WindowEvent e) { // Exit when user closes window System.exit(0); } });
Compilers won't pick up on this one, and the problem can be quite frustrating to detect. In the past, I've looked at a method, believed that it was being called, and taken ages to spot the problem. The symptom of this error will be that your code isn't being called, or you think the method has skipped over its code. The only way to ever be certain is to add a println statement, to record a message in a log file, or to use good trace debugger (like Visual J++ or Borland JBuilder) and step through line by line. If your method still isn't being called, then it's likely you've mistyped the name.
This is an easy error to make. If you're used other languages before, such as Pascal, you'll realize just how poor a choice this was by the language's designers. In Pascal, for example, we use the := operator for assignment, and leave = for comparison. This looks like a throwback to C/C++, from which Java draws its roots.
Fortunately, even if you don't spot this one by looking at code on the screen, your compiler will. Most commonly, it will report an error message like this : "Can't convert xxx to boolean", where xxx is a Java type that you're assigning instead of comparing.
When we use the == operator, we are actually comparing two object references, to see if they point to the same object. We cannot compare, for example, two strings for equality, using the == operator. We must instead use the .equals method, which is a method inherited by all classes from java.lang.Object.
Here's the correct way to compare two strings.
String abc = "abc"; String def = "def"; // Bad way if ( (abc + def) == "abcdef" ) { ...... }
// Good way if ( (abc + def).equals("abcdef") ) { ..... }
This can be a frustrating problem to diagnose, because when you look at the code, you might be sure that its passing by reference, but find that its actually being passed by value. Java uses both, so you need to understand when you're passing by value, and when you're passing by reference.
When you pass a primitive data type, such as a char, int, float, or double, to a function then you are passing by value. That means that a copy of the data type is duplicated, and passed to the function. If the function chooses to modify that value, it will be modifying the copy only. Once the function finishes, and control is returned to the returning function, the "real" variable will be untouched, and no changes will have been saved. If you need to modify a primitive data type, make it a return value for a function, or wrap it inside an object.
When you pass a Java object, such as an array, a vector, or a string, to a function then you are passing by reference. Yes - a String is actually an object, not a primitive data type. So that means that if you pass an object to a function, you are passing a reference to it, not a duplicate. Any changes you make to the object's member variables will be permanent - which can be either good or bad, depending on whether this was what you intended.
On a side note, since String contains no methods to modify its contents, you might as well be passing by value.
I know it's very tempting to write blank exception handlers, and to just ignore errors. But if you run into problems, and haven't written any error messages, it becomes almost impossible to find out the cause of the error. Even the simplest exception handler can be of benefit. For example, put a try { .. } catch Exception around your code, to catch ANY type of exception, and print out the message. You don't need to write a custom handler for every exception (though this is still good programming practice). Don't ever leave it blank, or you won't know what's happening.
For example
public static void main(String args[]) { try { // Your code goes here.. } catch (Exception e) { System.out.println ("Err - " + e ); } }
If you've come from a C/C++ background, you may not find this quite as much a problem as those who have used other languages. In Java, arrays are zero-indexed, meaning that the first element's index is actually 0. Confused? Let's look at a quick example.
// Create an array of three strings String[] strArray = new String[3]; // First element's index is actually 0 strArray[0] = "First string"; // Second element's index is actually 1 strArray[1] = "Second string"; // Final element's index is actually 2 strArray[2] = "Third and final string";
In this example, we have an array of three strings, but to access elements of the array we actually subtract one. Now, if we were to try and access strArray[3], we'd be accessing the fourth element. This will case an ArrayOutOfBoundsException to be thrown - the most obvious sign of forgetting the zero-indexing rule.
Other areas where zero-indexing can get you into trouble is with strings. Suppose you wanted to get a character at a particular offset within a string. Using the String.charAt(int) function you can look this information up - but under Java, the String class is also zero-indexed. That means than the first character is at offset 0, and second at offset 1. You can run into some very frustrating problems unless you are aware of this - particularly if you write applications with heavy string processing. You can be working on the wrong character, and also throw exceptions at run-time. Just like the ArrayOutOfBoundsException, there is a string equivalent. Accessing beyond the bounds of a String will cause a StringIndexOutOfBoundsException to be thrown, as demonstrated by this example.
public class StrDemo { public static void main (String args[]) { String abc = "abc"; System.out.println ("Char at offset 0 : " + abc.charAt(0) ); System.out.println ("Char at offset 1 : " + abc.charAt(1) ); System.out.println ("Char at offset 2 : " + abc.charAt(2) ); // This line should throw a StringIndexOutOfBoundsException System.out.println ("Char at offset 3 : " + abc.charAt(3) ); } }
Note too, that zero-indexing doesn't just apply to arrays, or to Strings. Other parts of Java are also indexed, but not always consistently. The java.util.Date, and java.util.Calendar classes start their months with 0, but days start normally with 1. This problem is demonstrated by the following application.
import java.util.Date; import java.util.Calendar; public class ZeroIndexedDate { public static void main (String args[]) { // Get today's date Date today = new Date(); // Print return value of getMonth System.out.println ("Date.getMonth() returns : " + today.getMonth()); // Get today's date using a Calendar Calendar rightNow = Calendar.getInstance(); // Print return value of get ( Calendar.MONTH ) System.out.println ("Calendar.get (month) returns : " + rightNow.get ( Calendar.MONTH ));
} }
Zero-indexing is only a problem if you don't realize that its occurring. If you think you're running into a problem, always consult your API documentation.
When writing multi-threaded applications, many programmers (myself included) often cut corners, and leave their applications and applets vulnerable to thread conflicts. When two or more threads access the same data concurrently, there exists the possibility (and Murphy's law holding, the probability) that two threads will access or modify the same data at the same time. Don't be fooled into thinking that such problems won't occur on single-threaded processors. While accessing some data (performing a read), your thread may be suspended, and another thread scheduled. It writes its data, which is then overwritten when the first thread makes its changes.
Such problems are not just limited to multi-threaded applications or applets. If you write Java APIs, or JavaBeans, then your code may not be thread-safe. Even if you never write a single application that uses threads, people that use your code WILL. For the sanity of others, if not yourself, you should always take precautions to prevent concurrent access to shared data.
How can this problem be solved? The simplest method is to make your variables private (but you do that already, right?) and to use synchronized accessor methods. Accessor methods allow access to private member variables, but in a controlled manner. Take the following accessor methods, which provide a safe way to change the value of a counter.
public class MyCounter { private int count = 0; // count starts at zero public synchronized void setCount(int amount) { count = amount; } public synchronized int getCount() { return count; } }
This is one of the most frequent errors that we all make. It's so simple to do, and sometimes one can look at an uncapitalized variable or method and still not spot the problem. I myself have often been puzzled by these errors, because I recognize that the method or variable does exist, but don't spot the lack of capitalization.
While there's no silver bullet for detecting this error, you can easily train yourself to make less of them. There's a very simple trick you can learn :-
If you use this pattern for all of your member variables and classes, and then make a conscious effort to get it right, you can gradually reduce the number of mistakes you'll make. It may take a while, but it can save some serious head scratching in the future.
Null pointers are one of the most common errors that Java programmers make. Compilers can't check this one for you - it will only surface at runtime, and if you don't discover it, your users certainly will.
When an attempt to access an object is made, and the reference to that object is null, a NullPointerException will be thrown. The cause of null pointers can be varied, but generally it means that either you haven't initialized an object, or you haven't checked the return value of a function.
Many functions return null to indicate an error condition - but unless you check your return values, you'll never know what's happening. Since the cause is an error condition, normal testing may not pick it up - which means that your users will end up discovering the problem for you. If the API function indicates that null may be returned, be sure to check this before using the object reference!
Another cause is where your initialization has been sloppy, or where it is conditional. For example, examine the following code, and see if you can spot the problem.
public static void main(String args[]) { // Accept up to 3 parameters String[] list = new String[3]; int index = 0; while ( (index < args.length) && ( index < 3 ) ) { list[index++] = args[index]; } // Check all the parameters for (int i = 0; i < list.length; i++) { if (list[i].equals "-help") { // ......... } else if (list[i].equals "-cp") { // ......... } // else ..... } }
This code (while a contrived example), shows a common mistake. Under some circumstances, where the user enters three or more parameters, the code will run fine. If no parameters are entered, you'll get a NullPointerException at runtime. Sometimes your variables (the array of strings) will be initialized, and other times they won't. One easy solution is to check BEFORE you attempt to access a variable in an array that it is not equal to null.
These errors represent but some of the many that we all make. Though it is impossible to completely eliminate errors from the coding process, with care and practice you can avoid repeating the same ones. Rest assured, however, that all Java programmers encounter the same sorts of problems. It's comforting to know, that while you work late into the night tracking down an error, someone, somewhere, sometime, will make the same mistake!
We'd like to thank the readers of the comp.lang.java.programmer newsgroup for their suggestions for the top ten. Regrettably, due to the number of submissions, not every error could be featured - but we think this "Top Ten" list represents the most popular and frequent errors people make. |
Properties Editor
http://propedit.sourceforge.jp/eclipse/updates/
CAS用来标志用户的token是存在它自己的域名下?不是存在web应用的域名下?CAS判断用户d由agent军_,agent验证用户信息有两U处?
1.如果q个用户是以前没dq的,也就是说q个web应用的域名下没有一个agent颁发的sessionid(在cookie?的话,那么它会跌{到CAS server的登录界?q里由CAS server军_是否昄d界面,q是直接p转回?也就是不是每ơ都要求输入密码d?.
2.CAS的登录界面会有两U处?如果以前没登录过,也就是在CAS server自己的域名下,没有用户的token的话,p求登?如果有token的话,p回一个ticket(也就是不昄d界面直接重定向返回了).
然后接第一步里?agent收到ticket以后提交给CAS server验证,q取得返回信?是个xml,cas的协议规定的,也可以用saml之类?q个地方可以取得除了用户姓名以外的信?q样可以做同步?权限的问题可以这么解?.然后agent׃存此时的session,把sessionid攑ֈ该web应用域名下的cookie?
以上逻辑说明?标志用户w䆾的token在CAS server的域名下,每个web应用不保存用戯n?因此跨域是绝Ҏ(gu)问题?只是single sign off需要CAS server的配合了,要把那个token删掉.
不过如果标志w䆾的token不存?而sessionid存在,那还是被认ؓ是登录的,只不q是在等待那个session timeout而已.
囄中的字体E微了?呵呵,使用visio我还是个新?
ps:q个程图是Ҏ(gu)cas服务端的webflow的配|画出来,如有本h有理解错误的!Ƣ迎指正!
!-----------------------------------------------------------------------------!
! PATTERN FORMATS GLOSSARY !
!-----------------------------------------------------------------------------!
! %n - newline !
! %m - your log message !
! %p - message priority (FATAL, ERROR, WARN, INFO, DEBUG or custom) !
! %r - millisecs since program started running !
! %% - percent sign in output !
! !
!-----------------------SOME MORE CLUTTER IN YOUR LOG-------------------------!
! %c - name of your category (logger), %c{2} will outputs last two components !
! %t - name of current thread !
! %x - Nested Diagnostic Context (NDC) (you supply it!) !
! !
!-------------------------SLOW PERFORMANCE FORMATS----------------------------!
! %d - date and time, also %d{ISO8601}, %d{DATE}, %d{ABSOLUTE}, !
! %d{HH:mm:ss,SSS}, %d{dd MMM yyyy HH:mm:ss,SSS} and so on !
! %l - Shortcut for %F%L%C%M !
! %F - Java source file name !
! %L - Java source line number !
! %C - Java class name, %C{1} will output the last one component !
! %M - Java method name !
! !
!------------------------------FORMAT MODIFIERS-------------------------------!
! %-any_letter_above - Left-justify in min. width (default is right-justify) !
! %20any_letter_above - 20 char. min. width (pad with spaces if reqd.) !
! %.30any_letter_above - 30 char. max. width (truncate beginning if reqd.) !
! %-10.10r - Example. Left-justify time elapsed within 10-wide field. !
! Truncate from beginning if wider than 10 characters. !
!-----------------------------------------------------------------------------!