replacement for camel cxfbean - apache-camel

we are currently struggling with updating our legacy service (non spring, jee + deltaspike, weld) and it's dependencies.
We try to upgrade from camel 2.16.2 to 3.x (due to java 11 compatibility).
We have already read through the migration guide several times, but could not find any reference to your replacement of the cxfbean component.
e.g.:
public class MonitoringRoute extends RouteBuilder {
#Override
public void configure() throws Exception {
from("servlet:///monitoring?matchOnUriPrefix=true")
.to("cxfbean:monitoringService")
.setId("MonitoringRoute");
}
}
#Named("monitoringService")
public class MonitoringService implements MonitoringAPI {
#Override
public String status() {
return "OK";
}
}
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
public interface MonitoringAPI {
#GET
#Path("status")
#Produces(MediaType.TEXT_PLAIN)
String status();
}
We already tried cxfrs:monitoringService, but this will led to "Uri is not absolute" exception.
Any idea to replace cxfbean properly?

Related

Download pdf for my web users

I'm having fun with pdfbox but still can't find usefull info about downloading this.
So, I've got button, when I click it - pdf is saved on my computer locally.
Controller:
#RequestMapping("/pdf")
public class DocumentCreateController {
#Autowired
private DocumentCreate DCpdf;
#RequestMapping(method=RequestMethod.GET)
public void getPDF() throws IOException{
DCpdf.getPDF();
}
}
Service:
package pl.asseco.portalhr.obiegdokum;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.springframework.stereotype.Service;
#Service
public class DocumentCreate {
public void getPDF() throws IOException{
PDDocument document = new PDDocument();
document.save("C:/myfolder/test.pdf");
document.close();
return;
}
}
Please help, what about I have to learn? What I need to use?

Why isn't Camel route test resolving placeholder endpoint?

I have a simple Camel route test class that I have expanded to use a placeholder for an endpoint.
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import java.util.Properties;
public class SimpleTestRoute extends CamelTestSupport {
#EndpointInject(uri = "{{test.route.out}}")
protected MockEndpoint resultEndpoint;
#Produce(uri = "direct:start")
protected ProducerTemplate template;
#Test
public void test() throws Exception {
}
#Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
#Override
public void configure() throws Exception {
from("direct:start").to("{{test.route.out}}");
}
};
}
#Override
protected CamelContext createCamelContext() throws Exception {
Properties props = new Properties();
props.setProperty("test.route.out", "mock:result");
CamelContext context = super.createCamelContext();
PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
pc.setOverrideProperties(props);
return context;
}
}
However, when I run I get
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: {{test.route.out}} due to: Property with key [test.route.out] not found in properties from text: {{test.route.out}}
at ...
Caused by: java.lang.IllegalArgumentException: Property with key [test.route.out] not found in properties from text: {{test.route.out}}
at ...
I have tried various combinations of brace locations without progress. Now I suspect the problem is that the override is not being set but I cannot see what I am doing wrong or how to resolve it.
FWIW, I am running camel 2.13.1

Ejb3 -Accessing Local Enterprise Beans Using the No-Interface View

I'm trying to learn EJB3,
I created an EJB project with just a bean class:
package com;
import javax.ejb.Local;
import javax.ejb.Stateless;
#Stateless
#LocalBean
public class MyBean {
public MyBean() {
// TODO Auto-generated constructor stub
}
public String getMessage(){
return "Hello";
};
}
I deployed this project on Jboss 6 , then i create a Java project (adding in the build path the ejbProject above and Jboss-client.jar to make RMI calls).
for testing , this is the class i created:
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.MyBean;
public class LanceProgram {
// #EJB
//public static MyBean mybean;
public static void main(String[] args) {
Context ctx;
try {
ctx = new InitialContext();
MyBean exampleBean = (MyBean) ctx.lookup("MyBean");
System.out.println(exampleBean.getMessage());
} catch (NamingException e) {
e.printStackTrace();
}
}
}
Normally, when running this, i should have a reference to MyBean,but it's null and i have this error message (using JNDI lookup):
Exception in thread "main" java.lang.ClassCastException: org.jnp.interfaces.NamingContext cannot be cast to com.MyBean
at LanceProgram.main(LanceProgram.java:17)
While with an EJB injection i have a NullPointerException !
this i my jndi.properties file specifications:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
I'm trying to make a call to a bean which doesn't implements an interface.
Thanks for helping

Change EndPoint details in CXF ServiceInfo

The environment CXF2.2.6 and Spring 2.5. On Startup JBOSS I need to read CXF properties and change End point details. From basic reading it gives me the idea that CXF Service Info class (org.apache.cxf.service.model.ServiceInfo) handle bindings,endpoints,messages,schemas and so on.
I can Extend CXFServlet and create my own custom servlet. Please advise me the way I can give my own details to Endpoint in startup and override what is given in Spring.xml
The below Spring bean should do what you wanted. Why do you want to override ServiceInfo class ? Any particular reason ?
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.ServletContextAware;
public class CXFConfig implements InitializingBean{
#Autowired
Bus cxfBus;
#Override
public void afterPropertiesSet() throws Exception {
EndpointImpl endpoint = new EndpointImpl(cxfBus, new GdsAutomationServiceProviderImpl());
endpoint.setAddress("/public/api/service/v1");//WSDL URL
endpoint.setPublishedEndpointUrl(getEndPointAddress());
endpoint.publish();
}
public Bus getCxfBus() {
return cxfBus;
}
public void setCxfBus(Bus cxfBus) {
this.cxfBus = cxfBus;
}
public String getEndPointAddress() {
// Soap address location you need to define here
return "address"
}
#Override
public void setServletContext(ServletContext context) {
context.getServerInfo();
}
}

Cannot Unit Test Using Fongo fails in 4.1.4 - worked in 3.1.4

https://github.com/sanjuthomas/spring-data-mongodb
I have try several examples such as the one above to understand how to unit test mongo applications using fongo. All the examples examples worked - including the one above but when I upgrade the pom to the latest releases supported in spring boot all the examples fail. It seems the application context is no longer getting loaded for the test. Is this unit test functionality broken or do I need to change the code?
Below is the code that fails and used to work in Spring 3 - now the rule fails stating that a mongo instance does not exist in the context:
package com.ourownjava.spring.data.mongo.repository;
import static com.lordofthejars.nosqlunit.mongodb.MongoDbRule.MongoDbRuleBuilder.newMongoDbRule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.foursquare.fongo.Fongo;
import com.lordofthejars.nosqlunit.annotation.ShouldMatchDataSet;
import com.lordofthejars.nosqlunit.annotation.UsingDataSet;
import com.lordofthejars.nosqlunit.mongodb.MongoDbRule;
import com.mongodb.Mongo;
import com.ourownjava.spring.data.mongo.model.Trade;
/**
* Spring Data MongoDB Repository Unit testcase.
*
* #author ourownjava.com
*
*/
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration
public class TestTradeRepository {
#Autowired
private ApplicationContext applicationContext;
#Rule
public MongoDbRule mongoDbRule = newMongoDbRule().defaultSpringMongoDb(
"trade-db");
#Autowired
private TradeRepository tradeRepository;
#Test
#ShouldMatchDataSet(location = "/testData/trade-t1.json")
public void shouldSaveTrade(){
tradeRepository.save(createTrade());
}
#Test
#UsingDataSet(locations = {"/testData/trade-t1.json"})
public void shouldFindByTraderId(){
final List<Trade> trades = tradeRepository.findByTraderId("papjac");
assertNotNull(trades);
assertTrue(trades.size() > 0);
assertEquals("papjac", trades.get(0).getTraderId());
}
#Test
#UsingDataSet(locations = {"/testData/trade-t1.json"})
public void shouldFindByExchangeCode(){
final List<Trade> trades = tradeRepository.findByExchangeCode("NYSE");
assertNotNull(trades);
assertTrue(trades.size() > 0);
assertEquals("NYSE", trades.get(0).getExchangeCode());
}
private Trade createTrade(){
final Trade trade = new Trade();
trade.setId("t1");
trade.setTraderId("papjac");
trade.setExchangeCode("NYSE");
trade.setValue(90.3);
return trade;
}
#Configuration
#EnableMongoRepositories
#ComponentScan(basePackageClasses = { TradeRepository.class })
static class MongoConfiguration extends AbstractMongoConfiguration {
#Override
protected String getDatabaseName() {
return "trade-db";
}
#Override
public Mongo mongo() {
return new Fongo("trade-test").getMongo();
}
#Override
protected String getMappingBasePackage() {
return "com.ourownjava.spring.data.mongo";
}
}
}
You have to use Annotation #Bean for mongo()
#Bean
#Override
public Mongo mongo() {
return new Fongo("trade-test").getMongo();
}

Resources