java.lang.reflect.InvocationTargetException when running Java code through exec-maven-plugin - java

I have been struggling with this for hours now.
I am trying to run a Java class with maven and am getting the following error
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:418)
at java.util.Properties.load0(Properties.java:337)
at java.util.Properties.load(Properties.java:325)
at com.services.utils.EnvHandler.getProperty(EnvHandler.java:26)
at com.services.agentsMonitor.MonitorAgentsTrigger.main(MonitorAgentsTrigger.java:77)
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project SupportUtilities:
An exception occured while executing the Java class. null:
InvocationTargetException: NullPointerException
The thing is I have been able to execute the project successfully when running from eclipse but not from the command prompt
This is my pom.xml where I have configured exec-maven-plugin v1.5.0
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.services</groupId>
<artifactId>SupportUtilities</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mockito.version>1.9.0</mockito.version>
<platform.messaging-jms-client.version>3.6.2.2</platform.messaging-jms-client.version>
<tibco.jms.client.version>7.0.1</tibco.jms.client.version>
<omslite.version>0.0.1-SNAPSHOT</omslite.version>
<logmon-parent-pom>2.2.2</logmon-parent-pom>
<fasterxml.jackson.jsonSchema>2.4.0</fasterxml.jackson.jsonSchema>
<fasterxml.jackson.databind>2.4.0</fasterxml.jackson.databind>
<fasterxml.jackson.core>2.4.0</fasterxml.jackson.core>
<ojdbc6.version>12.1.0.2.0</ojdbc6.version>
<commons-lang.version>2.1</commons-lang.version>
<log4j.version>1.2.16</log4j.version>
<json-simple.version>1.1</json-simple.version>
<apache.commons.io.version>1.4.0</apache.commons.io.version>
<netty.version>3.2.10.Final</netty.version>
<javax.jms.version>1.1</javax.jms.version>
<org.slf4j.version>1.6.2</org.slf4j.version>
<joda-time.version>2.9</joda-time.version>
<sling.commons.json.version>2.0.12</sling.commons.json.version>
<jsch.version>0.1.51</jsch.version>
<xercesImpl.version>2.8.0</xercesImpl.version>
<httpclient.version>4.5.1</httpclient.version>
<javax.mail.version>1.5.0-b01</javax.mail.version>
<poi-ooxml.version>3.9</poi-ooxml.version>
<JSON4J.version>1.1.0</JSON4J.version>
<exec-maven-plugin.version>3.1</exec-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>${json-simple.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.io</artifactId>
<version>${apache.commons.io.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>tibco.jms</groupId>
<artifactId>tibco_jms</artifactId>
<version>${tibco.jms.client.version}</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>${javax.jms.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.walmart.platform.messaging</groupId>
<artifactId>messaging-jms-client</artifactId>
<version>${platform.messaging-jms-client.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.json</artifactId>
<version>${sling.commons.json.version}</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>${jsch.version}</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xercesImpl.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${javax.mail.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi-ooxml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>JSON4J</artifactId>
<version>${JSON4J.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${fasterxml.jackson.core}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${fasterxml.jackson.databind}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
<version>${fasterxml.jackson.jsonSchema}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin> -->
</plugins>
</build>
</project>
The problem is that my code is not able to load a file that is located in my resources folder.
Below is the code for the EnvHandler Class that is there in my com.services.utils package
public Properties getProperty(String env, String mgmtSystem) throws IOException {
Properties prop = new Properties();
InputStream propFile = null;
/*
* Loading based on OMS/IMS
*/
if("OMS".equalsIgnoreCase(mgmtSystem)) {
/*
* Loading the properties file based on environment qa/qa2/prod
*/
if("qa".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/OMS/Credentials_qa.properties"); //I have error here
System.out.println("PropFile->" + propFile.toString());
prop.load(propFile);
return prop;
}
else if("qa2".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/OMS/Credentials_qa2.properties");
prop.load(propFile);
return prop;
}else if("prod".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/OMS/Credentials_prod.properties");
prop.load(propFile);
return prop;
}
} else if("IMS".equalsIgnoreCase(mgmtSystem)) {
/*
* Loading the properties file based on environment qa/qa2/prod
*/
if("qa".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/IMS/Credentials_qa.properties");
prop.load(propFile);
return prop;
}
else if("qa2".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/IMS/Credentials_qa2.properties");
prop.load(propFile);
return prop;
}else if("prod".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/Services/agentsMonitor/IMS/Credentials_prod.properties");
prop.load(propFile);
return prop;
}
}
return null;
}
Any help is highly appreciated.
Please comment if you need any more information
Update: Below is my project structure
--src/main/java
--com.services.agentsMonitor
--MonitorAgentsForTrigger.java
--com.services.logsMonitor
--MonitorLogsForConnectionIssues.java
--com.services.utils
--EnvHandler.java
--src/main/resources
--com.services.agentsMonitor
--OMS
--Credentials_qa.properties
--Credentials_qa2.properties
--Credentials_prod.properties
--IMS
--Credentials_qa.properties
--Credentials_qa2.properties
--Credentials_prod.properties

I have been struggling with this for days till I find that the error is because when running in windows the reourceUrl is not treated to be case sensitive, but when running on a unix machine it is treated case Sensitive, so the resource had mentioned com/Services instead of /com/services
if("OMS".equalsIgnoreCase(mgmtSystem)) {
/*
* Loading the properties file based on environment qa/qa2/prod
*/
if("qa".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/services/agentsMonitor/OMS/Credentials_qa.properties"); //I have error here
System.out.println("PropFile->" + propFile.toString());
prop.load(propFile);
return prop;
}
else if("qa2".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/services/agentsMonitor/OMS/Credentials_qa2.properties");
prop.load(propFile);
return prop;
}else if("prod".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/services/agentsMonitor/OMS/Credentials_prod.properties");
prop.load(propFile);
return prop;
}
} else if("IMS".equalsIgnoreCase(mgmtSystem)) {
/*
* Loading the properties file based on environment qa/qa2/prod
*/
if("qa".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/services/agentsMonitor/IMS/Credentials_qa.properties");
prop.load(propFile);
return prop;
}
else if("qa2".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/services/agentsMonitor/IMS/Credentials_qa2.properties");
prop.load(propFile);
return prop;
}else if("prod".equalsIgnoreCase(env)) {
propFile = EnvHandler.class.getResourceAsStream("/com/services/agentsMonitor/IMS/Credentials_prod.properties");
prop.load(propFile);
return prop;
}
}

Related

Java Lambda for spring-cloud version to 3.2.3/3.1.7 org/springframework/boot/ApplicationContextFactory: java.lang.NoClassDefFoundError

I'm trying change version for spring-cloud-function-adapter-aws from 3.0.7.RELEASE to either 3.1.7 or 3.2.3 (as Spring Cloud Function Vulnerability CVE-2022-22963) but getting error as it is not able to find the class
java.lang.NoClassDefFoundError: org/spring framework/boot/ApplicationContextFactory
at org.springframework.cloud.function.context.FunctionalSpringApplication.(FunctionalSpringApplication.java:67)
at org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.springApplication(AbstractSpringFunctionAdapterInitializer.java:378)
at org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.initialize(AbstractSpringFunctionAdapterInitializer.java:121)
at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.initialize(SpringBootStreamHandler.java:61)
at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.handleRequest(SpringBootStreamHandler.java:53)
Caused by: java.lang.ClassNotFoundException:
My Application.java
#ComponentScan
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
FunctionConfiguration.java
#Configuration
public class FunctionConfiguration {
private static Logger logger = LoggerFactory.getLogger(FunctionConfiguration.class);
#Autowired
ActionService service;
#Bean
public Function<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> containerService() {
return value -> {
try {
APIGatewayProxyResponseEvent responseEvent = checkHttpMethod(value);
if (responseEvent != null) {
responseEvent.setBody("Option Method");
return responseEvent;
} else {
return createResponseEvent(value);
}
} catch (Exception e) {
return new APIGatewayProxyResponseEvent().withBody(e.getMessage()).withStatusCode(500)
.withHeaders(createResultHeader(value));
}
};
}
private APIGatewayProxyResponseEvent checkHttpMethod(APIGatewayProxyRequestEvent event) {
APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
if (event.getHttpMethod() != null && event.getHttpMethod().equalsIgnoreCase("options")) {
responseEvent.setHeaders(createResultHeader(event));
responseEvent.setStatusCode(200);
return responseEvent;
} else
return null;
}
private APIGatewayProxyResponseEvent createResponseEvent(APIGatewayProxyRequestEvent event) {
APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
try {
responseEvent = service.actionMethod(event);
responseEvent.setHeaders(createResultHeader(event));
return responseEvent;
} catch (Exception e) {
logger.error("Error executing method", e);
responseEvent.setHeaders(createResultHeader(event));
responseEvent.setBody(e.getMessage());
responseEvent.setStatusCode(500);
return responseEvent;
}
}
private Map<String, String> createResultHeader(APIGatewayProxyRequestEvent event) {
Map<String, String> resultHeader = new HashMap<>();
resultHeader.put("Content-Type", "application/json");
resultHeader.put("Access-Control-Allow-Headers", "Content-Type");
resultHeader.put("Vary", "Origin");
try {
String origin = event.getHeaders().get("origin");
resultHeader.put("Access-Control-Allow-Origin", origin);
} catch (Exception e) {
logger.error("origin not exist to add");
}
resultHeader.put("Access-Control-Allow-Credentials", "true");
logger.info(" Headers added ");
return resultHeader;
}
}
pom.xml
4.0.0
com.app.lambda
springBootLambda
1.0.3
springBootLambda
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aws-lambda-java-core.version>1.2.1</aws-lambda-java-core.version>
<spring-cloud-function.version>3.0.7.RELEASE
</spring-cloud-function.version>
<wrapper.version>1.0.17.RELEASE</wrapper.version>
<aws-lambda-java-events.version>2.2.7</aws-lambda-java-events.version>
<aws-java-sdk-s3.version>1.11.792</aws-java-sdk-s3.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<scope>optional</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-aws</artifactId>
<version>${spring-cloud-function.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>${aws-lambda-java-core.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.672</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.672</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>${aws-lambda-java-events.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>${wrapper.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
</configuration>
</plugin>
</plugins>
</build>
serverless.yml
service: SpringBoot-Lambda
provider:
name: aws
runtime: java8
region: us-east-1
memory: 2048
timeout: 40
spring:
jpa:
hibernate.ddl-auto: update
generate-ddl: true
show-sql: true
jar file that will be uploaded and executed on AWS
package:
artifact: target/{project.artifactId}-${project.version}.jar
#define Lambda function
functions:
createMethod:
handler: org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler
events: # api gateway
- http:
path: pass
method: post
cors: true
environment: # environment variables
FUNCTION_NAME: SpringBoot-Lambda
You need to upgrade Spring Boot as well. You are using 2.3.0 and ApplicationContextFactory was added in 2.4, but 2.4.x is no longer supported.
You should upgrade to Spring Boot 2.5.12 or 2.6.6.

java.lang.LinkageError: ClassCastException:attempting to castjar: javax.ws.rs-api-2.0.1.jar

I am running below rest API in my code and it gives me the below error. I am not sure whether this is an issue with the jar. Please help me .
java.lang.LinkageError: ClassCastException: attempting to castjar:file:/C:/apache-tomcat-8.5.9/wtpwebapps/searchextractweb/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to jar:file:/C:/apache-tomcat-8.5.9/wtpwebapps/searchextractweb/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class
javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:146)
javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:120)
javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
com.sun.jersey.api.client.PartialRequestBuilder.type(PartialRequestBuilder.java:92)
com.sun.jersey.api.client.WebResource.type(WebResource.java:343)
com.tlr.searchextract.workflow.Workflow.retrieveSearchInfo(Workflow.java:1208)
com.tlr.searchextract.workflow.Workflow.createWorkflowRequest(Workflow.java:275)
com.tlr.searchextract.messages.SearchExtractEventHandler.createNewWorkflowRequest(SearchExtractEventHandler.java:675)
com.tlr.searchextract.messages.SearchExtractEventHandler.processRequest(SearchExtractEventHandler.java:134)
com.tlr.searchextract.messages.SearchExtractEventHandler.processMessage(SearchExtractEventHandler.java:65)
com.tlr.searchextract.messages.MessageHandler.routeMessage(MessageHandler.java:92)
com.tlr.searchextract.messages.MessageHandler.processMessages(MessageHandler.java:64)
com.tlr.searchextract.servlet.RequestModel.insertCurrentRequest(RequestModel.java:190)
com.tlr.searchextract.servlet.SEControllerServlet.insertRequestTemplate(SEControllerServlet.java:1344)
com.tlr.searchextract.servlet.SEControllerServlet.performTask(SEControllerServlet.java:1941)
com.tlr.searchextract.servlet.SEControllerServlet.doPost(SEControllerServlet.java:90)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
I have the below code for executing REST API
private void retrieveSearchInfo() {
// find out what type of workflow to create
searchType =
document
.getElementsByTagName("search.type")
.item(0)
.getFirstChild()
.getNodeValue();
try {
excludeMetaDoc =
document
.getElementsByTagName("exclude.metadoc")
.item(0)
.getFirstChild()
.getNodeValue();
} catch (Exception e) {
excludeMetaDoc = "";
}
try {
searchGroup =
document
.getElementsByTagName("search.group")
.item(0)
.getFirstChild()
.getNodeValue();
} catch (Exception e) {
searchGroup = "";
}
try{
imageDoc =
document
.getElementsByTagName("search.imagedoc")
.item(0)
.getFirstChild()
.getNodeValue();
}catch (Exception e) {
imageDoc = "";
}
//add the term "search" to the value of the searchLevel
//vaiable in order to fit the needs of the LTC request
searchLevel =
document
.getElementsByTagName("search.level")
.item(0)
.getFirstChild()
.getNodeValue();
if (searchLevel.equalsIgnoreCase("collection set")) {
searchLevel = "collectionset";
}
//collection or collection set name
searchName =
document
.getElementsByTagName("search.name")
.item(0)
.getFirstChild()
.getNodeValue();
searchNovusVersion =
document
.getElementsByTagName("search.novus.version")
.item(0)
.getFirstChild()
.getNodeValue();
searchNovusEnvironment =
document
.getElementsByTagName("search.novus.environment")
.item(0)
.getFirstChild()
.getNodeValue();
//check to see if the user wants either all of the guids
//for a collection or a collection set
if (searchType.equalsIgnoreCase("all guids")
|| searchType.equalsIgnoreCase("document count")) {
if("Norm".equalsIgnoreCase(searchGroup))
queryText = "=n-relbase";
else
queryText = "=n-document";
queryType = "boolean";
} else {
queryText =
document
.getElementsByTagName("search.query.text")
.item(0)
.getFirstChild()
.getNodeValue();
//escapte special characters
// escape any reserved characters
// Problem using an ampersand (&) in the Search query. Maestro translates it to an entity in the relevant data. Need to use the word "and".
queryText = escapeXML(queryText, "&", "and");
// queryText = escapeXML(queryText, "&", "&");
queryText = escapeXML(queryText, "<", "<");
queryText = escapeXML(queryText, ">", ">");
queryText = escapeXML(queryText, "'", "&apos;");
queryText = escapeXML(queryText, "\"", """);
//find the search type boolean or natural
queryType =
document
.getElementsByTagName("search.query.type")
.item(0)
.getFirstChild()
.getNodeValue();
}
try {
searchOutputResource =
document
.getElementsByTagName("search.output.resource")
.item(0)
.getFirstChild()
.getNodeValue();
searchOutputPath =
document
.getElementsByTagName("search.output.path")
.item(0)
.getFirstChild()
.getNodeValue();
searchOutputPrefix =
document
.getElementsByTagName("search.output.file.prefix")
.item(0)
.getFirstChild()
.getNodeValue();
} catch (Exception e) {
searchOutputResource = "";
searchOutputPath = "";
searchOutputPrefix = "";
if (searchOutputPrefix != null) {
if (searchOutputPrefix.length() == 0) {
searchOutputPrefix = "se";
}
} else {
searchOutputPrefix = "se";
}
//e.printStackTrace();
}
//now get the resource signon and password
String output="";
try {
Client client = Client.create();
System.out.println("resourceName: "+searchOutputResource);
WebResource webResource = client.resource("http://localhost:8080/searchextract/webapi/resource?isGroupAndResource=true&groupId="
+ requestGroup + "&resourceName=" + searchOutputResource);
ClientResponse response = webResource.type("application/json").get(ClientResponse.class);
if (response.getStatus() != 200)
{
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
output = response.getEntity(String.class);
ResultSetIterator rsi = new ResultSetIterator(output);
searchOutputResourceUser = rsi.getFieldValue("resource_signon");
searchOutputResourcePass = rsi.getFieldValue("resource_password");
} catch (RemoteException re) {
System.err.println(re.detail.getMessage());
if (re.detail.getMessage().indexOf("DuplicateKeyException") > -1) {
//throw new Exception("Duplicate record");
}
} catch (NamingException e) {
System.err.println("NamingException: " + e.getMessage());
System.err.println("Root cause: " + e.getRootCause());
System.err.println("Explanation: " + e.getExplanation());
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
Below is the pom.xml file
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tlr.searchextractproject</groupId>
<artifactId>parent-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.tlr.searchextractproject</groupId>
<artifactId>searchextract</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>searchextract</name>
<properties>
<jersey.version>2.16</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.16</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.16</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/jsr311-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.owlike</groupId>
<artifactId>genson</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.9.1</version>
</dependency>
<!-- uncomment this to get JSON support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>8.5.9</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>8.5.9</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>8.5.9</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq</artifactId>
<version>6.0.2.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.ibm/com.ibm.mqjms -->
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mqjms</artifactId>
<version>6.0.2.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.resource/connector -->
<dependency>
<groupId>javax.resource </groupId>
<artifactId>connector</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.dhbcore </artifactId>
<version>7.1.0.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>searchextract</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
This exception is thrown while executing the below line
ClientResponse response = webResource.type("application/json").get(ClientResponse.class)
I am using Java 8 and Tomcat 8
I have faced the same error with my code and could resolve by using jersey dependency version 2.34
POM dependency
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>3.0.0</version>
</dependency>
My Error Message
2021-09-22 08:32:23.839 INFO 10 --- [http-nio-9070-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.LinkageError: ClassCastException: attempting to castjar:file:/faw-qa-api/target/faw-qa-api-1.0-SNAPSHOT.jar!/javax/ws/rs/client/ClientBuilder.class to jar:file:/faw-qa-api/target/faw-qa-api-1.0-SNAPSHOT.jar!/javax/ws/rs/client/ClientBuilder.class] with root cause
java.lang.LinkageError: ClassCastException: attempting to castjar:file:/faw-qa-api/target/faw-qa-api-1.0-SNAPSHOT.jar!/javax/ws/rs/client/ClientBuilder.class to jar:file:/faw-qa-api/target/faw-qa-api-1.0-SNAPSHOT.jar!/javax/ws/rs/client/ClientBuilder.class
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:105)
I updated the dependency version of jersey-client and jersey-common to 2.34 and the issue was resolved.
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.34</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.34</version>
</dependency>

An attempt was made to call a method that does not exist. STS

When i run the STS(SpringBoot) application i get the below error:
The attempt was made from the following location: org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1321)
The following method did not exist:
javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/home/talha/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
jar:file:/home/talha/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.33/tomcat-embed-core-9.0.33.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/home/talha/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar
The suggestion in the ide is:
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
I guess there is something wrong with my pom.xml the code is as below:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.uni</groupId>
<artifactId>authorize</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>authorize</name>
<description>API for user registration and login with validation</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.jsontoken</groupId>
<artifactId>jsontoken</artifactId>
<version>1.0</version>
</dependency>
<!-- Thanks for using https://jar-download.com -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>authrize</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The main dependencies causing the error are:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.jsontoken</groupId>
<artifactId>jsontoken</artifactId>
<version>1.0</version>
</dependency>
I get the error only after adding the above dependencies, the need to add the dependencies is the below class:
package com.uni.authorize.service;
import java.security.InvalidKeyException;
import java.security.SignatureException;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Instant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import com.google.gson.JsonObject;
import com.uni.authorize.model.TokenKeys;
import com.uni.authorize.pojo.TokenObject;
import com.uni.authorize.repository.TokenKeysRepository;
import com.uni.authorize.service.CreateToken;
import net.oauth.jsontoken.JsonToken;
import net.oauth.jsontoken.crypto.HmacSHA256Signer;
#Configuration
public class CreateToken {
private static final Logger LOGGER = LoggerFactory.getLogger(CreateToken.class);
private static final String ISSUER = "UnI United Tech";
#Autowired
TokenKeysRepository tokenKeyRepository;
public TokenObject createToken(String userId) {
List<TokenKeys> tokenList = tokenKeyRepository.findAll();
TokenKeys tokenKeys = tokenList.get(0);
long accessTokenValidity = tokenKeys.getAccessTokenValidity();
long refreshTokenValidiry = tokenKeys.getRefreshTokenValidity();
String accessTokenKey = tokenKeys.getAccessKey();
String refreshTokenKey = tokenKeys.getRefreshKey();
String accessToken = generateAccessToken(userId, accessTokenKey, accessTokenValidity);
String refreshToken = generateRefreshToken(userId, refreshTokenKey, refreshTokenValidiry);
TokenObject tokenObject = new TokenObject();
tokenObject.setAccess_token(accessToken);
tokenObject.setRefresh_token(refreshToken);
tokenObject.setToken_type("bearer");
tokenObject.setExpires_in(accessTokenValidity);
tokenObject.setScope("read write trust");
return tokenObject;
}
private String generateAccessToken(String userId, String accessTokenKey, long accessTokenValidity) {
HmacSHA256Signer signer;
try {
signer = new HmacSHA256Signer(ISSUER, null, accessTokenKey.getBytes());
} catch (InvalidKeyException e) {
throw new RuntimeException(e);
}
// Configure JSON token
JsonToken token = new net.oauth.jsontoken.JsonToken(signer);
// token.setAudience(AUDIENCE);
DateTime dateTime = new DateTime();
long dateTimeMillis = dateTime.getMillis();
// DateTime currentTimeDateTime = new DateTime(dateTimeMillis);
// DateTime expiryTimeDateTime = new DateTime(dateTimeMillis + accessTokenValidity);
Instant currentTimeInstant = new org.joda.time.Instant(dateTimeMillis);
Instant expirationTimeInstant = new org.joda.time.Instant(dateTimeMillis + accessTokenValidity);
LOGGER.debug("Current Time Instant" + currentTimeInstant);
LOGGER.debug("Expiration Tine Instant" + expirationTimeInstant);
token.setIssuedAt(currentTimeInstant);
token.setExpiration(expirationTimeInstant);
// Configure request object, which provides information of the item
JsonObject request = new JsonObject();
request.addProperty("userId", userId);
JsonObject payload = token.getPayloadAsJsonObject();
payload.add("info", request);
try {
return token.serializeAndSign();
} catch (SignatureException e) {
throw new RuntimeException(e);
}
}
private String generateRefreshToken(String userId, String refreshTokenKey, long refreshTokenValidiry) {
HmacSHA256Signer signer;
try {
signer = new HmacSHA256Signer(ISSUER, null, refreshTokenKey.getBytes());
} catch (InvalidKeyException e) {
throw new RuntimeException(e);
}
// Configure JSON token
JsonToken token = new net.oauth.jsontoken.JsonToken(signer);
// token.setAudience(AUDIENCE);
DateTime dateTime = new DateTime();
long dateTimeMillis = dateTime.getMillis();
// DateTime currentTimeDateTime = new DateTime(dateTimeMillis);
// DateTime expiryTimeDateTime = new DateTime(dateTimeMillis + refreshTokenValidiry);
Instant currentTimeInstant = new org.joda.time.Instant(dateTimeMillis);
Instant expirationTimeInstant = new org.joda.time.Instant(dateTimeMillis + refreshTokenValidiry);
LOGGER.debug("Current Time Instant" + currentTimeInstant);
LOGGER.debug("Expiration Tine Instant" + expirationTimeInstant);
token.setIssuedAt(currentTimeInstant);
token.setExpiration(expirationTimeInstant);
// Configure request object, which provides information of the item
JsonObject request = new JsonObject();
request.addProperty("userId", userId);
JsonObject payload = token.getPayloadAsJsonObject();
payload.add("info", request);
try {
return token.serializeAndSign();
} catch (SignatureException e) {
throw new RuntimeException(e);
}
}
}
Please help me resolve this issue.
Thanks in advance
getVirtualServerName() was added in Servlet 3.1, but you included servlet-api-2.5.jar is your application.
Options:
Change your dependencies to include servlet-api-3.1.jar (or later)
Remove the servlet-api-2.5.jar dependency, since the correct version is included in the Embedded Tomcat file (tomcat-embed-core-9.0.33.jar).
Actually, you should never ship servlet-api.jar with your application, since it will be provided by the Servlet Container. Seems you're missing <scope>provided</scope> in your dependency tag for the servlet-api file.
I solved a similar issue by adding dependencyManagement.
Here is an example of my code where a version of org.springframework.cloud was the problem:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Getting an error in jdbcTemplate.queryForObject(sql, new Object[] { user.getUserId(), user.getPassword() }, String.class);

cant solve this exception
java.lang.NoSuchMethodError: org.springframework.dao.support.DataAccessUtils.nullableSingleResult(Ljava/util/Collection;)Ljava/lang/Object;
String sql = "SELECT uname FROM USER_DATA WHERE uid=? AND upass=?";
try {
System.out.println("2222222222222");
String userId = jdbcTemplate.queryForObject(sql, new Object[] {
user.getUserId(), user.getPassword() }, String.class);System.out.println("noooooo");
return userId;
} catch (Exception e) {
e.printStackTrace();
return null;
}
my versions
spring-boot-starter-parent 1.5.10.RELEASE,spring-boot-starter jdbc,
spring-boot-starter-web,spring-boot-starter-test,spring-boot-starter-tomcat
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
About lines are in pom which all need to change kindly help

Lucene exception NoSuchMethodError with version 6.4.0

I am relatively new to Lucene and playing with the latest version 6.4.0.
I have written a cutom analyzer class for doing synonyms,
public class MySynonymAnalyzer extends Analyzer {
#Override
protected TokenStreamComponents createComponents(String fieldName) {
Tokenizer source = new ClassicTokenizer();
TokenStream filter = new StandardFilter(source);
filter = new LowerCaseFilter(filter);
filter = new SynonymGraphFilter(filter, getSynonymsMap(), false);
filter = new FlattenGraphFilter(filter);
return new TokenStreamComponents(source, filter);
}
private SynonymMap getSynonymsMap() {
try {
SynonymMap.Builder builder = new SynonymMap.Builder(true);
builder.add(new CharsRef("work"), new CharsRef("labor"), true);
builder.add(new CharsRef("work"), new CharsRef("effort"), true);
SynonymMap mySynonymMap = builder.build();
return mySynonymMap;
} catch (Exception ex) {
return null;
}
}
In the line where I call getSynonymsMap(), I get the following exception:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.lucene.util.UnicodeUtil.UTF16toUTF8WithHash([CIILorg/apache/lucene/util/BytesRef;)I
at org.apache.lucene.analysis.synonym.SynonymMap$Builder.add(SynonymMap.java:192)
at org.apache.lucene.analysis.synonym.SynonymMap$Builder.add(SynonymMap.java:239)
at m2_lab4.MySynonymAnalyzer.getSynonymsMap(MySynonymAnalyzer.java:37)
at m2_lab4.MySynonymAnalyzer.createComponents(MySynonymAnalyzer.java:28)
at org.apache.lucene.analysis.Analyzer.tokenStream(Analyzer.java:162)
at org.apache.lucene.document.Field.tokenStream(Field.java:568)
Version 6.4.0 doesn't seem to have method UTF16toUTF8WithHash in class UnicodeUtil. I am using everything from lucene 6.4.0 and there doesn't seem to be any old versioned jar in my classpath. This is how my maven dependendies look like:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<lucene.version>6.4.0</lucene.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queries</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-facet</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-spatial</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>com.spatial4j</groupId>
<artifactId>spatial4j</artifactId>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
Any idea what's going on? I am specially puzzled by the [CIILorg/apache/lucene/util/BytesRef text inside the exception description.

Categories