Guice.createInjector error - eclipse-rcp

I'm trying to use mybatis-guice in eclipse 4 rcp project:
injector = Guice.createInjector(new MyBatisModule() {
#Override
protected void initialize() {
install(JdbcHelper.HSQLDB_Embedded);
bindDataSourceProviderType(PooledDataSourceProvider.class);
bindTransactionFactoryType(JdbcTransactionFactory.class);
addMapperClass(UserMapper.class);
Names.bindProperties(binder, createTestProperties());
bind(FooService.class).to(FooServiceMapperImpl.class);
}
});
and getting exception:
java.lang.NoSuchMethodError: org.mybatis.guice.AbstractMyBatisModule.bindInterceptor(Lcom/google/inject/matcher/Matcher;Lcom/google/inject/matcher/Matcher;[Lorg/aopalliance/intercept/MethodInterceptor;)
what i'm doing wrong?

Related

Capacitor plugin stop responding after exception

I'm using ionic and capacitor v2.5 for creating a plugin
I'm using the following code for catching unhandled exception in the capacitor plugin
public void load() {
super.load();
try {
Thread
.setDefaultUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable e) {
PluginCall call = getSavedCall();
if (call != null) {
call.error("called failed:"+e.getMessage());
}
freeSavedCall();
}
});
} catch (SecurityException e) {
Log.e(Constants.TAG_MASTER,
"Could not set the Default Uncaught Exception Handler:"
+ e.getStackTrace());
}
}
my problem is that whenever there is an unhandled exception, the plugin stop to respond to calls from the ionic app.
The code operates as "expected" in a sense that gets the call from the method that throwed the exception and the call.error(..); is executed.
I can replicate that with the following code
public void foo(PluginCall call) {
saveCall(call);
throw new exception();
}
Any thoughts on why the plugin stops to respond after that?

Vertx stop method not executed on service stop

When I stop the service the stop is not getting called but if try the same in test case where I deploy and undeploy verticle with deployment ID the stop method is executing.
EDIT:-
I am creating jar file (not a shadow Jar).
Below is build.gradle configuration
application{
mainClassName='io.vertx.core.Launcher'
}
def mainVerticleName = 'verticleName'
jar {
manifest {
attributes(
"Manifest-Version": "1.0",
"Main-Verticle": "$mainVerticleName",
"Main-Class": "io.vertx.core.Launcher",
"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
)
}
}
starting application :-
java -jar api-gateway-1.0.0-SNAPSHOT.jar -Dconfig.propertyFile="<property file path>" -DlogfilePath="<log file path>"
stopping application :-
CTRL+C
Creating CustomLauncher extending Launcher class worked.
#Log4j2
public class CustomLauncher extends Launcher {
public static void main(String[] args) {
new CustomLauncher().dispatch(args);
}
#Override
public void beforeStoppingVertx(Vertx vertx) {
log.info(" beforeStoppingVertx Called ===========");
cleanUPBeforeStoppingVerx();
}
#Override
public void afterStoppingVertx() {
log.info(" afterStoppingVertx Called ===========");
}
#Override
public void beforeDeployingVerticle(DeploymentOptions deploymentOptions) {
log.info(" beforeDeployingVerticle Called ===========");
}
#Override
public void beforeStartingVertx(VertxOptions options) {
log.info(" beforeStartingVertx Called ===========");
}
#Override
public void afterStartingVertx(Vertx vertx) {
log.info(" afterStartingVertx Called ===========");
}
#Override
public void handleDeployFailed(Vertx vertx, String mainVerticle, DeploymentOptions deploymentOptions,
Throwable cause) {
log.info("handleDeployFailed *****************");
vertx.close();
}
}
build.gradle changes :-
jar {
manifest {
attributes(
"Manifest-Version": "1.0",
"Main-Verticle": "LauncherVerticle",
"Main-Class": "CustomLauncher",
"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
)
}
}

Camel Restlet and CXF SOA Integration Issue

I am new to Camel and am facing an issue with a route I need to setup. It will be great if someone can either guide me to the correct forum or better still rectify the issue I am facing.
Here is what I need to do - expose a restlet endpoint to accept data; use this data as input to an external SOAP web service and send back the response in JSON format back to the caller...
Here is what I have done...however, I am getting the following error while Camel tries to call the Web Service...can anyone guide me here? Thanks.
I am using camel 2.11.1 and cxf-codegen-plugin version 2.7.11
I am getting the following exception: org.restlet.data.Parameter cannot be cast to java.lang.String.
public class IntegrationTest extends CamelTestSupport {
String restletURL = <url>;
#org.junit.Test
public void integTest() throws Exception {
//trying to simulate the rest service call...
template.sendBodyAndHeader(restletURL, "Body does not matter here", "data", "{\"FromCurrency\":\"AUD\",\"ToCurrency\":\"USD\"}");
}
#Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
#Override
public void configure() throws Exception {
System.out.println("In Counfigure");
String cxfEndpoint = "cxf://http://www.webservicex.net/CurrencyConvertor.asmx?"
+ "wsdlURL=http://www.webservicex.net/CurrencyConvertor.asmx?wsdl&"
+ "serviceName={http://www.webserviceX.NET/}CurrencyConvertor&"
+ "portName={http://www.webserviceX.NET/}CurrencyConvertorSoap&"
+ "dataFormat=MESSAGE";
XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("net.webservicex", new ServiceInterfaceStrategy(CurrencyConvertorSoap.class, true));
GsonDataFormat gson = new GsonDataFormat(ConversionRate.class);
gson.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
from(restletURL).routeId("Restlet")
.process(new Processor() {
#Override
public void process(Exchange exchange) throws Exception {
String data = (String) URLDecoder.decode((String) exchange.getIn().getHeader("data"), "UTF-8");
System.out.println(data);
// get the mail body as a String
exchange.getIn().setBody(data);
Response.getCurrent().setStatus(Status.SUCCESS_OK);
}
})
.unmarshal(gson)
.marshal(soap)
.log("${body}")
.to(cxfEndpoint)
.unmarshal(soap)
.marshal(xmlJsonFormat);
.log("${body}");
}
};
}
}
However, the sample works when I try out the individual pieces - restlet alone and CXF alone...
Thanks,
Ritwick.
Sure Willem, here is the entire configure implementation:
#Override
public void configure() throws Exception {
String restletURL = "restlet:http://localhost:8080/convert/{data}?restletMethods=get";
String cxfEndpoint = "cxf://http://www.webservicex.net/CurrencyConvertor.asmx?"
+ "portName={http://www.webserviceX.NET/}CurrencyConvertorSoap&"
+ "dataFormat=MESSAGE&loggingFeatureEnabled=true&defaultOperationName=ConversionRate&defaultOperationNamespace={http://www.webserviceX.NET/}&synchronous=true";
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("net.webservicex", new ServiceInterfaceStrategy(CurrencyConvertorSoap.class, true));
soap.setVersion("1.2");
GsonDataFormat gson = new GsonDataFormat(ConversionRate.class);
gson.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
from(restletURL).routeId("Restlet")
.process(new Processor() {
#Override
public void process(Exchange exchange) throws Exception {
String data = (String) URLDecoder.decode((String) exchange.getIn().getHeader("data"), "UTF-8");
exchange.getIn().setHeader("org.restlet.http.headers", "");
exchange.getIn().setHeader("data", "");
exchange.getIn().setBody(data);
Response.getCurrent().setStatus(Status.SUCCESS_OK);
}
})
.unmarshal(gson)
.marshal(soap)
.to(cxfEndpoint)
.unmarshal(soap)
.marshal(gson)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String output = exchange.getIn().getBody(String.class);
exchange.getOut().setBody(output);
}
});
}
The issue I was facing has been resolved. In addition to "exchange.getIn().setBody(data);", I added the following line of code "exchange.getIn().setHeader("org.restlet.http.headers", "");" in order to get rid of the class cast exception I was getting. The restlet headers were causing this issue and once these headers were removed (I didn't need the headers in the first place), everything worked as expected.
Thanks,
Ritwick.

jboss 7.1 jndi binding programmatically

How to bind to jndi custom object programmatically on jboss 7.1?
Context.bind throws exception indicating that jndi context is read-only.
Is it possible at all?
Yes, it is possible at all. The following code works in JBoss AS 7.1.1.Final:
#Stateless
public class JndiEjb {
private static final Logger LOGGER = LoggerFactory.getLogger(JndiEjb.class);
public void registerInJndi() {
try {
Context context = new InitialContext();
context.bind("java:global/JndiEjb", this);
} catch (NamingException e) {
LOGGER.error(String.format("Failed to register bean in jndi: %s", e.getMessage()));
}
}
public void retrieveFromJndi() {
try {
Context context = new InitialContext();
Object lookup = context.lookup("java:global/JndiEjb");
if(lookup != null && lookup instanceof JndiEjb) {
LOGGER.debug("Retrieval successful.");
JndiEjb jndiEjb = (JndiEjb)lookup;
jndiEjb.helloWorld();
}
} catch (NamingException e) {
LOGGER.error(String.format("Failed to register bean in jndi: %s", e.getMessage()));
}
}
public void helloWorld() {
LOGGER.info("Hello world!");
}
}
If you call first registerInJndi() and afterwards retrieveFromJndi() the object will be looked up and the method helloWorld()is called.
You will find more information here.

GWT+JPA Persistence.Exception source code not found

I'm trying to create a simple DB connection using JPA.
It works fine but when I try to Throw an Exception to the client I get the error:
[ERROR] [browsereditor] - Line 210: No source code is available for type javax.persistence.EntityExistsException; did you forget to inherit a required module?
[ERROR] [browsereditor] - Line 212: No source code is available for type javax.persistence.EntityNotFoundException; did you forget to inherit a required module?
I get no error in development mode and it compiles fine, but when the app module is loaded there is where I get the error.
I have the required imports in server/Composer and client/Presenter classes
import javax.persistence.EntityExistsException;
import javax.persistence.EntityNotFoundException;
I also added the following jars to the classpath and build path:
javax.persistence.jar
jpa-annotations-source.jar (http://code.google.com/p/google-web-toolkit/issues/detail?id=1830#c14)
I also tried adding to gwt.xml
<source path='client'/>
<source path='shared'/>
<source path='server'/>
Any ideas on how to tell eclipse where to find the source code??
Thanks
Here is the code:
//Create composer from Composer.class in server
public static Composer createComposer(String name)
throws EntityExistsException {
Composer comp = new Composer();
comp.setName(name);
comp.setId(1);
EntityManager entityManager = entityManager();
entityManager.getTransaction().begin();
entityManager.persist(comp);
entityManager.getTransaction().commit();
entityManager.close();
return comp;
}
///fire Request from createComposer(above) in Presenter.class
req.fire(new Receiver<ComposerProxy>() {
public void onSuccess(ComposerProxy arg0) {
ComposerProxy comp;
comp = arg0;
}
public void onFailure(Throwable caught)
throws Throwable {
// Convenient way to find out which exception
// was thrown.
try {
throw caught;
} catch (EntityExistsException e) {
} catch (EntityNotFoundException e) {
}
}});
}});
[ERROR] [browsereditor] - Line 210: No source code is available for type javax.persistence.EntityExistsException; did you forget to inherit a required module?
[ERROR] [browsereditor] - Line 212: No source code is available for type javax.persistence.EntityNotFoundException; did you forget to inherit a required module?
You can't use types such as EntityExistsException or EntityNotFoundException in client-side GWT code at all.
These are plain Java classes and GWT don't know how to translate them to JavaScript.
You can only use very limited part of external libraries in your client-side code. These libraries (like Visualisation for example) are designed and prepared specifically for client-side and require inheriting their GWT module in your application's module.
I think that what you really want to do is something like that:
public void onFailure(ServerFailure failure) throws Throwable {
if(failure.getExceptionType().equals("javax.persistence.EntityExistsException")){
...
}else if(failure.getExceptionType().equals("javax.persistence.EntityNotFoundException")){
...
}
}
Because you can read type of server-side exception as String, see Javadoc for Receiver and ServerFailure.
Thanks Piotr for your help.
Here is the code for what I finally did:
Code in the client
req.fire(new Receiver<ComposerProxy>() {
public void onSuccess(ComposerProxy arg0) {
ComposerProxy comp;
comp = arg0;
}
public void onFailure(ServerFailure failure) {
serverError.getServerError(failure,
"onAddButtonClicked");
}
});
I created a class to handle the errors
public class ServerError {
public ServerError() {
}
public void getServerError(ServerFailure failure, String message) {
// Duplicate Key Error
if (failure.getMessage().contains(
"IntegrityConstraintViolationException")) {
Window.alert("Duplicate Key " + message);
return;
}
// Connection Error
if (failure.getMessage().contains("NonTransientConnectionException")) {
Window.alert("Connection error ");
return;
}
// TimeOut Error
if (failure.getMessage().contains("TimeoutException")) {
Window.alert("Timeout Error" + message);
return;
}
// Other Error
else {
Window.alert("Duplicate Key " + message);
return;
}
}
}
Service in the server
public static Composer createComposer(String name) throws Throwable {
EntityManager entityManager = entityManager();
Composer comp = new Composer();
try {
comp.setName(name);
comp.setId(1);
entityManager.getTransaction().begin();
entityManager.persist(comp);
entityManager.getTransaction().commit();
} catch (Exception e) {
log.error("Error in Composer::createComposer( " + name + ") //"
+ e.toString());
throw e;
} finally {
entityManager.close();
}
return comp;
}
One problem I found is that the variable 'ServerFailure failure'only contains info in the failure.message; all the other variables are null.