Domanda

I'm new to this concept so I might be wrong in calling it a "multi-module project". In the software I'm making, there's one distinct unit with distinct inputs and outputs. I decided to pull it out and run it as a separate (web) service since it has other values in this stand-alone mode.

But the thing is, now the application which was previously blended with this unit has to run standalone, too. And that means there should be a new way for it to communicate with that unit by calling it's service endpoints which adds new layers of complexity (serializing and de-serializing not-so-simple data into XML and JSON). Is there a common practice for this in software engineering? Can I transmit the data in any other way?

The software is being written in Scala which runs on JVM and may or may not affect this story.

È stato utile?

Soluzione

If you can't have your original client ap connect to a server, then I would recommend the following module breakdown:

  • Service module with Java/Scala API
  • Web service module which wraps the service module with Rest/XML/JSON
  • Client module which calls directly to the Java/Scala API module

Altri suggerimenti

I'm afraid I can't offer anything on the Scala front, but as far as Java goes you should think of your new service as being in the Service layer of your application, whereas the REST/SOAP/Whatever interface to your service is defined in the Web/Servlet layer.

So let us say you have a service like the following in your com.myco.services package:

public interface PersonService {
    public Person createPerson(PersonIdentifier id, PersonType type);
    public Person retrievePerson(PersonIdentifier id);
    public void updatePerson(Person existingPerson);
    public void deletePerson(Person existingPerson);
    public boolean authenticatePerson(String personName, String password);
}

We'll take it as read that you have an PersonServiceImpl implementation of this that updates your database or whatever. In your application on the same JVM you can inject the PersonServiceImpl into your code and call the methods directly, without having to marshal or unmarshal the parameters.

In the Web layer you can have a separate PersonServiceController that is mapped to URLs in your servlet. When a URL like "http://myco.com/person/update" is hit, the body of the request can be passed to the controller like so:

public class PersonServiceController {
    private final PersonService personService; // Inject PersonServiceImpl in constructor
    ...

    public void updatePerson(String requestBody) {
        Person updatedPerson = unmarshalPerson(requestBody);
        this.personService.updatePerson(updatedPerson);
    }

    ...
}

Well, that's pretty much what people do with XML and JSON, what the goal of SOA is, what SOAP was created for, plus things like JMS, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top