Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Data Rest lists strange "profile" service in 1.2.0.M2 #1718

Closed
mraible opened this issue Oct 15, 2014 · 4 comments
Closed

Spring Data Rest lists strange "profile" service in 1.2.0.M2 #1718

mraible opened this issue Oct 15, 2014 · 4 comments

Comments

@mraible
Copy link

mraible commented Oct 15, 2014

I upgraded my Spring Boot 1.1.7 app today to 1.2.0.M2 to use the rest.baseUri property. From my application.yml:

spring:
    data:
        rest.baseUri: /api

When I go to http://localhost:8080/api, I see the following:

{
  "_links" : {
    "patients" : {
      "href" : "http://localhost:8080/api/patients{?page,size,sort}",
      "templated" : true
    },
    "messages" : {
      "href" : "http://localhost:8080/api/messages{?page,size,sort}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://localhost:8080/api/alps"
    }
  }
}

There's a "profile" service listed that I never developed. If I try to hit its "href", it throws a 404. This doesn't happen in 1.1.7. With 1.1.7, I use a @configuration class to specify the prefix.

@Configuration
@Import(RepositoryRestMvcConfiguration.class)
public class RestDataConfig extends RepositoryRestMvcConfiguration {

    @Override
    protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        super.configureRepositoryRestConfiguration(config);
        try {
            config.setBaseUri(new URI("/api"));
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
}

And the result is:

{
  "_links" : {
    "patients" : {
      "href" : "http://localhost:8080/api/patients{?page,size,sort}",
      "templated" : true
    },
    "messages" : {
      "href" : "http://localhost:8080/api/messages{?page,size,sort}",
      "templated" : true
    }
  }
}

On a related note, I noticed that if I have an interface that extends PagingAndSortingRepository, it gets added to the list of APIs, regardless of whether it's annotated with @RepositoryRestResource. Is this as designed?

@odrotbohm
Copy link
Member

There are a few things going on here that are not necessarily related but I'll try to cover all of them:

The profile "service"

This is actually not a service but a resource pointed to by using the profile relation specified in RFC6906. Generally speaking it points clients to resources that describe the application level semantics of REST resources (i.e. What exactly does patients mean? What exactly is the page template variable for?). Spring Boot 1.2 upgraded to the Spring Data Evans release train that added support for that kind of metadata by using yet another RFC named Application Level Profile Semantics (ALPS). Basically any client that understands the profile relation and the ALPS+JSON media type can now make sense of the individual hypermedia elements and fields of a representation (to dynamically build forms or the like).

Long story short, this can be disabled by calling repositoryRestConfiguration.metadataConfiguration().setAlpsEnabled(false);. Not sure this is already exposed through Boot's application.properties (basically because the methods on RepositoryRestConfiguration were not necessarily designed for bean-style access) but we could definitely turn this ticket into an improvement request in that regard.

The 404 you see is due to a glitch in the Spring Data REST 2.2.0 release that breaks the wiring of the ALPS resources when using a base URI. So to see the stuff from above working, briefly try without a base URI. This glitch is already fixed in master and the bugfix branch of Spring Data REST and will ship with the first service release for Evans which Boot 1.2 GA will most likely use.

Non-annotated repositories exported

Yes, this is the default and doesn't actually depend on the repository interface you extend. Every Spring Data repository is exported by default, except it carries @RepositoryRestResource(exported = false) or is in package scope (if the latter shall be exposed nonetheless, @RepositoryRestResource(exported = true) will do the trick).

I guess your expectation stems from the fact that most of the examples use the explicit annotation but mostly to customize the rel or path of the exported resources.

Does that make sense? :)

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Oct 16, 2014
@mraible
Copy link
Author

mraible commented Oct 16, 2014

I tried the alps URL without the API prefix and it works. Thanks for the information on Spring Data repositories and how they're automatically exported.

@dsyer dsyer closed this as completed Oct 16, 2014
@dsyer dsyer removed the status: waiting-for-feedback We need additional information before we can continue label Oct 16, 2014
@mraible
Copy link
Author

mraible commented Oct 21, 2014

In the latest Spring Boot 1.2.0.BUILD-SNAPSHOT, Spring Data REST seems to take priority over my static files. I have a src/main/resources/static/index.html file that I've been using to serve up the homepage of my application. After a change last week, this now shows up as the the JSON I expect at the root of /api. So now I see the following at both / and /api:

{
  "_links" : {
    "patients" : {
      "href" : "http://localhost:8080/api/patients{?page,size,sort}",
      "templated" : true
    },
    "messages" : {
      "href" : "http://localhost:8080/api/messages{?page,size,sort}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://localhost:8080/api/alps"
    }
  }
}

@philwebb philwebb added this to the 1.2.0.RC1 milestone Oct 21, 2014
@wilkinsona
Copy link
Member

I believe that's another symptom of the problem that @olivergierke described above. It's this Spring Data REST issue and should be fixed in the 2.2.1 snapshots.

@philwebb philwebb removed this from the 1.2.0.RC1 milestone Oct 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants