@Override
  protected ModelAndView onSubmit(
      HttpServletRequest hreq, HttpServletResponse hres, Object o, BindException error)
      throws Exception {

    ConfirmWarnings cmd = (ConfirmWarnings) o;

    if (logger.isDebugEnabled()) logger.debug("Received CMD" + cmd);

    PolicyEnforcementRequest request = cmd.getRequest();

    EndpointDescriptor ed = request.getReplyTo();

    String location = ed.getResponseLocation();
    if (location == null) location = ed.getLocation();

    PolicyEnforcementResponse response = new PolicyEnforcementResponseImpl();

    Artifact a = getArtifactQueueManager().pushMessage(response);
    location += "?SSOArt=" + a.getContent();

    if (logger.isDebugEnabled()) logger.debug("Returing policy enforcemet response to " + location);

    return new ModelAndView(new RedirectView(location));
  }
  @Override
  public Object sendMessage(MediationMessage message) throws IdentityMediationException {

    if (logger.isTraceEnabled()) logger.trace("Sending new SPML 2.0 message using SOAP Binding");

    EndpointDescriptor endpoint = message.getDestination();

    String soapEndpoint = endpoint.getLocation();

    // ---------------------------------------------------------
    // Setup CXF Client
    // ---------------------------------------------------------
    Service service = Service.create(SPMLR2MessagingConstants.SERVICE_NAME);
    service.addPort(
        SPMLR2MessagingConstants.PORT_NAME,
        javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING,
        endpoint.getLocation());

    Object content = message.getContent();

    if (!(content instanceof RequestType)) {
      throw new IdentityMediationException("Unsupported content " + content);
    }

    String soapMethodName = content.getClass().getSimpleName();
    soapMethodName =
        "spml" + soapMethodName.substring(0, soapMethodName.length() - 4); // Remove Type

    if (logger.isTraceEnabled()) logger.trace("Using soap method [" + soapMethodName + "]");

    SPMLRequestPortType port =
        service.getPort(SPMLR2MessagingConstants.PORT_NAME, SPMLRequestPortType.class);

    if (logger.isTraceEnabled()) logger.trace("Sending SSO SOAP Request: " + content);

    try {
      Method soapMethod = port.getClass().getMethod(soapMethodName, content.getClass());

      Object o = soapMethod.invoke(port, content);

      if (logger.isTraceEnabled()) logger.trace("Received SSO SOAP Response: " + o);

      return o;

    } catch (NoSuchMethodException e) {
      throw new IdentityMediationException(
          "SOAP Method not impelmented " + soapMethodName + ": " + e.getMessage(), e);

    } catch (Exception e) {
      throw new IdentityMediationException(
          "SOAP Method not impelmented " + soapMethodName + ": " + e.getMessage(), e);
    }
  }
  @Override
  protected ModelAndView onSubmit(
      HttpServletRequest hreq, HttpServletResponse hres, Object o, BindException error)
      throws Exception {

    CollectUsernamePasswordClaims cmd = (CollectUsernamePasswordClaims) o;

    if (logger.isDebugEnabled()) logger.debug("Received CMD" + cmd);

    CredentialClaimsRequest cRequestCredential = cmd.getCredentialClaimsRequest();
    if (logger.isDebugEnabled())
      logger.debug(
          "Collecting usenrame/password claims for request "
              + (cRequestCredential != null ? cRequestCredential.getId() : "NULL"));

    ClaimSet claims = new ClaimSetImpl();
    claims.addClaim(new CredentialClaimImpl("username", cmd.getUsername()));
    claims.addClaim(new CredentialClaimImpl("password", cmd.getPassword()));
    claims.addClaim(new CredentialClaimImpl("rememberMe", cmd.isRememberMe()));

    CredentialClaimsResponse responseCredential =
        new CredentialClaimsResponseImpl(
            idGenerator.generateId(),
            null,
            cRequestCredential.getId(),
            claims,
            cRequestCredential.getRelayState());

    EndpointDescriptor claimsEndpoint = resolveClaimsEndpoint(cRequestCredential);
    if (claimsEndpoint == null) {
      logger.error("No claims endpoint found!");
      // TODO : Create error and redirect to error view using 'IDBusErrArt'
    }

    // We want the binding factory to use a binding component to build this URL, if possible
    Channel claimsChannel = cRequestCredential.getClaimsChannel();
    claimsChannel = getNonSerializedChannel(claimsChannel);

    String claimsEndpointUrl = null;
    if (claimsChannel != null) {

      MediationBindingFactory f = claimsChannel.getIdentityMediator().getBindingFactory();
      MediationBinding b =
          f.createBinding(
              SSOBinding.SSO_ARTIFACT.getValue(), cRequestCredential.getClaimsChannel());

      claimsEndpointUrl = claimsEndpoint.getResponseLocation();
      if (claimsEndpointUrl == null) claimsEndpointUrl = claimsEndpoint.getLocation();

      if (b instanceof AbstractMediationHttpBinding) {
        AbstractMediationHttpBinding httpBinding = (AbstractMediationHttpBinding) b;
        claimsEndpointUrl =
            ((AbstractMediationHttpBinding) b).buildHttpTargetLocation(hreq, claimsEndpoint, true);

      } else {
        logger.warn("Cannot delegate URL construction to binding, non-http binding found " + b);
        claimsEndpointUrl =
            claimsEndpoint.getResponseLocation() != null
                ? claimsEndpoint.getResponseLocation()
                : claimsEndpoint.getLocation();
      }
    } else {

      logger.warn(
          "Cannot delegate URL construction to binding, valid definition of channel "
              + cRequestCredential.getClaimsChannel().getName()
              + " not foud ...");
      claimsEndpointUrl =
          claimsEndpoint.getResponseLocation() != null
              ? claimsEndpoint.getResponseLocation()
              : claimsEndpoint.getLocation();
    }

    if (logger.isDebugEnabled())
      logger.debug("Using claims endpoint URL [" + claimsEndpointUrl + "]");

    Artifact a = getArtifactQueueManager().pushMessage(responseCredential);
    claimsEndpointUrl += "?SSOArt=" + a.getContent();

    if (logger.isDebugEnabled()) logger.debug("Returing claims to " + claimsEndpointUrl);

    hreq.getSession().removeAttribute("CollectUsernamePasswordClaims");

    return new ModelAndView(new RedirectView(claimsEndpointUrl));
  }