找不到REST Web服务404

问题描述 投票:0回答:1

当调用weblogic服务器中部署的Web服务时,我得到404 - Not found错误。即使在搜索SO中的类似问题后,我也无法找到解决方案:

Rest Web services returning a 404

Java Restful Service eclipse tomcat HTTP Error 404

Restful Web Service returning 404, bad web.xml?

正如您在下面的图像中所看到的那样,资源已正确部署在weblogic服务器中:

enter image description here

我有以下代码:

services rest.Java

package pt.vdf.nc.webproxy;

@Path("/NCProxyServices")
public class ServicesREST {

    public ServicesREST(){
        WebProxy.getAllInstances();
    }

    @Path("ManageShortNumber/{MSISDN}/{DestinationNumber}")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response manageShortNumberSMSIntegration(@PathParam("MSISDN") String terminal, @PathParam("DestinationNumber") Integer shortNumber) {
    (...)
   }

application.xml中

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
    version="5">
    <description>WebApp builder and deployer</description>
    <display-name>ncwebproxy</display-name>
    <module>
        <web>
            <web-uri>ncwebproxy.war</web-uri>
            <context-root>/webproxy/</context-root>
        </web>
    </module>
    <library-directory>lib</library-directory>
</application>

veb.hml

(...)

<security-constraint>
    <display-name>Administrators</display-name>
    <web-resource-collection>
        <web-resource-name>webproxy</web-resource-name>
        <url-pattern>/webproxy/*</url-pattern>
        <http-method>GET</http-method>
    </web-resource-collection>
 </security-constraint>

(...)

[编辑] - >在下面添加了pom.xml:

   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>services-web</artifactId>
    <packaging>war</packaging>
    <name>services-web</name>
    <description>Services Web - WAR</description>

    <parent>
        <groupId>pt.vdf.nc.services</groupId>
        <artifactId>services</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../services</relativePath>
    </parent>

    <properties>
        <war.phase>package</war.phase>
        <install.phase>install</install.phase>
        <weblogic.version>10.3.6</weblogic.version>
    </properties>

    <profiles>

        <profile>
            <id>env-loc-wl</id>

            <properties>
                <war.phase>package</war.phase>
                <install.phase>install</install.phase>
            </properties>
        </profile>

        <profile>
            <id>env-loc-tc</id>

            <properties>
                <war.phase>none</war.phase>
                <install.phase>none</install.phase>
            </properties>
        </profile>

        <profile>
            <id>env-dev-wl</id>

            <properties>
                <war.phase>package</war.phase>
                <install.phase>install</install.phase>
            </properties>
        </profile>

        <profile>
            <id>env-tst-wl</id>

            <properties>
                <war.phase>package</war.phase>
                <install.phase>install</install.phase>
            </properties>
        </profile>

        <profile>
            <id>env-ath-wl</id>

            <properties>
                <war.phase>none</war.phase>
                <install.phase>none</install.phase>
            </properties>
        </profile>

        <profile>
            <id>env-prd-wl</id>

            <properties>
                <war.phase>package</war.phase>
                <install.phase>install</install.phase>
            </properties>
        </profile>
    </profiles>

    <build>
        <finalName>ncservices</finalName>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>cfg/services-cfg.properties</include>
                    <include>ctx/*</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-war</id>
                        <phase>${war.phase}</phase>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-install</id>
                        <phase>${install.phase}</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <artifactId>services-common</artifactId>
            <groupId>${project.groupId}</groupId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.22.1</version>
</dependency>

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.22.1</version>
    </dependency>

        <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.22.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.22.1</version>
</dependency>
        <dependency>
            <groupId>com.oracle.weblogic</groupId>
            <artifactId>weblogic</artifactId>
            <version>${weblogic.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.timesten</groupId>
            <artifactId>ttjdbc6</artifactId>
            <version>11.2.1.6.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.oracle.weblogic</groupId>
            <artifactId>wlclient</artifactId>
            <version>${weblogic.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
        </dependency>
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-core_2.10</artifactId>
            <version>1.3.11</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.ws.rs</groupId>
                    <artifactId>jsr311-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.9.0</version>
        </dependency>
    </dependencies>
</project>

我尝试了各种不同的url模式尝试成功调用服务,但我不断收到错误404。

http://localhost:7001/webproxy/NCProxyServices/ManageShortNumber/9842987982/97668/
http://localhost:7001/pt.vdf.nc.webproxy/webproxy/NCProxyServices/ManageShortNumber/9842987982/97668/
http://localhost:7001/NCProxyServices/ManageShortNumber/9842987982/97668/

请您指出我正确的方向来成功调用此服务。

感谢您的时间

java web-services rest jersey weblogic
1个回答
0
投票

我看到你正在使用@Consumes(MediaType.APPLICATION_JSON)但是使用@PathParam而不是JSON格式读取参数。我也看到了@Produces(MediaType.APPLICATION_JSON),但方法返回类型是Response。你能尝试删除这两个注释吗?如果您需要处理JSON请求/响应,则需要指定JSON库以进行编码和解码。不确定你是否已经照顾好了。

© www.soinside.com 2019 - 2024. All rights reserved.