Business Archetype
Purpose
Referencing services
Service reference via annotation
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 8 9 |
|
REST
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package conf; | |
/* | |
* #%L | |
* Osgiliath integration tests JaxRS CDI | |
* %% | |
* Copyright (C) 2013 - 2015 Osgiliath | |
* %% | |
* 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. | |
* #L% | |
*/ | |
import helpers.cxf.exception.handling.jaxrs.mapper.ExceptionXmlMapper; | |
import java.util.Set; | |
import javax.inject.Inject; | |
import javax.ws.rs.ApplicationPath; | |
import javax.ws.rs.core.Application; | |
import net.osgiliath.features.karaf.jaxrs.cdi.HelloServiceJaxRS; | |
import org.apache.cxf.jaxrs.provider.JAXBElementProvider; | |
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; | |
import com.google.common.collect.Sets; | |
import com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider; | |
import com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON; | |
import com.wordnik.swagger.jaxrs.listing.ResourceListingProvider; | |
@ApplicationPath("/helloService") | |
public class CXFApplication extends Application { | |
@Inject private HelloServiceJaxRS helloService; | |
@Inject private ApiListingResourceJSON swaggerService; | |
@Override | |
public Set< Object > getSingletons() { | |
return Sets.< Object >newHashSet( | |
helloService, | |
swaggerService, | |
new JAXBElementProvider(), | |
new ExceptionXmlMapper(), | |
new ResourceListingProvider(), | |
new ApiDeclarationProvider(), | |
new JacksonJsonProvider()); | |
} | |
} |
Messaging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
@ApplicationScoped | |
@ContextName | |
public class HelloServiceJMS extends RouteBuilder implements HelloService { | |
private final transient DataFormat helloObjectJSonFormat = new JacksonDataFormat( | |
HelloEntity.class, Hellos.class); | |
/** | |
* The repository. | |
*/ | |
@Inject | |
@OsgiService | |
private transient HelloRepository helloObjectRepository; | |
/** | |
* JMS producer. | |
*/ | |
@Inject | |
@Uri("jms:topic:helloServiceQueueOut") | |
private transient ProducerTemplate producer; | |
/** | |
* saves element | |
* | |
* @param helloObject | |
* element to save | |
*/ | |
@Override | |
public void persistHello(@NotNull @Valid HelloEntity helloObject) { | |
log.info("****************** Save on JMS Service **********************"); | |
log.info("persisting new message with jms: " + helloObject.getHelloMessage()); | |
this.helloObjectRepository.save(helloObject); | |
ObjectMapper mapper = new ObjectMapper(); | |
try { | |
this.producer.sendBody( mapper.writeValueAsString(getHellos())); | |
} catch (CamelExecutionException | JsonProcessingException e) { | |
log.error("exception marshalling messages", e); | |
} | |
} | |
/** | |
* Returns all elements. | |
* | |
* @return all elements | |
*/ | |
@Override | |
public Hellos getHellos() { | |
final Collection<HelloEntity> helloObjects = this.helloObjectRepository.findAll(); | |
if (helloObjects.isEmpty()) { | |
throw new UnsupportedOperationException("You could not call this method when the list is empty"); | |
} | |
return Hellos.builder() | |
.helloCollection(helloObjects.stream().map(x -> x.getHelloMessage()).collect(Collectors.toList())).build(); | |
} | |
/** | |
* Deletes all elements. | |
*/ | |
@Override | |
public void deleteHellos() { | |
this.helloObjectRepository.deleteAll(); | |
} | |
/** | |
* receives JMS message. | |
* | |
* @throws Exception | |
* Persistence error | |
*/ | |
@Override | |
public void configure() throws Exception { | |
from("properties:{{helloApp.inQueueJMS}}"/*"jms:queue:helloServiceQueueIn"*/) | |
.log(LoggingLevel.INFO, "received jms message: ${body}").unmarshal(this.helloObjectJSonFormat).process(new Processor() { | |
@Override | |
public void process(Exchange exchange) throws Exception { | |
HelloServiceJMS.this.persistHello((HelloEntity) exchange.getIn().getBody()); | |
} | |
}); | |
} | |
} |
Validation
1 2 3 4 |
|
1 2 3 4 |
|
Integration testing
1 2 3 4 5 6 7 8 9 10 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|