I am trying to create a v2 of a web service. For this I created a new package com.package.v2 where the remote interface has been declared. If I keep the class name of v2 same as v1, then I get an error during the deployment to glassfish server.
SEVERE|glassfish3.1.2|com.sun.jersey.spi.inject.Errors|_ThreadID=61;_ThreadName=Thread-2;|The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: The class com.package.v2.TestRESTServiceBA is an interface and cannot be instantiated.|#]
If I rename the v2 class to a different name then everything works fine. Can you please let me know how I can keep both the version with the same name?
More details:
INFO|glassfish3.1.2|com.sun.jersey.api.core.ScanningResourceConfig|_ThreadID=61;_ThreadName=Thread-2;|Root resource classes found:
interface com.package.v2.TestRESTServiceBA
interface com.package.v1.TestRESTServiceBA
Adding Code:
Version 1 Interface
package com.package.v1;
import java.util.Map;
import javax.ejb.Remote;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import com.package.common.dto.ResponseDTO;
#Remote
#Path("/v1/test")
public interface TestRESTServiceBA {
#GET
#Path("/headers")
#Produces("application/json")
ResponseDTO<Map<String, String>> getAllHeaders();
}
Version 1 Implementation
package com.package.v1;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.Stateless;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.package.common.dto.ResponseDTO;
import com.package.v1.TestRESTServiceBA;
#Stateless
public class TestRESTServiceBABean implements TestRESTServiceBA {
private static final Log LOG = LogFactory.getLog(TestRESTServiceBABean.class);
#Context
private HttpServletRequest request;
public TestRESTServiceBABean() {
}
#Override
public ResponseDTO<Map<String, String>> getAllHeaders() {
LOG.info("GET:v1/test/headers requested!");
final ResponseDTO<Map<String, String>> response = new ResponseDTO<>();
return response;
}
}
Version 2 interface
package com.package.v2;
import java.util.Map;
import javax.ejb.Remote;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import com.package.common.dto.ResponseDTO;
#Remote
#Path("/v2/test")
public interface TestRESTServiceBA2 {
#GET
#Path("/headers")
#Produces("application/json")
ResponseDTO<Map<String, String>> getAllHeaders();
}
Version 2 Implementation
package com.package.v2;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.Stateless;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.package.common.dto.ResponseDTO;
import com.package.common.model.DealerSpeedUser;
import com.package.v2.TestRESTServiceBA2;
#Stateless
public class TestRESTServiceBABean implements TestRESTServiceBA {
private static final Log LOG = LogFactory.getLog(TestRESTServiceBABean2.class);
#Context
private HttpServletRequest request;
public TestRESTServiceBABean2() {
}
#Override
public ResponseDTO<Map<String, String>> getAllHeaders() {
LOG.info("GET:v2/test/headers requested!");
final ResponseDTO<Map<String, String>> response = new ResponseDTO<>();
return response;
}
}
The error is telling you it can't create an instance of an interface because you've put the #Path #GET, #Produces, etc. annotations on the interface classes. Move those annotations to the TestRESTServiceBABean classes instead.
Related
I try to deploy a REST web service on my tomee.
i use apache-tomee-plus-8.0.6 with JDK 15
I create a web application called test
I create a class like this:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/test")
public class WebServiceApplication extends Application {
#Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(QueueContentWebService.class));
}
}
And another like this:
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
#Path("/queuecontent")
public class QueueContentWebService {
#POST
public Response getContent() {
return Response.status(200).entity("getContent is called").build();
}
}
Then i try this URL, with a browser and with postman in POST:
http://localhost:8080/test/test/queuecontent/
I only get 404 response... It seems that my web service is not deployed. Anybody can help me by saying what is missing?
When I tried to write negative unit test case for getting UnauthenticatedException which is user defined exception, After executing mockmvc code it is throwing me an exception back and test case is failed.
(org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
com.exception.UnauthenticatedException: Invalid Credentials!)*
#Test
public void loginUser_NotAuthorised() throws Exception {
User user = new User();
user.setUsername("user");
user.setPassword("");
when(loginService.loginUser(ArgumentMatchers.any(User.class)))
.thenThrow(new UnauthenticatedException("Invalid Credentials!"));
mockMvc.perform(post("/login").contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(user)).characterEncoding("utf-8").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isUnauthorized()).andDo(print()).andReturn();
}
This is the exception received
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.exception.UnauthenticatedException: Invalid Credentials!
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:167)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:134)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:134)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:134)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:183)
at com.tests.controller.LoginControllerTest.loginUser_NotAuthorised(LoginControllerTest.java:169)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:141)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: com.exception.UnauthenticatedException: Invalid Credentials!
at com.controller.LoginController.loginUser(LoginController.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
... 67 more
I also had doubt, what all possible ways of unit test cases can be written for combined Mockito and MockMVC and can you also share resources and example projects for the same?
LoginTestController class with all imports
package com.tests.controller;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static
org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static
org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static
org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static
org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static
org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static
org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Matchers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import com.beans.User;
import com.controller.LoginController;
import com.service.impl.LoginServiceImpl;
import com.exception.UnauthenticatedException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
#RunWith(SpringRunner.class)
#WebMvcTest(value = LoginController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
#ContextConfiguration(classes = { LoginController.class })
public class LoginControllerTest {
#Autowired
private MockMvc mockMvc;
#MockBean
LoginServiceImpl loginService;
#Autowired
private ObjectMapper mapper;
#Test
public void loginUser_NotAuthorised() throws Exception {
User user = new User();
user.setUsername("user");
user.setPassword("");
when(loginService.loginUser(ArgumentMatchers.any(User.class)))
.thenThrow(new UnauthenticatedException("Invalid Credentials!"));
mockMvc.perform(post("/login").contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(user)).characterEncoding("utf-8").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isUnauthorized())
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Invalid Cr
edentials!")).andDo(print())
.andReturn();
}
}
I think you need to change your expect to below one
mockMvc.perform(post("/login").contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(user)).characterEncoding("utf-8").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isUnauthorized()).andExpect(
MockMvcResultMatchers.jsonPath("$.message").value("Invalid Credentials!"));
I know its very old thread,
I had same issue as well, the culprit here is that your services implementation Mock object
Instead of this
when(loginService.loginUser(ArgumentMatchers.any(User.class)))
.thenThrow(new UnauthenticatedException("Invalid Credentials!"));
Use this
LoginServiceImpl loginService = Mockito.mock(LoginServiceImpl.class)
Mockito.doThrow(new UnauthenticatedException("Invalid Credentials!"))
.when(loginService)
.loginUser(ArgumentMatchers.any(User.class))
If you see above, you should mock your impl class and then pass that mock object to when and call your method.
It worked for me.
I am trying to generate SAML metadata for Service provider,I have created simple servlet and trying to generate metadata in a methoad doGet()
this is the code I have tried below
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpRetryException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import org.opensaml.Configuration;
import org.opensaml.saml2.metadata.EntityDescriptor;
import org.opensaml.xml.XMLObjectBuilderFactory;
public class MetadataProviderServlet extends HttpServlet{
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
PrintWriter writer = response.getWriter();
response.setContentType("text/html");
writer.println("Hello world");
String entityId = "www.sampleEntityId.com";
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
EntityDescriptor descriptor = (EntityDescriptor)(builderFactory.getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME).buildObject(EntityDescriptor.DEFAULT_ELEMENT_NAME));
descriptor.setEntityID(entityId);
}
}
But when I run the web application using one application server I got the NUllpointer Exception in particularly creation the object Entity Descriptor.Can Anyone please figure out what went wrong?
You need to initialise the OpenSAML library first. OpenSAML is initialised using the bootstrap method.
DefaultBootstrap.bootstrap();
I write about this on my blog here
I am trying to take ServletContext in my web service ,but WebServiceContext is always NULL.Can anyone tell what am I doing wrong, I am using spring framework and tomcat.
package com.xyz.webser;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
#WebService(serviceName = "myWebService", endpointInterface = "com.xyz.webser.MyWebService")
public class MyWebServiceImpl implements MyWebService {
#Resource
private WebServiceContext context;
public void setContext(WebServiceContext context) {
this.context = context;
}
I have created a new java file in service package used "implements ServletContextAware"
called that method from web service.
I am trying to get all the column families in the current keyspace I am using because I want to get rid of the error:
InvalidRequestException(why:[column family] already exists in keyspace)
My logic is to get all the Column Families in the current key space & check whether or not a particular column family appears in the returned list. So, I try:
KeyspaceDefinition keyspaceDef = HFactory.createKeyspaceDefinition("test");
...
List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs();
There seems to be a problem with creating the
List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs();
I did a System.out.println(keyspaceDef.getCfDefs()) and it returned
[]
an empty list - which is what I expected. What I cannot understand is why List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs(); is incorrect. Eclipse disagrees with the "List" portion of this line. Other than that, it appears that he code is right. Can some one please help me understand why this line is wrong or whether my approach is off?
Here's the full code snippet:
package org.cassandra.examples;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.*;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.model.thrift.ThriftConverter;
import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.thrift.Cassandra;
import me.prettyprint.cassandra.service.ThriftKsDef;
import me.prettyprint.hector.api.*;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.beans.HSuperColumn;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ColumnIndexType;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.SuperColumnQuery;
public class HectorTest {
private static String keyspaceName = "test3";
private static KeyspaceDefinition newKeyspaceDef;
private static Cluster cluster;
private static Keyspace ksp;
public static void main(String[] args) {
cluster = HFactory.getOrCreateCluster("test cluster", "xxx.xxx.x.xx:9160");
newKeyspaceDef = HFactory.createKeyspaceDefinition(keyspaceName);
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("MyKeyspace",
"ColumnFamilyName",
ComparatorType.BYTESTYPE);
List<ColumnFamilyDefinition> lCf = newKeyspaceDef.getCfDefs(); //= new ArrayList<ColumnFamilyDefinition>();
if((cluster.describeKeyspace(keyspaceName)) == null){
createSchema();
}
ksp = HFactory.createKeyspace(keyspaceName, cluster);
//Articles art = new Articles(cluster, newKeyspaceDef);
//cluster.dropColumnFamily(keyspaceName, "Articles");
}
public static void createSchema(){
cluster.addKeyspace(newKeyspaceDef,true);
}
}
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
List cannot be resolved to a type
at org.cassandra.examples.HectorTest.main(HectorTest.java:55)
Add
import java.util.List;
to you imports. In eclipse, CTRL-SHIFT-O will organize your imports for you, and add anything that is missing.