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?
Related
I have some issue with the init constructor related to selenium webdriver's chrome instances.
Here are the pieces of my scripts:
First one named methods.py
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import paths
class PagePatterns(object):
def __init__(self, title=None):
self.driver = webdriver.Chrome('C:\Python27\chromedriver.exe')
self.title = title
def get_page_title(self):
return self.get_driver().title
Second one named login.py
from utils.methods import PagePatterns
from selenium.webdriver.common.by import By
from utils import paths
methods = PagePatterns()
class LoginPage(object):
def login(self):
country_choose = (By.XPATH, paths.country_list_login)
methods.click(country_choose)
Next one - register.py
from utils.methods import PagePatterns
from selenium.webdriver.common.by import By
from utils import utils, paths
from selenium.webdriver.support.wait import WebDriverWait
methods = PagePatterns()
class MainPage(object):
def open_homepage(self):
methods.open_base_page()
title_check = methods.get_page_title()
assert title_check == paths.page_title
The last one main_test.py is using LoginPage class
from register import MainPage
from login import LoginPage
MainPage().open_homepage()
LoginPage().login()
That's all about the code. My question is - when I am running main_test.py Chrome is called two times (two windows), but I want only one window of the browser - how to make it?
Thanks.
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.
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.