gradle-tomcat-plugin icon indicating copy to clipboard operation
gradle-tomcat-plugin copied to clipboard

Deploy websocket services with tomcat 8.0.33 by tomcatRun task,404 error received when send a request from client browser (chrome or ie 11)

Open yin-bp opened this issue 8 years ago • 3 comments

Deploy websocket services with tomcat 8.0.33 by tomcatRun task,but response 404 error when send a request from client browser (chrome or ie 11): WebSocket connection to 'ws://localhost/bboss-websocket/Websocket1Action' failed: Error during WebSocket handshake: Unexpected response code: 404

but deploy directly same websocket services with tomcat 8.0.33 is ok.

build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.4'
    }
}
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'com.bmuschko.tomcat'
sourceSets {
    main {
        java {
            srcDirs 'src'
        }
        resources {

        }
    }
}

dependencies {
    //test依赖bboss_rt和frameworkset_util的输出
    compileOnly(
            [group: 'org.apache.tomcat', name: 'tomcat-catalina', version: "8.0.33", transitive: false],
            [group: 'org.apache.tomcat', name: 'tomcat-coyote', version: "8.0.33", transitive: false],
            [group: 'org.apache.tomcat', name: 'tomcat-websocket', version: "8.0.33", transitive: true],
            [group: 'servletapi', name: 'servletapi', version: '2.4', transitive: false],
            [group: 'javax.servlet', name: 'jsp-api', version: '2.0', transitive: false]
    )

compile(
           [group: 'org.bbossgroups', name: 'bboss-util', version: "${version}", transitive: true]
    )
    def tomcatVersion = '8.0.33'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
           "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
           "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"

}

tomcat
{
     httpPort = 80
}
war {
    from 'WebRoot'
    // adds a file-set to the root of the archive
    webInf { from 'WebRoot/WEB-INF' } // adds a file-set to the WEB-INF dir.

    classpath configurations.providedCompile // adds a configuration to the WEB-INF/lib dir.
    webXml = file('WebRoot/WEB-INF/web.xml') // copies a file to WEB-INF/web.xml
}
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact war
        }
    }
    repositories {
        mavenLocal()
    }
}
webAppDirName = 'WebRoot'  

gradle version:2.12 tomcat 8.0.33

yin-bp avatar Apr 05 '16 08:04 yin-bp

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>WebSocketTomcat7</display-name>

  <welcome-file-list>

    <welcome-file>websocket.jsp</welcome-file>

  </welcome-file-list>
</web-app>

yin-bp avatar Apr 05 '16 08:04 yin-bp

Have the same problem.

sinall avatar Jun 25 '17 06:06 sinall

Same problem here with Java9 & Tomcat9.0.6 Has anybody tried this plugin: https://github.com/gretty-gradle-plugin/gretty ?

Edit: Fixed it by removing (accidentally added) tag <absolute-ordering/> from my web.xml. build.gradle:

dependencies {
    // JavaEE APIs
    providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'4.0.0'
    providedCompile group: 'javax.servlet.jsp', name: 'javax.servlet.jsp-api', version:'2.3.1'
    providedCompile group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
    providedCompile group: 'javax.websocket', name: 'javax.websocket-api', version:'1.1'
    
    // Tomcat
    def tomcatVersion = '9.0.6'
    compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-websocket', version: tomcatVersion
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
    //     "org.apache.tomcat.embed:tomcat-embed-logging-juli:9.0.0.M6",
           "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
}

Katharsas avatar Apr 07 '18 00:04 Katharsas