/**
 *       Copyright 2010 Newcastle University
 *
 *          http://research.ncl.ac.uk/smart/
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.amber.oauth2.rs.extractor;

import javax.servlet.http.HttpServletRequest;

import org.apache.amber.oauth2.common.OAuth;

/**
 * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
 * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
 * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
 */
public class BearerQueryTokenExtractor implements TokenExtractor {

    @Override
    public String getAccessToken(HttpServletRequest request) {
        String token = request.getParameter(OAuth.OAUTH_BEARER_TOKEN);
        if (token == null) {
            token = request.getParameter(OAuth.OAUTH_TOKEN);
        }
        return token;
    }

    @Override
    public String getAccessToken(HttpServletRequest request, String tokenName) {
        return request.getParameter(tokenName);
    }

}

@@ -941,16 +941,90 @@
 actor;%0A%0A
+import java.io.UnsupportedEncodingException;%0Aimport java.net.URLDecoder;%0A%0A
 import j
@@ -1435,35 +1435,32 @@
 ing token = 
-request.get
+getQuery
 Parameter(OA
@@ -1449,32 +1449,41 @@
 tQueryParameter(
+request, 
 OAuth.OAUTH_BEAR
@@ -1542,27 +1542,24 @@
 token = 
-request.get
+getQuery
 Paramete
@@ -1560,16 +1560,25 @@
 rameter(
+request, 
 OAuth.OA
@@ -1742,39 +1742,1035 @@
 urn 
-request.getParameter(tokenName)
+getQueryParameter(request, tokenName);%0A    %7D%0A%0A    /**%0A     * A replacement for HttpServletRequest.getParameter() as it will mess up with HTTP POST body%0A     * @param request%0A     * @param name%0A     * @return%0A     */%0A    private String getQueryParameter(HttpServletRequest request, String name) %7B%0A        String query = request.getQueryString();%0A        if (query == null) %7B%0A            return null;%0A        %7D%0A        String%5B%5D params = query.split(%22&%22);%0A        for (String param : params) %7B%0A            try %7B%0A                param = URLDecoder.decode(param, %22UTF-8%22);%0A            %7D catch (UnsupportedEncodingException e) %7B%0A                // Ignore%0A            %7D%0A            int index = param.indexOf('=');%0A            String key = param;%0A            String value = null;%0A            if (index != -1) %7B%0A                key = param.substring(0, index);%0A                value = param.substring(index + 1);%0A            %7D%0A            if (key.equals(name)) %7B%0A                return value;%0A            %7D%0A        %7D%0A        return null
 ;%0A  

Fix the code to not mess up with HTTP POST body