0

我使用 [this RestComm Sip Servlet release version with tomcat][1], [1]: https://github.com/RestComm/sip-servlets/releases/tag/3.2.0-89 和 IntelliJ 想法。当我调试示例项目“LocationServiceApplication”时,总是得到错误“Artifact cc:war exploded: Server is not connected. Deploy is not available.”。我在 server.xml 中将引擎名称从 Sip-Servlets 更改为 Catalina。然后得到另一个错误:

Dec 27, 2017 12:04:20 AM org.apache.tomcat.util.modeler.BaseModelMBean invoke
Error: Exception invoking method createStandardContext
javax.management.MBeanException: Cannot find operation manageApp
    at org.apache.tomcat.util.modeler.ManagedBean.getInvoke(ManagedBean.java:524)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:292)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
    at sun.rmi.transport.Transport$1.run(Transport.java:178)
    at sun.rmi.transport.Transport$1.run(Transport.java:175)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.management.ServiceNotFoundException: Cannot find operation manageApp
    ... 33 more

[2017-12-27 12:04:20,301] Artifact cc:war exploded: Error during artifact deployment. See server log for details.

WEB_INFO/sip.xml

<sip-app>
    <app-name>LocationServiceApplication</app-name>
    <display-name>Location Service Sip Servlet</display-name>
    <description>Location Service Sip Servlet</description>

    <servlet-selection>
        <main-servlet>
            LocationServiceSipServlet
        </main-servlet>
    </servlet-selection>

    <servlet>
        <servlet-name>LocationServiceSipServlet</servlet-name>
        <display-name>LocationServiceSipServlet</display-name>
        <description>Location Service SIP servlet</description>
        <servlet-class>
            LocationServiceSipServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
</sip-app>

LocationServiceSipServlet.java

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

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.sip.Address;
import javax.servlet.sip.Proxy;
import javax.servlet.sip.SipFactory;
import javax.servlet.sip.SipServlet;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;
import javax.servlet.sip.URI;

import org.apache.log4j.Logger;

public class LocationServiceSipServlet extends SipServlet {
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(LocationServiceSipServlet.class);
    private static final String CONTACT_HEADER = "Contact";
    Map<String, List<URI>> registeredUsers = null;

    /** Creates a new instance of SpeedDialSipServlet */
    public LocationServiceSipServlet() {}

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        if(logger.isInfoEnabled()) {
            logger.info("the locationb service sip servlet has been started");
        }
        super.init(servletConfig);
        SipFactory sipFactory = (SipFactory)getServletContext().getAttribute(SIP_FACTORY);
        registeredUsers = new HashMap<String, List<URI>>();
        List<URI> uriList  = new ArrayList<URI>();
        uriList.add(sipFactory.createURI("sip:receiver@127.0.0.1:5090"));
        uriList.add(sipFactory.createURI("sip:receiver@127.0.0.1:6090"));

        registeredUsers.put("sip:receiver@sip-servlets.com", uriList);

        List<URI> perfUriList  = new ArrayList<URI>();
        perfUriList.add(sipFactory.createURI("sip:perf-receiver@127.0.0.1:5090"));      
        registeredUsers.put("sip:perf-receiver@sip-servlets.com", perfUriList);

        ArrayList<URI> failOverUriList  = new ArrayList<URI>();
        failOverUriList.add(sipFactory.createURI("sip:receiver-failover@127.0.0.1:5090"));
        registeredUsers.put("sip:receiver-failover@sip-servlets.com", failOverUriList);
    }

    @Override
    protected void doInvite(SipServletRequest request) throws ServletException,
            IOException {

        if(logger.isInfoEnabled()) {
            logger.info("Got request:\n" + request.toString());     
        }
        List<URI> contactAddresses = registeredUsers.get(request.getRequestURI().toString());
        if(contactAddresses != null && contactAddresses.size() > 0) {           
            Proxy proxy = request.getProxy();
            proxy.setRecordRoute(true);
            proxy.setParallel(true);
            proxy.setSupervised(false);
            proxy.proxyTo(contactAddresses);        
        } else {
            if(logger.isInfoEnabled()) {
                logger.info(request.getRequestURI().toString() + " is not currently registered");
            }
            SipServletResponse sipServletResponse = 
                request.createResponse(SipServletResponse.SC_MOVED_PERMANENTLY, "Moved Permanently");
            sipServletResponse.send();
        }
    }

    @Override
    protected void doRegister(SipServletRequest req) throws ServletException,
            IOException {
        if(logger.isInfoEnabled()) {
            logger.info("Received register request: " + req.getTo());
        }
        int response = SipServletResponse.SC_OK;
        SipServletResponse resp = req.createResponse(response);
        HashMap<String, String> users = (HashMap<String, String>) getServletContext().getAttribute("registeredUsersMap");
        if(users == null) users = new HashMap<String, String>();
        getServletContext().setAttribute("registeredUsersMap", users);

        Address address = req.getAddressHeader(CONTACT_HEADER);
        String fromURI = req.getFrom().getURI().toString();

        int expires = address.getExpires();
        if(expires < 0) {
            expires = req.getExpires();
        }
        if(expires == 0) {
            users.remove(fromURI);
            if(logger.isInfoEnabled()) {
                logger.info("User " + fromURI + " unregistered");
            }
        } else {
            resp.setAddressHeader(CONTACT_HEADER, address);
            users.put(fromURI, address.getURI().toString());
            if(logger.isInfoEnabled()) {
                logger.info("User " + fromURI + 
                    " registered with an Expire time of " + expires);
            }
        }               

        resp.send();
    }

    /**
     * {@inheritDoc}
     */
    protected void doResponse(SipServletResponse response)
            throws ServletException, IOException {
        if(logger.isInfoEnabled()) {
            logger.info("SimpleProxyServlet: Got response:\n" + response);
        }
        // session should not be invalidated so fast
//      if(SipServletResponse.SC_OK == response.getStatus() && "BYE".equalsIgnoreCase(response.getMethod())) {
//          SipSession sipSession = response.getSession(false);
//          if(sipSession != null) {
//              SipApplicationSession sipApplicationSession = sipSession.getApplicationSession();
//              sipSession.invalidate();
//              sipApplicationSession.invalidate();
//          }           
//      }
    }

}

conf/server.xml

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina" sipPathName="org.mobicents.ext" className="org.mobicents.servlet.sip.startup.SipStandardService" sipApplicationDispatcherClassName="org.mobicents.servlet.sip.core.SipApplicationDispatcherImpl" concurrencyControlMode="SipApplicationSession" congestionControlCheckingInterval="-1" darConfigurationFileLocation="conf/dars/mobicents-dar.properties" sipStackPropertiesFile="conf/mss-sip-stack.properties">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2"/>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->

    <!-- Define a SIP Connector on port 5080 -->
    <Connector port="5080" 
    ipAddress = "127.0.0.1"
    protocol="org.mobicents.servlet.sip.startup.SipProtocolHandler"
    signalingTransport="udp"/>

    <!-- Define the default TCP SIP Connector -->
    <Connector port="5080" 
         ipAddress = "127.0.0.1"
         protocol="org.mobicents.servlet.sip.startup.SipProtocolHandler"
         signalingTransport="tcp"/>

    <!-- Define the default TLS SIP Connector -->
    <Connector port="5081" 
         ipAddress = "127.0.0.1"
         protocol="org.mobicents.servlet.sip.startup.SipProtocolHandler"
         signalingTransport="tls"/>

    <!-- Define the default SIP Over WebSockets Connector -->
    <Connector port="5082" 
         ipAddress = "127.0.0.1"
         protocol="org.mobicents.servlet.sip.startup.SipProtocolHandler"
         signalingTransport="ws"/>

    <!-- Define the default Secure SIP Over WebSockets Connector -->
    <Connector port="5083" 
         ipAddress = "127.0.0.1"
         protocol="org.mobicents.servlet.sip.startup.SipProtocolHandler"
         signalingTransport="wss"/>

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine defaultHost="localhost" name="Catalina" className="org.mobicents.servlet.sip.startup.SipStandardEngine">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host className="org.mobicents.servlet.sip.startup.SipStandardHost" appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" configClass="org.mobicents.servlet.sip.startup.SipContextConfig">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

我能做些什么?

4

0 回答 0