Frage

I have the following code in my plugin's definition file:

def doWithWebDescriptor = { xml ->
  // Implement additions to web.xml (optional), this event occurs before
  xml.'welcome-file-list'[0] + {
    'security-constraint'({
      'web-resource-collection'({
        'web-resource-name'('Java Melody Monitoring')
        'url-pattern'('/monitoring')
      })
      'auth-constraint'({
        'role-name'('melody')
      })
    })

    'login-config'({
      'auth-method'('BASIC')
      'realm-name'('Restricted Area')
    })
  }
}

This adds "security-constraint" and "login-config" nodes to the web.xml file, however, I currently have it hard-coded to be added after the "welcome-file-list" node. What I can't figure out is how to simply tell it to add these nodes as the last nodes in the "web-app" root node.

War es hilfreich?

Lösung

Grab children, append after last child.

xml.children()[-1] + {
    'security-constraint'({
      'web-resource-collection'({
        'web-resource-name'('Java Melody Monitoring')
        'url-pattern'('/monitoring')
      })
      'auth-constraint'({
        'role-name'('melody')
      })
    })

    'login-config'({
      'auth-method'('BASIC')
      'realm-name'('Restricted Area')
    })
  }

Andere Tipps

While dmahapatro's answer will work, I believe that appendNode is the clearest way to go about it.

Something like this would work:

xml.appendNode {
    'security-constraint'({       
        'web-resource-collection'({         
            'web-resource-name'('Java Melody Monitoring')         
            'url-pattern'('/monitoring')       
        })       
        'auth-constraint'({         
            'role-name'('melody')       
        })     
    })      
    'login-config'({       
        'auth-method'('BASIC')       
        'realm-name'('Restricted Area')     
    })
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top