Merge pull request #343 from matzew/master
Adding simple CDI injection into resources
This commit is contained in:
commit
bda85f700a
4 changed files with 72 additions and 10 deletions
|
@ -253,6 +253,13 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- CDI -->
|
||||
<dependency>
|
||||
<groupId>javax.enterprise</groupId>
|
||||
<artifactId>cdi-api</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright Red Hat, Inc., and individual contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.keycloak.example.oauth;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomerDataProvider {
|
||||
|
||||
public List<String> getCustomers() {
|
||||
ArrayList<String> rtn = new ArrayList<String>();
|
||||
rtn.add("Bill Burke");
|
||||
rtn.add("Stian Thorgersen");
|
||||
rtn.add("Stan Silvert");
|
||||
rtn.add("Gabriel Cardoso");
|
||||
rtn.add("Viliam Rockai");
|
||||
rtn.add("Marek Posolda");
|
||||
rtn.add("Boleslaw Dawidowicz");
|
||||
return rtn;
|
||||
}
|
||||
}
|
|
@ -2,10 +2,10 @@ package org.keycloak.example.oauth;
|
|||
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -14,18 +14,14 @@ import java.util.List;
|
|||
*/
|
||||
@Path("customers")
|
||||
public class CustomerService {
|
||||
|
||||
@Inject
|
||||
private CustomerDataProvider provider;
|
||||
|
||||
@GET
|
||||
@Produces("application/json")
|
||||
@NoCache
|
||||
public List<String> getCustomers() {
|
||||
ArrayList<String> rtn = new ArrayList<String>();
|
||||
rtn.add("Bill Burke");
|
||||
rtn.add("Stian Thorgersen");
|
||||
rtn.add("Stan Silvert");
|
||||
rtn.add("Gabriel Cardoso");
|
||||
rtn.add("Viliam Rockai");
|
||||
rtn.add("Marek Posolda");
|
||||
rtn.add("Boleslaw Dawidowicz");
|
||||
return rtn;
|
||||
return provider.getCustomers();
|
||||
}
|
||||
}
|
||||
|
|
24
bundled-war-example/src/main/resources/META-INF/beans.xml
Normal file
24
bundled-war-example/src/main/resources/META-INF/beans.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright Red Hat, Inc., and individual contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
<beans xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
|
||||
|
||||
</beans>
|
Loading…
Reference in a new issue