2013年8月1日星期四

eclipse hadoop plugin configuration

with a good hadoop 's eclipse plugin, wrote a test class is used to print configuration information , configuration information is found to eclipse plugin that comes with , rather than hadoop installation directory configuration information, such as my core-site.xml configuration fs.default.name information hdfs :/ / localhost: 9000, eclipse print out the message that fs.default.name = file :/ / /. This class is packaged and put into a jar file, run the shell command line , the printed information is configured hadoop installation directory information , ie hdfs :/ / localhost: 9000.

This is the test code from the Hadoop The Definitive Guide Second Edition revised edition of 135

package lin;

import java.util.Map.Entry;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class ConfigurationPrinter extends Configured implements Tool{
static{
Configuration.addDefaultResource("hdfs-default.xml");
Configuration.addDefaultResource("hdfs-sit.xml");
Configuration.addDefaultResource("mapred-default.xml");
Configuration.addDefaultResource("mapred-site.xml");
}

@Override
public int run(String[] arg0) throws Exception {
// TODO Auto-generated method stub
Configuration conf = getConf();
for(Entry<String,String> entry : conf){
System.out.printf("%s=%s\n",entry.getKey(),entry.getValue());
}
return 0;
}

public static void main(String args[]) throws Exception{
int exitCode = ToolRunner.run(new ConfigurationPrinter(),args);
System.out.println(exitCode);
}

}


eclipse print information
fs.default.name = file :/ / /

packaged into jar command line after printing information
fs.default.name = hdfs :/ / localhost: 9000

This situation is normal do

------ Solution ------------------------------------ --------
not called , do not control

Principles and solutions struts2 vulnerability

 
  
   

1, Principle

   

Struts2 core is used webwork framework that addresses the underlying action is by calling the getter / setter methods to handle http parameters, it is declared as a parameter for each http ONGL (here ONGL introduction) statements. When we submit an http parameter:

   

? user.address.city = Bishkek & user ['favoriteDrink'] = kumys
ONGL convert it to:
action.getUser (). getAddress (). setCity ("Bishkek" ;)
action.getUser (). setFavoriteDrink ("kumys")

   

This is done by ParametersInterceptor (parameter filter) to perform, using the user-supplied HTTP parameter called ValueStack.setValue (). www.2cto.com

   

order to prevent tampering with the server-side object, XWork's ParametersInterceptor allowed parameter names in a "#" character, but if you use Java unicode string representation of \ u0023, an attacker can bypass the protection, modify the protection Java manner values:

   

   


destructive code here Please executed in a test environment is strictly prohibited to use this method for malicious attacks
? ('\ u0023_memberAccess [\' allowStaticMethodAccess \ ']') (meh) = true & (aaa) (('\ u0023context [\' xwork.MethodAccessor.denyMethodExecution \ '] \ u003d \ u0023foo') (\ u0023foo \ u003dnew% 20java.lang.Boolean ("false"))) & (asdf ) (('\ u0023rt.exit (1)') (\ u0023rt \ u003d@java.lang.Runtime @ getRuntime ())) = 1

   

   


escaped like this:

   

? ('# _memberAccess [' allowStaticMethodAccess ']') (meh) = true & (aaa) (('# context [' xwork.MethodAccessor.denyMethodExecution '] = # foo') (# foo = new% 20java . lang.Boolean ("false"))) & (asdf) (('# rt.exit (1)') (# rt = @ java.lang.Runtime @ getRuntime ())) = 1

   

   


OGNL processing end result is

   

java.lang.Runtime.getRuntime (). exit (1); / / close the program, is about to shut down web applications

   

similar can perform
java.lang.Runtime.getRuntime (). exec ("net user username password / add") ;/ / increase the operating system user privileges in the case of a successful (using% 20 in the URL replaces spaces,% 2F replaces /)
permission as long as you can run any DOS commands.

   

2, Solution
many online articles have introduced three solutions, personal feel to the struts2 jar package update to the latest version of the most simple, do not change any program code, the current the latest version 2.3.4
download to the update package has a lot of jar package, I system in the main use of the following replaces the old version:
commons-lang3-3.1.jar (reservation commons-lang-2.6.jar)
javassist-3.11.0.GA.jar (new plus package)
ognl-3.0.5.jar (replacing the old version)
struts2-core-2.3.4.1.jar (replacing the old version)
xwork-core-2.3.4.1.jar ; (replacing the old version)

  
 

Pojo and JavaBean difference ( reprint )

 

OJO (Plain Old Java Object) The name used to emphasize that it is a normal java object , rather than a specific object.

 
  November 2005 when , "POJO" is mainly used to refer to those useless comply with specific Java object model , agreement or frameworks such as EJB Java objects.  
 
  Ideally speaking, a POJO is a Java object without any restrictions ( in addition to the Java Language Specification ) . For example, should not be a POJO  
 
  
       
  1. expansion scheduled classes, such as public class Foo extends javax.servlet.http.HttpServlet {...
  2.    
  3. achieve the intended interfaces, such as public class Bar implements javax.ejb.EntityBean {...
  4.    
  5. contains predefined annotation , such as @ javax.ejb.Entity public class Baz {...
  6.   
 
 
  Then , because of technical difficulties and other reasons, many software products compatible POJO style or frame in fact still requires using a predetermined dimension , such as more convenient for persistence .  
 
    
 
  Written in JAVA language JavaBean is a reusable component . Its method naming , structure and behavior must conform to certain conventions :  
 
  
       
  1. The class must have a public default constructor.
  2.    
  3. properties of this class to access using getter and setter , other methods to comply with standard naming conventions.
  4.    
  5. This class should be serializable.
  6.   
 
 
  Because these requirements mainly by convention rather than by implementing the interface , so many developers as to comply with the specific JavaBean naming conventions POJO.  
 
    
 
  In short , when a Pojo serializable , there is a no-argument constructor , use getter and setter methods to access the property, he is a JavaBean.  

Issue struts.xml

struts.xml wildcard Encountered a problem struts wildcard, seeking expert help in the end is where the problem facie.
package chapter8;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.opensymphony.xwork2.Action;

public class LoginRegisterAction implements Action{

private String username;
private String password;

private HttpServletRequest request;


private static Map<String, String> users = new HashMap<String, String>();

public String register() throws Exception{
request.setAttribute("info", "您已经注册成功!");
return SUCCESS;
}

public String login() throws Exception{
try{
if(getUsername().equals("bill") && getPassword().equals("1234")){
request.setAttribute("info", "登陆成功");
return SUCCESS;
}else{
request.setAttribute("info", "登录失败");
return ERROR;
}
}catch(Exception e){
return ERROR;
}
}
public String execute() throws Exception{
return SUCCESS;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public void setRequest(HttpServletRequest request) {
this.request = request;
}

}

struts.xml file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
   
<struts>
<package name="struts2" extends="struts-default" namespace="/myspace">

<action name="*Action" class="chapter8.LoginRegisterAction" method="{1}">
<result name="success">/chapter8/success.jsp</result>
<result name="error">/chapter8/error.jsp</result>
</action>

</package>
</struts>

jsp page:
<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"  %>
<html>
<body>
<script type="text/javascript">
function login(){
alert("登陆");
form.action = "/loginAction.action";
alert(form.action);
form.submit();
}
function register(){
alert("注册");
form.action = "registerAction";
form.submit();
}
</script>

<s:form name="form" theme="simple" namespace="/myspace">
用户:<s:textfield name="username" /><p />
密码:<s:textfield name="password" /><p />

<s:submit value="登陆" onclick="login()" />
<s:submit value="注册" onclick="register()" />
</s:form>
  </body>
</html>



point after landing alert


then prompts:
type Status report

message / loginAction.action

description The requested resource (/ loginAction.action) is not available.
------ Solution -------------- ------------------------------
landlord, is that you address the problem ah. .

you see your namespace is myspace then each request path can be coupled myspace
Also in js developed under the absolute path to the best path.
so the
form.action = "/ loginAction.action";
form.action = "registerAction";
changed
form.action = "$ {pageContext.request.contextPath} / myspace / loginAction.action";
form.action = "$ {pageContext.request.contextPath} / myspace / registerAction";


------ Solution ------------------------------------ --------
fourth floor, note the people using struts2 tag have a namespace
landlord you know what causes it?
------ For reference only -------------------------------------- -
Online, trouble you heroes ~ ~ ~ ~ ~
------ For reference only --------------------- ------------------
<action name="loginAction" class="chapter8.LoginRegisterAction" method="register">

<action name="registerAction" class="chapter8.LoginRegisterAction" method="register">


solve the problem, use a wildcard before you do not have the requested action wildcards were implored once, and then changed to a wildcard in the form, no problem.

but do not know the specific reasons why?
------ For reference only -------------------------------- -------
  The reply deleted by an administrator at 2013-06-04 21:00:54

------ For reference only ---------------------------------- -----


I do not know, the first time without a wildcard request, then switch to a wildcard, you can, do not know the environmental issues?
------ For reference only -------------------------------------- -
never encountered before, I do not know how you get, there is definitely a problem here just like that. . Investigation it yourself slowly

Java, swap FAQ

 
  

directly on the code ......

  
   
public class Swap { 

public static void main(String[] args) {
int a[] = new int[]{1,2};
System.out.println(a[
0] + " "+a[1]);
swap(a,
0,1);
System.out.println(a[
0] + " "+a[1]);

}
private static void swap(int[] a, int i, int j) {

int temp = a[i];
a[i]
= a[j];
a[j]
= temp;
}
}
  
 
 
  

method call (call by) is a standard computer scientific terms , the method call according to the parameters passed value of the case is divided into call (call by reference) , and reference calls ( call by value ). There are many rivers and lakes on the definition of these two calls , the most common argument is passed value is a value call delivery address is referenced calls. This is actually very appropriate , that these claims are easy to make we associate a Java object parameter passing is call by reference in fact , Java's object parameter passing value is still called. In the main output or the original 2,3 years , regardless of reference type is passed also is the object instance.

  
   
public class Swap1 
{
public static void main(String[] args)
{
Integer a
=new Integer(2);
Integer b
=new Integer(3);
TestSwap ts
=new TestSwap(a,b);
System.out.println(
"before swap:");
ts.outPut();
ts.dataSwap1(a,b);
System.out.println(
"after swap:");
ts.outPut();
}
}

class TestSwap
{
Integer a
=null;
Integer b
=null;

public TestSwap(Integer a,Integer b)
{
this.a=a;
this.b=b;
}
/*这样不可交换,交换的只是拷贝过来的引用,而
* 输出还是成员变量(输出用的是类内的方法)
* 重要的是,形参和实参所占的内存地址并不一样,
* 形参中的内容只是实参中存储的对象引用的一份拷贝。
*
*/
protected void dataSwap0(Integer a,Integer b)
{
Integer temp
=a;
a
=b;
b
=temp;
}
protected void dataSwap(Integer a,Integer b)
{
this.a = b;
this.b = a;
}
//这样也可以,不过需要类内的输出,就是说输出TestSwap的成员变量
protected void dataSwap1(Integer a,Integer b)
{
Integer temp
=this.a;
this.a=this.b;
this.b=temp;
}
protected void outPut()
{
System.out.println(
"a="+a+" b="+b);
}
}
  
 

oozie + sqoop ClassNotFound

Want to run a sqoop of action oozie
wrote a workflow is as follows

<workflow-app xmlns='uri:oozie:workflow:0.4' name='sqoop-workflow'>
<start to='testSqoop'/>
<action name='testSqoop'>
<sqoop xmlns='uri:oozie:sqoop-action:0.2'>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<arg>import</arg>
<arg>--connect</arg>
<arg>jdbc:mysql://127.0.0.1/snaplb_query</arg>
<arg>--table</arg>
<arg>test_table</arg>
<arg>--username</arg>
<arg>root</arg>
<arg>--password</arg>
<arg>XXOO</arg>
<arg>--hive-import</arg>
<arg>--hive-partition-key</arg>
<arg>dt</arg>
<arg>--hive-partition-value</arg>
<arg>2013-05-22</arg>
</sqoop>
<ok to="end"/>
<error to="fail"/>
</action>
<kill name='fail'>
<message>Sqoop copy shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name='end'/>
</workflow-app>



Runtime Error Failing Oozie Launcher, Main class [org.apache.oozie.action.hadoop.SqoopMain], main () threw exception, org / apache / sqoop / Sqoop
java.lang.NoClassDefFoundError: org / apache / sqoop / Sqoop
at org.apache.oozie.action.hadoop.SqoopMain.runSqoopJob (SqoopMain.java: 205)
at org.apache.oozie.action.hadoop.SqoopMain.run (SqoopMain.java: 174)
at org.apache.oozie.action.hadoop.LauncherMain.run (LauncherMain.java: 37)
at org.apache.oozie.action.hadoop.SqoopMain.main (SqoopMain.java: 47)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java: 39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java: 25)
at java.lang.reflect.Method.invoke (Method.java: 597)
at org.apache.oozie.action.hadoop.LauncherMapper.map (LauncherMapper.java: 491)
at org.apache.hadoop.mapred.MapRunner.run (MapRunner.java: 50)
at org.apache.hadoop.mapred.MapTask.runOldMapper (MapTask.java: 418)
at org.apache.hadoop.mapred.MapTask.run (MapTask.java: 333)
at org.apache.hadoop.mapred.Child $ 4.run (Child.java: 268)
at java.security.AccessController.doPrivileged (Native Method)
at javax.security.auth.Subject.doAs (Subject.java: 396)
at org.apache.hadoop.security.UserGroupInformation.doAs (UserGroupInformation.java: 1408)
at org.apache.hadoop.mapred.Child.main (Child.java: 262)
Caused by: java.lang.ClassNotFoundException: org.apache.sqoop.Sqoop
at java.net.URLClassLoader $ 1.run (URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged (Native Method)
at java.net.URLClassLoader.findClass (URLClassLoader.java: 190)
at java.lang.ClassLoader.loadClass (ClassLoader.java: 306)
at sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.java: 301)
at java.lang.ClassLoader.loadClass (ClassLoader.java: 247)
... 17 more
sqoop jar package properly in sqoop the path, I even tried to copy it to the lib under mapreduce, oozie mapreduce task jar package loaded loaded with all mapreduce the jar package, simply put sqoop of package throws go, I guess where should change the configuration can get, ask everyone who understand to finger Ming Lu, thank you

------ Solution ------------------------------------ --------
Hello, what is your hadoop with sqoop, oozie what version is it? Just wrote a workflow with the job configuration? jar package like it? Specifically, the following procedure can do? I reported errors are found sqoop label
------ Solution ------------------------------ --------------
I never played oozie, oozie you have your own lib directory
If so, put into a jar sqoop to try
or join in the CLASSPATH sqoop package
------ For reference only -------------------------- -------------
is not sharelib problem?
------ For reference only -------------------------------------- -

oozie has its own lib directory, I have tried, no
hadoop or mapred do not know where the CLASSPATH configuration, headache
------ For reference only ---------------------- -----------------

hadoop version Hadoop 2.0.0-cdh4.2.0
oozie version 3.3.0-cdh4.2.0
sqoop version 1.4.2-cdh4.2.0
all cdh4.2.0 integrated
I just wrote a workflow, simply just ran a sqoop command, do not need to do jar package
------ For reference only ------------- --------------------------

What is this problem? How to change?
------ For reference only -------------------------------------- -
your package LIB missing SQOOP reference, the need to carefully check the LZ
There is a possibility that your LIB library environment dirty
This is due to some kind of LIB library JAR, there are different versions, different versions of the JAR added repeatedly can cause this problem


------ For reference only ---------------------------------- -----
get, simply put the jar package into workflow sqoop path where the lib under
------ For reference only ------------ ---------------------------
Hello, may I ask mahout integration with oozie did use it? If you do not oozie with java program it? And the java program is executed a mahout command line algorithm

[Original] eclipse can not find run as junit

 

ran into this problem, torture me a good look!

 

root of the problem and solutions

 

First, ensure that there junit jar package, basically not make this mistake;

 

second, to ensure you that this class is Source can be compiled file , If this class in general folder, the project is not compiled it, it can not find the class.

 

guarantee this basic points can be implemented.

 

how to ensure that the second point:

 

first, to ensure that this class or this directory, not in this Excluded under. I came across this situation is the case, do not know when added to the list, Excluded files will not be compiled.

 

 

Second, a way to the Internet, but it must be the case under the premise of the first point.

 

If you are getting the above error message in Eclipse IDE , while running your test case, just make sure that you have the test class as a part of the "eclipse source folder" definition. Easiest way. Right click on the folder -> Build Path -> Use as source folder D one .

 

might encounter an error message

 

No tests found with test runner JUnit4

 

The input type of the launch configuration does not exist

 

 

tortured half, hereby record.