Custom request handler fails at startup - vespa

I'm writing a custom RequestHandler, extending from ThreadedHttpRequestHandler, and after running vespa-deploy prepare and vespa-deploy activate the logs are showing a recurring error.
[2018-12-27 01:09:42.950] ERROR : container Container.com.yahoo.jdisc.core.StandaloneMain
JDisc exiting: Throwable caught:
exception=
java.lang.RuntimeException: Binding configured for non-jdisc request handler my.package.MyRequestHandler
at com.yahoo.container.jdisc.ConfiguredApplication.addHandlerBindings(ConfiguredApplication.java:348)
at com.yahoo.container.jdisc.ConfiguredApplication.intitializeAndActivateContainer(ConfiguredApplication.java:178)
at com.yahoo.container.jdisc.ConfiguredApplication.start(ConfiguredApplication.java:130)
at com.yahoo.jdisc.core.ApplicationLoader.start(ApplicationLoader.java:154)
at com.yahoo.jdisc.core.StandaloneMain.run(StandaloneMain.java:43)
at com.yahoo.jdisc.core.StandaloneMain.main(StandaloneMain.java:34)
My services.xml looks like this right now:
<?xml version="1.0" encoding="utf-8" ?>
<services version="1.0">
<container version="1.0">
<document-api />
<handler id="my.package.MyRequestHandler" bundle="my-vespa-bundle">
<binding>http://*/myendpoint</binding>
</handler>
<nodes>
<node hostalias="node1"/>
</nodes>
</container>
</services>
I've tried tracing as much as I could through the code and it looks like there's a check against a list of configured Components where this exception is coming from, but I'm not clear why my Handler is not being picked up by that.
vespa-deploy prepare is not showing any additional complaints about the structure of my code or config.

The most likely reason your handler is not being picked up is that you have embedded the RequestHandler class into your own bundle. This will prevent the JDisc framework's class loader from recognizing your handler as a subclass of the RequestHandler it uses as reference. You can verify this by running mvn dependency:tree. You'll probably see some vespa dependencies in scope compile, but they should have been provided.
Please take a look at the dependencies section of our sample project and try to update your pom.xml accordingly.

Related

How to configure dependencies for DataNucleus AppEngine plugin v3?

In my project (Spring Framework + Google App Engine + DataNucleus + JPA) I get the following exception on the server startup:
WARNING: Nestedin org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/db.xml]: Invocation of init method failed;
nested exception is java.lang.NoSuchMethodError: org.datanucleus.metadata.MetaDataUtils.parsePersistenceFiles(Lorg/datanucleus/plugin/PluginManager;Ljava/lang/String;ZLorg/datanucleus/NucleusContext;)[Lorg/datanucleus/metadata/PersistenceFileMetaData;:
java.lang.NoSuchMethodError: org.datanucleus.metadata.MetaDataUtils.parsePersistenceFiles(Lorg/datanucleus/plugin/PluginManager;Ljava/lang/String;ZLorg/datanucleus/NucleusContext;)[Lorg/datanucleus/metadata/PersistenceFileMetaData;
at org.datanucleus.api.jpa.JPAEntityManagerFactory.<init>(JPAEntityManagerFactory.java:342)
at org.datanucleus.api.jpa.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:91)
Obviously this exception is throwed during persistence.xml parsing. Spring tries to invoke method MetaDataUtils#parsePersistenceFiles(PluginManager,String,NucleusContext,nucCtx), but it is absent. This method is a part of org.datanucleus:datanucleus-core. At first I thought that I have a missing or duplicate dependency somewhere. I've executed
gradle dependencies
carefully scanned output and found nothing suspicious: only a single version of the dependency.
According to the documentation MetaDataUtils has only one parsePersistenceFiles method:
public static PersistenceFileMetaData[] parsePersistenceFiles(
PluginManager pluginMgr, String persistenceFilename, boolean validate, ClassLoaderResolver clr);
If you are observant, you've probably noticed that it differs in arguments: there is an extra boolean validate argument. Odd thing is that there is no such method in any version of DataNucleus. Why is DataNucleus looking for the method that haven't even existed? I can't get it.
Please help DataNucleus and me find the missing method!
UPDATE
As Neil Stockton pointed out it's because I'm using inconsistent versions of datanucleus-core and datanucleus-api-jpa. But I don't know the right combination of dependencies. And I'm starting to think, that DataNucleus App Engine Plugin 3.0 is not currently ready for usage.
I want to use DataNucleus App Engine Plugin 3.0 because of this issue (fixed in DataNucleus versions 3.2.6 and 3.3.3) and because I need JPA 2.1 features (fetch groups / entity graphs). The DataNucleus App Engine Plugin 3.0 is compatible with the mentioned versions of DataNucleus, but unreleased. I've checked out the plugin from SVN, packaged it, and added to my project as jar (an identical jar is available for download, if you want to repeat this setup yourself).
build.gradle:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
dependencies {
// App Engine
compile fileTree(dir: 'libs', include: ['*.jar']) // There is datanucleus-appengine-3.0.0-20140128.jar in libs
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.19'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.19'
// persistence
// App Engine and DataNucleus compatibility:
// https://code.google.com/p/datanucleus-appengine/wiki/Compatibility
compile 'org.eclipse.persistence:javax.persistence:2.1.0'
runtime 'org.datanucleus:datanucleus-core:3.2.15'
compile 'org.datanucleus:datanucleus-api-jpa:3.1.3'
compile 'javax.jdo:jdo-api:3.1'
compile 'org.datanucleus:datanucleus-jodatime:3.2.1'
// Spring Framework
compile("org.springframework:spring-webmvc:4.1.6.RELEASE")
compile ("org.springframework.data:spring-data-jpa:1.8.0.RELEASE")
providedCompile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.google.code.gson:gson:2.3.1'
providedCompile 'org.projectlombok:lombok:1.16.+'
}
appengine {
downloadSdk = true
httpAddress = "0.0.0.0"
}
Spring context:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
default-autowire="byName">
<jpa:repositories base-package="<my.package.name>.repositories" />
<!-- The simplest and the most limited form of JPA deployment -->
<!-- For details see http://docs.spring.io/spring/docs/current/spring-framework-reference/html/orm.html#orm-jpa -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="transactions-optional" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
Persistence unit
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true" />
<property name="datanucleus.NontransactionalWrite" value="true" />
<property name="datanucleus.ConnectionURL" value="appengine" />
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true" />
</properties>
</persistence-unit>
UPDATE:
If I put datanucleus-api-jpa of another version on CLASSPATH, for example
compile 'org.datanucleus:datanucleus-api-jpa:3.2.2'
I get an exception during enhancement:
java.lang.RuntimeException: Unexpected exception
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:76)
at com.google.appengine.tools.enhancer.Enhance.<init>(Enhance.java:71)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
... 5 more
Caused by: org.datanucleus.exceptions.NucleusException:
Plugin (Bundle) "org.datanucleus.api.jpa" is already registered.
Ensure you dont have multiple JAR versions of the same plugin in the classpath.
The URL "file:/<GRADLE_HOME>/appengine-sdk/appengine-java-sdk-1.9.19/lib/opt/tools/datanucleus/v2/datanucleus-api-jpa-3.1.3.jar" is already registered,
and you are trying to register an identical plugin located at URL "file:/<GRADLE_HOME>/caches/modules-2/files-2.1/org.datanucleus/datanucleus-api-jpa/3.2.2/c24c14634c39b5b9a59dcd379dbb6d93da97f3e7/datanucleus-api-jpa-3.2.2.jar."
at org.datanucleus.plugin.NonManagedPluginRegistry.registerBundle(NonManagedPluginRegistry.java:541)
at org.datanucleus.plugin.NonManagedPluginRegistry.registerBundle(NonManagedPluginRegistry.java:395)
From documentation:
The App Engine Java SDK includes version 2.x of the DataNucleus plugin for App Engine. This plugin corresponds to version 3.0 of the DataNucleus Access Platform, which enables you to use the App Engine Datastore via JPA 2.0.
JPA presents a standard interface for interacting with relational databases, but the App Engine datastore is not a relational database. As a result, there are features of JPA that App Engine simply cannot support.
The simple fact is that you have to use consistent versions of the various jars. If using Google's "datanucleus-appengine" v3.0 (SVN) then you MUST have DataNucleus project "datanucleus-core", "datanucleus-api-jpa" v3.2.x (or 3.3.x of the datanucleus-api-jpa) and no other versions. If you get some message about
Plugin (Bundle) "org.datanucleus.api.jpa" is already registered.
then you have multiple versions of that plugin in the CLASSPATH and you should FIX your CLASSPATH (just print out what is in the CLASSPATH and it will tell you ... something like System.getProperty("java.class.path")).
In your case you have
file://appengine-sdk/appengine-java-sdk-1.9.19/lib/opt/tools/datanucleus/v2/datanucleus-api-jpa-3.1.3.jar
and
file://caches/modules-2/files-2.1/org.datanucleus/datanucleus-api-jpa/3.2.2/c24c14634c39b5b9a59dcd379dbb6d93da97f3e7/datanucleus-api-jpa-3.2.2.jar
so get rid of the first one

Tomcat 6.0.35 - how to bypass new CSRF protection on the manager application?

I have a command line script (actually a git post-checkout hook) that reloads my Solr application by doing a cURL to:
http://localhost:8080/manager/html/reload?path=/solr
Since I upgraded to Ubuntu 13.04, it now fails, where it used to work before the upgrade.
The cause of the problem is that my newer version of Tomcat (6.0.35), has some new CSRF protection and it now returns 403 Access Denied.
How can I solve the issue and bypass the CSRF protection?
More info:
My /etc/tomcat6/tomcat-users.xml file:
<?xml version='1.0' encoding='utf-8'?>
<role rolename="manager"/>
<user username="tomcat" password="secret" roles="manager"/>
</tomcat-users>
The documentation for Configuring Manager Application access in tomcat mentions some new manager roles, however my error specifically mentions that the single "manager" role still exists for the moment (and I tried the other roles anyway without success).
(As I was writing the question, I found the answer.) Instead of cURLing to the HTML application, I needed to cURL to the "plain text interface".
i.e. instead of
http://localhost:8080/manager/html/reload?path=/solr
Use:
http://localhost:8080/manager/reload?path=/solr
It turns out:
The HTML interface is protected against CSRF but the text and JMX interfaces are not.
This fits with the new role called "manager-script". To ensure my app will work in the future I changed my /etc/tomcat6/tomcat-users.xml file:
<?xml version='1.0' encoding='utf-8'?>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="secret" roles="manager-gui,manager-script"/>
</tomcat-users>

Apache Camel error handler : Spring DSL

I have a question about adding an Apache Camel error handler to my config. I think I am doing something very silly that is probably a basic mistake.
I want to add two types of error handling...
<camel:errorHandler id="errorHandler" type="DefaultErrorHandler"
<camel:redeliveryPolicy maximumRedeliveries="0"/>
</camel:errorHandler>
and
<onException>
<exception>java.sql.SQLException</exception>
<redeliveryPolicy maximumRedeliveries="0"/>
<to uri="log:xml?level=ERROR"/>
</onException>
Every time I add these to my context xml files the xml editor in Eclipse tells me that I have invalid XML content. I must be missing a namespace or something. For the first type of catch all exceptions I am placing that outside my camel context to then reference errorHandlerRef. For the 2nd type of error handling specifically to catch sql exceptions I am placing that in the route itself.
Here is my XML declaration.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
Can anyone shed some light here pls... thanks

No declaration for cxfEndpoint in Servicemix deployment

I am trying to get a CXF endpoint working on Servicemix 4. I have created a Spring archetype with a CXF endpoint and successfully installed it with Maven. Having run osgi:install - s mvn: it installs onto Servicemix but the logs are displaying:
Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=springdm,
config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 21 in XML document
from URL [bundle://218.0:0/META-INF/spring/camel-context.xml] is invalid; nested exception is
org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'cxf:cxfEndpoint'
I have built this route just on Camel before with the following in my context.xml file:
<beans ...
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/tranposrts/camel http://cxf.apache.org/tranposrts/camel.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<cxf:cxfEndpoint id="wspoc"
address="http://localhost:8181/ws/ping"
serviceClass="net.ja.smx.springdm.PongImpl" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:wspoc"/>
<to uri="activemq:helloQ" />
</route>
</camelContext>
This is a clone of a working Camel context file but I cannot see why ServiceMix is throwing the error when it starts. The only difference is that the pom file does not use CXF as a dependency but it is in the section which I took from the online example.
I would be grateful for any pointers for any missing imports or corrections to the context file or anything that I ought to check for.
Many thanks.
Shortly after posting, I discovered that I was missing the camel-cxf dependency in my POM file which causes this error. I also needed to make sure that it was the right version as this caused an error in ServiceMix finding the correct META.cxf file.

Calling WCF service with forms authentication

I have wpf application that calls wcf service with forms authentication.
I added Service Reference to my solution, and in service configuration checked Generate asynchronous operations.
In code behind I created client to that reference,
than I attached event to fire after async method is completed,
then username and pass is setted:
client.ClientCredentials.UserName.UserName = txtUser.Text;
client.ClientCredentials.UserName.Password = passbox.Password;
client.IsAuthenticatedAsync(txtUser.Text, passbox.Password);
client.Close();
in IsAuthenticatedCompletedEventArgs I get error:
"The communication object, System.ServiceModel.Channels.HttpsChannelFactory+HttpsRequestChannel, cannot be used for communication because it has been Aborted."
Does anyone knows why this happens?
Thanks in advance!
To be honest, I haven't had a chance to test your scenario, but that error is a general error stating something went wrong while communicating with the service (this answer is more of a comment, but it's extensive and can't fit). You could get more info by putting the following lines at the end of the <configuration> section in your web.config and app.config:
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "ServiceTestWCFTrace.svclog" />
</listeners>
</source>
</sources>
After you get the error use svc log viewer to view the log: C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\SvcTraceViewer.exe
There you'll probably find the exact error that caused the Abort on the channel. Hope it helps.

Resources