Сервер Liberty Profile выполняет неправильную функцию по запросу

Предисловие: у меня нет этой проблемы с сервером Tomcat или Tomee.

Я пытаюсь выполнить простой запрос Get через ajax, когда запрос попадает на сервер, он выполняет неправильный метод.

JS-файл

function CustomerPoints() {
        this.initializeListeners = function () {
            $("#storeSelect").change(function (event) {
                event.preventDefault();
                customerPoints.callAjax(contextPath + "/loyaltyPoints/customerPoints?getPoints&id=" + $("#storeSelect").val());
            });

        this.callAjax = function (url, value) {
            // generated url = http://localhost:9080/TLC/loyaltyPoints/customerPoints?getPoints&id=3778
            var cardNumber = $("#customerNumber");
            var alternateId = $("#alternateId");
            $
                .ajax(
                url,
                {
                    type: "GET",
                    data: value,
                    beforeSend: function (req) {
                        $("#modalErrorDiv").empty();
                        req.setRequestHeader("Accept",
                            "text/html;type=ajax");
                        req.setRequestHeader($(
                            "meta[name='_csrf_header']").attr(
                            "content"), $("meta[name='_csrf']")
                            .attr("content"));
                    },
                    complete: function (jqXHR) {
                        $("#customerNumber").replaceWith(cardNumber);
                        $("#alternateId").replaceWith(alternateId);
                        customerPoints.initializeListeners();
                    },
                    success: function (data, textStatus, jqXHR) {
                        $("#content").replaceWith(data);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        $('html,body').animate({
                            scrollTop: $('body').offset().top
                        }, 'slow');
                        $("#modalErrorDiv").empty();
                        $("#modalErrorDiv")
                            .append("<ul ><li class='error'>An error has occured. Please contact support.</li></ul>");
                    }
                });
        };

Контроллер

@Controller
public class CustomerPointsController
{
    private static final String HTML_PAGE          = "loyaltyPoints/customerPoints";
    private static final String REQUESTMAPPING     = "/" + HTML_PAGE;
    private static final String APPLYPOINTSMAPPING = "loyaltyPoints/applyPoints :: #content";
    private static final String CONTENT            = HTML_PAGE + " :: #content";

    /**
     * @param model
     * @return
     */
    @RequestMapping(value = REQUESTMAPPING)
    public String maintainCustomerPoints(Model model)
    {
        // this is the method that is called everytime
        return HTML_PAGE;
    }

    /**
     * @param id
     * @param model
     * @returns the valid customer points for this store, default followed by promotion points
     * when a user picks a store from the drop down.
     */
    @RequestMapping(value = REQUESTMAPPING, method = RequestMethod.GET, params = {
            "getPoints"})
    public String getPoints(@RequestParam(value = "id") String id, Model model)
    {
        // this is the method that never gets called
        return CONTENT;
    }
}

Обратите внимание, что я также взял сгенерированный URL-адрес из скрипта страницы и вставил в свой браузер для выполнения. Он выполняет только maintainCustomerPoints.

сервер.xml

<?xml version="1.0" encoding="UTF-8"?>
<server description="tlc server">
  <!-- Enable features -->
  <featureManager>
    <feature>jsf-2.0</feature>
    <feature>jsp-2.2</feature>
    <feature>ssl-1.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>restConnector-1.0</feature>
    <feature>json-1.0</feature>
    <feature>jaxrs-1.1</feature>
    <feature>servlet-3.0</feature>
    <feature>jpa-2.0</feature>
    <feature>beanValidation-1.0</feature>
    <feature>jndi-1.0</feature>
    <feature>jdbc-4.0</feature>
    <feature>monitor-1.0</feature>
  </featureManager>
  <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" virtualHost="default_host" />
  <jdbcDriver id="DerbyJDBCDriver">
    <library name="DerbyLib">
      <fileset dir="C:\tools\servers\wlp\lib" includes="derbyclient-10.6.1.0.jar" />
    </library>
  </jdbcDriver>
  <dataSource jndiName="jdbc/TLCDataSource" id="derbyDataSource" jdbcDriverRef="DerbyJDBCDriver">
    <properties.derby.client databaseName="TLC" password="APP" user="APP" />
  </dataSource>
  <applicationMonitor updateTrigger="mbean" />
  <application id="TLC_war" context-root="/TLC" location="C:\Users\nd26434\gitrepos\tlc\target\TLC-1.0.0-SNAPSHOT.war" name="TLC_war" type="war">
    <classloader delegation="parentLast">
      <privateLibrary>
        <fileset dir="C:\tools\servers\wlp\lib" includes="aspectjweaver-1.8.0.jar" />
      </privateLibrary>
    </classloader>
  </application>
</server>

person ndrone    schedule 19.03.2015    source источник
comment
Просто из любопытства, не могли бы вы попробовать вызвать его через customerPoints?getPoints=1, чтобы добавить случайное значение к вашему параметру getPoints. Глядя на RequestMapping может потребоваться некоторое значение.   -  person Gas    schedule 20.03.2015
comment
Спасибо @Gas, который помог. Если вы хотите ввести это как ответ. я одобрю это   -  person ndrone    schedule 20.03.2015


Ответы (1)


Согласно документации @RequestMapping, если имеет params в форме {"myParam"}, предполагает, что такой параметр должен присутствовать в запросе и может иметь любое значение.

Таким образом, безопасная форма URL-адреса должна содержать любое значение для getPoints, например customerPoints?getPoints=anyValueHere.

Вероятно, метод request.getParameter() возвращает другое значение для Tomcat, когда значение отсутствует. Для Liberty он возвращает null, если нет =, например customerPoints?getPoints и non null, когда есть =, например customerPoints?getPoints=.

person Gas    schedule 20.03.2015