Skip to content

HBASE-19762 Fixed Checkstyle errors in hbase-http #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<!--
/**
* Licensed to the Apache Software Foundation (ASF) under one
Expand Down Expand Up @@ -37,6 +37,9 @@
<suppress checks="VisibilityModifier" files=".*/src/test/.*\.java"/>
<suppress checks="InterfaceIsTypeCheck" files=".*/src/main/.*\.java"/>
<suppress checks="EmptyBlockCheck" files="TBoundedThreadPoolServer.java"/>
<suppress checks="EmptyBlockCheck" files="TestServletFilter.java"/>
<suppress checks="EmptyBlockCheck" files="TestGlobalFilter.java"/>
<suppress checks="EmptyBlockCheck" files="TestPathFilter.java"/>
<suppress checks="EqualsHashCode" files="StartcodeAgnosticServerName.java"/>
<suppress checks="MethodLength" files="Branch1CoprocessorMethods.java"/>
<suppress checks="IllegalImport" message="org\.apache\.htrace\.core"/>
Expand Down
7 changes: 7 additions & 0 deletions hbase-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>warbucks-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,38 @@
*/
package org.apache.hadoop.hbase.http;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;

import org.apache.yetus.audience.InterfaceAudience;

@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
public class ClickjackingPreventionFilter implements Filter {

private FilterConfig filterConfig;

@Override
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}

@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain)
throws IOException, ServletException {
HttpServletResponse httpRes = (HttpServletResponse) res;
httpRes.addHeader("X-Frame-Options", filterConfig.getInitParameter("xframeoptions"));
chain.doFilter(req, res);
}

@Override
public void destroy() {
}

private FilterConfig filterConfig;

@Override
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse httpRes = (HttpServletResponse) res;
httpRes.addHeader("X-Frame-Options", filterConfig.getInitParameter("xframeoptions"));
chain.doFilter(req, res);
}

@Override
public void destroy() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ public final class HtmlQuoting {
*/
public static boolean needsQuoting(byte[] data, int off, int len) {
if (off+len > data.length) {
throw new IllegalStateException("off+len=" + off+len + " should be lower"
+ " than data length=" + data.length);
throw new IllegalStateException("off+len=" + off+len + " should be lower"
+ " than data length=" + data.length);
}
for(int i=off; i< off+len; ++i) {
switch(data[i]) {
case '&':
case '<':
case '>':
case '\'':
case '"':
return true;
default:
break;
case '&':
case '<':
case '>':
case '\'':
case '"':
return true;
default:
break;
}
}
return false;
Expand All @@ -83,16 +83,28 @@ public static boolean needsQuoting(String str) {
* @param off the index of the first byte to quote
* @param len the number of bytes to quote
*/
public static void quoteHtmlChars(OutputStream output, byte[] buffer,
int off, int len) throws IOException {
public static void quoteHtmlChars(OutputStream output, byte[] buffer, int off, int len)
throws IOException {
for(int i=off; i < off+len; i++) {
switch (buffer[i]) {
case '&': output.write(ampBytes); break;
case '<': output.write(ltBytes); break;
case '>': output.write(gtBytes); break;
case '\'': output.write(aposBytes); break;
case '"': output.write(quotBytes); break;
default: output.write(buffer, i, 1);
case '&':
output.write(ampBytes);
break;
case '<':
output.write(ltBytes);
break;
case '>':
output.write(gtBytes);
break;
case '\'':
output.write(aposBytes);
break;
case '"':
output.write(quotBytes);
break;
default:
output.write(buffer, i, 1);
break;
}
}
}
Expand Down Expand Up @@ -124,10 +136,8 @@ public static String quoteHtmlChars(String item) {
* Return an output stream that quotes all of the output.
* @param out the stream to write the quoted output to
* @return a new stream that the application show write to
* @throws IOException if the underlying output fails
*/
public static OutputStream quoteOutputStream(final OutputStream out
) throws IOException {
public static OutputStream quoteOutputStream(final OutputStream out) {
return new OutputStream() {
private byte[] data = new byte[1];
@Override
Expand Down Expand Up @@ -202,9 +212,9 @@ public static String unquoteHtmlChars(String item) {
return buffer.toString();
}

public static void main(String[] args) throws Exception {
public static void main(String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("Please provide some arguments");
throw new IllegalArgumentException("Please provide some arguments");
}
for(String arg:args) {
System.out.println("Original: " + arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase.http;

import org.apache.hadoop.conf.Configuration;

import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
import org.apache.hadoop.conf.Configuration;

/**
* Statics to get access to Http related configuration.
Expand Down Expand Up @@ -51,7 +52,7 @@ public boolean isHttpsEnabled() {
}
}

public HttpConfig(final Configuration conf) {
public HttpConfig(final Configuration conf) {
boolean sslEnabled = conf.getBoolean(
ServerConfigurationKeys.HBASE_SSL_ENABLED_KEY,
ServerConfigurationKeys.HBASE_SSL_ENABLED_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.http;

import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand Down
Loading