Question

I have the following urls that need mapping to two different servlets. Can anyone suggest a working url-pattern please?

vehlocsearch-ws:

/ws/vehlocsearch/vehlocsearch  
/ws/vehavailrate/vehavailratevehlocsearch  
/ws/vehavailrate/vehavailratevehlocsearch.wsdl

vehavailrate-ws:

/ws/vehavailrate/vehavailrate
/ws/vehavailrate/vehavailratevehavailrate  
/ws/vehavailrate/vehavailratevehavailrate.wsdl

So far I have this, which feels right, but isn't:

 <servlet-mapping>  
  <servlet-name>vehlocsearch-ws</servlet-name>  
  <url-pattern>*.vehlocsearch*</url-pattern>  
 </servlet-mapping>  
 <servlet-mapping>  
  <servlet-name>vehavailrate-ws</servlet-name>  
  <url-pattern>*.vehavailrate*</url-pattern>  
 </servlet-mapping>

Note: I have no control over the incoming urls

Was it helpful?

Solution 2

Using UrlRewriteFilter as suggested by Bozho I made the following changes:

added the reqrite filter to my web.xml:

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

Created a WEB-INF/urlreqrite.xml that looks like this:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE urlrewrite
    PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
    "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">

<urlrewrite>

    <rule>
        <from>/ws/vehavailrate/vehavailratevehlocsearch(.*)</from>
        <to type="forward">/ws/vehlocsearch/vehlocsearch$1</to>
    </rule>
    <rule>
        <from>/ws/vehavailrate/vehavailratevehavailrate(.*)</from>
        <to type="forward">/ws/vehavailrate/vehavailrate/$1</to>
    </rule>

</urlrewrite>

And changed my servlet-mappings in web.xml:

<servlet-mapping>
    <servlet-name>vehlocsearch-ws</servlet-name>
    <url-pattern>/ws/vehlocsearch/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>vehavailrate-ws</servlet-name>
    <url-pattern>/ws/vehavailrate/*</url-pattern>
</servlet-mapping>

OTHER TIPS

The url-pattern isn't that powerful. You can use the UrlRewriteFilter instead.

Or, to make it easier, use just one servlet, parse the request.getURL() and execute different code depending on that.

I don't think that request.getURL() exists, try String URL = request.getRequestURL().toString(); instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top