Saturday, April 20, 2013

ByPassHttpAdapter | XML post to commerce URL

This is a very useful extension when you need to build an extension where if SOAP is not accepted and authToken based authentication is not an option for inbound request.
if you want an external site to post XML into commerce. This would be a good approach.

Sample code and wc-server.xml

public class BypassHttpProgramAdapterImpl extends HttpProgramAdapterImpl implements
HttpAdapter, HttpAdapterFactory {

/*override the method to return a null if bypass condition is true, you can add bypass condition as a custom XML element in wc-server.xml*/
public HttpAdapter createAdapter(HttpServletRequest request, HttpServletResponse  response, TypedProperty param ) {
    //check for extension code.
}


}

<HttpAdapter
      deviceFormatId="-10000"
      deviceFormatType="XmlHttp"
      deviceFormatTypeId="-10000"
      enabled="true"
      factoryClassname="com.custom.programadapter.XXBypassHttpProgramAdapterImpl" name="XML/HTTP">
      <ProgramAdapter>
        <SessionContext ....
          <SessionContextConfig/>
        </SessionContext>
        <Configuration
          supportedCharacterEncoding="ISO8859-1, UTF-8, utf-8"
          supportedContentTypes="text/xml, text/xml; charset=UTF-8, text/xml-SOAP, text/xml; charset=utf-8"
          supportedMessageMappers="WCS.SOAPINTEGRATION, WCS.INTEGRATION" supportedMethods="POST, M-POST"/>
      </ProgramAdapter>
    </HttpAdapter>

1 comment:

  1. Raj,
    I have a requirement to extend AbstractHttpAdapter. I created a subclass for it. But for some reason it is not getting called. Is there a specific way in which the adapter extension needs to be done? Could you please suggest?

    ReplyDelete