mardi 25 septembre 2018

Divide one external request into multiple internal ones and redirect to the specific handlers

I have soap service with 2 methods:

SendRequestReques and GetRequestResponse

In each method I receive wrapped request with internal request(8 types of internal request). This may look like:

public SendRequestResponse sendRequest(SendRequestRequest request){

    if(request.getInternalrequestType().equals("RequestFirst"))
      RequestFirst requestFirst = marshaller.marsla(request.getInteRnalrequest());
      //send this reuest to concrete handler
    } else if(request.getInternalRequestType().equals("RequestSecond"))
      RequestSecond requestSecond= marshaller.marsla(request.getInternalrequest());
      //send this reuest to concrete handler
    } else if(request.getInternalrequestType().equals("RequestLast"))
      RequestLast requestLast= marshaller.marsla(request.getInternalRequest());
      //send this reuest to concrete handler
    }
   ...

I use strategy pattern:

InternalRequestHandler handler = internalrequestsResolver.getInternalRequestHandler(request.getInternalrequestType())
handler.process(request);

And in each handler implement marshalind to concreate class and implemebt logic.

But now I want change it to annotations. I want create handlers for eacj internal request:

@MyHandler(type = MyType.TYPE1)
@Component
public class MyFirstController {
  ...
}

And when spring boot app started I want faind all beans with @MyHandler annotations and create esolver/factory/etc with this beans. So I still get the strategy pattern. but create a handlers when starting from the annotations. I do not know if this is a good idea, or not. but the question is how to do it. and the second question is how can you do otherwise?

if abstractly, then the logic is:

  1. Client send request like this:

    class ExternalRequest{ private Element any; //org.w3c.dom.Element contains any type }

  2. I get this request in my soap service in methode:

public ExternalResponse request(ExternalRequest external request)

  1. I extract type of internalRequest and InternalRequest by this type.

  2. I redirect internal request to specific handler.

Aucun commentaire:

Enregistrer un commentaire