Jersey JAX-RS application returns 404

≡放荡痞女 提交于 2021-01-29 11:47:42

问题


Everytime I run the application on server and enter the url I don't get any response. It says the following (image):

Java code is as follows:

package application;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import javax.ws.rs.ApplicationPath;

@Path("demo")
public class FRITZ {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String calculateCellComplexities(String spreadsheetPath) throws Exception {
        System.out.print("Entered Cell Complexity......\n");
        //open spreadsheet
        Spreadsheet spreadsheet;

        try {
            spreadsheet = POIReader.readFromFile(spreadsheetPath);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        //analyze metrics
        AnalyzeEngine analyzer = new AnalyzeEngine();
        boolean success;
        try {
            success = analyzer.initializeEvaluationMode(EvaluationMode.SMELLS_COMPLETE);
            analyzer.analyze(spreadsheet);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        if(!success) {
            System.err.println("Could not analyze spreadsheet: abort!");
            return null;
        }

        //prepare metrics for analysis
        List<Metric> analysisMetrics = new ArrayList<Metric>();
        analysisMetrics.add(MetricFactory.getMetric(LongCalculationChainSmell.class));
        analysisMetrics.add(MetricFactory.getMetric(PatternFinderColumnNoBorder.class));
        analysisMetrics.add(MetricFactory.getMetric(PatternFinderRowNoBorder.class));
        analysisMetrics.add(MetricFactory.getMetric(MultipleReferences.class));
        analysisMetrics.add(MetricFactory.getMetric(MultipleOperations.class));

        //initialize max metric value data
        Double[] maxValues = new Double[analysisMetrics.size()];
        for(int i = 0; i < maxValues.length; i++) {
            maxValues[i] = 0.0d;
        }

        //determine max metric values in spreadsheet
        for(Worksheet worksheet : spreadsheet.getWorksheets()) {
            for(Cell cell : worksheet.getCells()) {
                for(int index = 0; index < analysisMetrics.size(); index++) {
                    Metric metric = analysisMetrics.get(index);
                    if(metric.domain == Domain.INTEGER) {
                        Integer metricValue = (Integer) metric.getMetricValueForCell(cell);
                        if(metricValue != null)
                        {
                            maxValues[index] = Math.max(maxValues[index], metricValue);
                        }
                    } if(metric.domain == Domain.LONG) {
                        Long metricValue = (Long) metric.getMetricValueForCell(cell);
                        if(metricValue != null)
                        {
                            maxValues[index] = Math.max(maxValues[index], metricValue);
                        }
                    } if (metric.domain == Domain.REAL) {
                        Double metricValue = (Double) metric.getMetricValueForCell(cell);
                        if(metricValue != null)
                            maxValues[index] = Math.max(maxValues[index], metricValue);
                    }
                }
            }
        }

//      for(int index = 0; index < analysisMetrics.size(); index++) {
//          Metric metric = analysisMetrics.get(index);
//          if(metric.domain == Domain.INTEGER || metric.domain == Domain.REAL) {
//              System.out.println(index + ": " + maxValues[index]);
//          }
//      }

        //calculate complexity estimate
        Map<String,Double> probabilityMap = new HashMap<String, Double>();
        for(Worksheet worksheet : spreadsheet.getWorksheets()) {
            for(Cell cell : worksheet.getCells()) {
                double complexity = 0.0d;

                if(cell.isFormulaCell()) {
                    int numAppliedMetrics = 0;

                    for(int index = 0; index < analysisMetrics.size(); index++) {
                        Metric metric = analysisMetrics.get(index);
                        switch(metric.domain) {
                        case BOOLEAN:
                            Boolean booleanMetricValue = (Boolean) metric.getMetricValueForCell(cell);
                            if(booleanMetricValue != null) {
                                complexity += (booleanMetricValue ?  1.0f : 0.0f);
                                numAppliedMetrics++;
                            }
                            break;
                        case INTEGER:
                            Integer metricValue = (Integer) metric.getMetricValueForCell(cell);
                            if(metricValue != null) {
                                complexity += metricValue / maxValues[index];
                                numAppliedMetrics++;
                            }
                            break;
                        case REAL:
                            Double doubleMetricValue = (Double) metric.getMetricValueForCell(cell);
                            if(doubleMetricValue != null) {
                                complexity += doubleMetricValue / maxValues[index];
                                numAppliedMetrics++;
                            }
                            break;
                        case STRING:
                        default:
                            break;

                        }
                    }

                    if(numAppliedMetrics > 0) 
                        complexity /= numAppliedMetrics;
                }
                probabilityMap.put(cell.getPosition().toA1DebugString(), complexity);
            }
        }

        //return probabilityMap;
        String a = "hello from server";
        return a;
    }
}

Please ignore main logic of function, I am just testing web api with simple returned string, once it runs successuflly I will return the json.

Following is my web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>FRITZ-WEBAPI</display-name>

  <servlet>
    <servlet-name>FRITZ JAVA API</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer.class</servlet-class>

    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>application</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>

    <servlet-name>FRITZ JAVA API</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app> 

来源:https://stackoverflow.com/questions/61103553/jersey-jax-rs-application-returns-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!