I have already existed database. When I test my connection, I get this exception
java.sql.SQLInvalidAuthorizationSpecException: invalid authorization specification: SA
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at libraryapp.AppConnect.getConnection(AppConnect.java:17)
at libraryapp.TestAppConnection.main(TestAppConnection.java:7)
Caused by: org.hsqldb.HsqlException: invalid authorization specification: SA
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.rights.User.checkPassword(Unknown Source)
at org.hsqldb.rights.UserManager.getUser(Unknown Source)
at org.hsqldb.Database.connect(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source)
My connection class
public class AppConnect {
private static final String url ="jdbc:hsqldb:file:src/main/resources/db/library";
private static final String driver ="org.hsqldb.jdbcDriver";
private static final String user = "SA";
private static final String password = " ";
public Connection getConnection() {
Connection connection = null;
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, user, password);
connection.setAutoCommit(true);
System.out.println("Good connection");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
System.out.println("Failed to establish the connection :(");
}
return connection;
}
}
In pom.xml i have this
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.5.0</version>
</dependency>
If i change path to non-existent database, it's create and connect
The error means your connection URL finds the database but the combination of username and password is not correct.
The password you are using is a space, but the default password for a database is the empty string. Try changing it to:
private static final String password = "";
If that doesn't work, you need to find out what you originally used as username and password when you created the database.
Related
I am writing junit for post using rest-assured, and while executing
My Test Class:
public class PolicyResourceTest {
private static MockRESTServer server;
#BeforeClass
public static void setUpBeforeClass() throws Exception {
server = new MockRESTServer(8080, new PolicyResource());
server.start();
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
server.stop();
}
#Test
public final void testCreatePolicy() {
Policy policy=new Policy();
policy.setName("policy123");
RestAssured.with()
.contentType("application/json")
.accept("application/json")
.body(policy)
.post("/create")
.then()
.assertThat()
.statusCode(200);
}
My Resource Class:
#Path("/")
public class PolicyResource {
#POST
#Path("/create")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response test( Policy messageBody) {
System.out.println("policy: "+messageBody);
return Response.ok().status(200).build();
}
}
I am getting below exception:
org.apache.http.NoHttpResponseException: localhost:8080 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:257)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:207)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:684)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at io.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:2028)
at io.restassured.internal.http.HTTPBuilder.post(HTTPBuilder.java:349)
at io.restassured.internal.http.HTTPBuilder$post$2.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at io.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1202)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
#Anju Singh, Make sure your back end is working properly.
I tried the request on my local as we as on the mock api and was successfully able to test for Objects as well. The exception you received org.apache.http.NoHttpResponseException: localhost:8080 failed to respond is from the Server. There is no issue from RestAssured or JUnit to resolve.
#Test(enabled=true)
public void sampleTester() {
EnrollEmail email = new EnrollEmail();
email.setEmailAddress("sample#domain.com");
RestAssured.given().contentType(ContentType.JSON).body(email).when().post("https://jsonplaceholder.typicode.com/posts").then()
.assertThat()
.statusCode(201);
}
#Test(enabled=true)
public void sampleTester2() {
EnrollEmail email = new EnrollEmail();
email.setEmailAddress("sample#domain.com");
RestAssured.given().contentType(ContentType.JSON).body(email).when().post("http://localhost:8089/posts").then()
.assertThat()
.statusCode(201);
}
I have tried this simple example and after hours spent still can not resolve the problem. I was wondering if anyone has any idea?
import org.apache.jena.rdf.model.*;
import org.apache.jena.vocabulary.*;
/** Tutorial 1 creating a simple model
*/
public class Tutorial01 extends Object {
// some definitions
static String personURI = "http://somewhere/JohnSmith";
static String fullName = "John Smith";
public static void main (String args[]) {
// create an empty model
Model model = ModelFactory.createDefaultModel();
// create the resource
Resource johnSmith = model.createResource(personURI);
// add the property
johnSmith.addProperty(VCARD.FN, fullName);
}
}
After running the program..
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/jena/rdf/model/ModelFactory
at jena.Tutorial01.main(Tutorial01.java:17)
Caused by: java.lang.ClassNotFoundException:
org.apache.jena.rdf.model.ModelFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
Whenever I compile, i get this:
Exception in thread "main" java.io.IOException: Server returned HTTP
response code: 403 for URL: the link at
sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown
Source) at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source) at java.net.URL.openStream(Unknown Source) at
readdata.aaa.main(aaa.java:15)
My script is:
package readdata;
import java.net.*;
import java.io.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class aaa
{
public static void main(String[] args) throws Exception {
URL oracle = new URL(" the link ");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
a.append(inputLine);
in.close();
int i = 0;
Pattern p = Pattern.compile("Open");
Matcher m = p.matcher( a );
while (m.find()) {
i++;
System.out.println(i);
}
}
}
Is there anyway I can bypass the cloudflare in order to read the data from the URL ?
Before
URL oracle = new URL(" the link ");
insert :
System.setProperty("http.agent", "Chrome");
That's probably because CloudFlare prevent from unknown agent requests so this code set the User-Agent to Chrome who is recognized by CloudFlare.
Has anyone implemented OpenSessionInView yet on Spring WebSocket messages yet? I need to implement this and was hoping for some existing material.
I created some test stuff such as below, but I ran into TransactionExceptions, presumably because when you send back a reply, your session needs to cover both sending and receiving messages
public class OpenSessionInViewChannelInterceptor extends ChannelInterceptorAdapter{
#Inject
private SessionFactory sessionFactory;
#Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
SessionFactory sf = sessionFactory;
if (!TransactionSynchronizationManager.hasResource(sf)) {
// New Session to be bound for the current method's scope...
Session session = openSession();
try {
TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
return super.preSend(message, channel);
}
finally {
SessionFactoryUtils.closeSession(session);
TransactionSynchronizationManager.unbindResource(sf);
}
}
else {
// Pre-bound Session found -> simply proceed.
return super.preSend(message, channel);
}
}
protected Session openSession() throws DataAccessResourceFailureException {
try {
Session session = sessionFactory.openSession();
session.setFlushMode(FlushMode.MANUAL);
return session;
}
catch (HibernateException ex) {
throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
}
}
}
Exception
[MSA] DEBUG [2016-06-21T18:40:05,054] SimpAnnotationMethodMessageHandler.processHandlerMethodException(468) | Searching methods to handle HibernateException
[MSA] ERROR [2016-06-21T18:40:05,057] SimpAnnotationMethodMessageHandler.processHandlerMethodException(478) | Unhandled exception
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134) ~[spring-orm-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.appfuse.dao.hibernate.GenericDaoHibernate.flush(GenericDaoHibernate.java:165) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]
I want to add the contents of an arraylist has meu in a jsf page but playing me anything can you help me !!!! thnks
this is the method where i fill my arraylist from database in bean
public List<String> profession_pere_list;
public String profession_pere;
//....setters & getters
public List<String> getSelectProfessions() throws SQLException, NamingException{
profession_pere_list = new ArrayList<String>();
initctx = (Context) new InitialContext();
Context envContext = (Context) initctx.lookup("java:comp/env");
ds = (DataSource) envContext.lookup("jdbc/reinscription");
cnx = ds.getConnection();
state = cnx.createStatement();
rst = state.executeQuery("select profession from professions");
while(rst.next())
{
etu = new etudiants();
prof =rst.getString(1);
etu.setProfession_pere(prof);
//profession_pere=prof;
//etu.setProfession_pere(rst.getString(1).toString());
profession_pere_list.add(prof);
}
return profession_pere_list;}
and my jsf page:
<h:selectOneMenu value="#{etudiants.profession_pere}">
<f:selectItems value="#{etudiants.profession_pere_list}"/>
so i have this error unknown source !!!
javax.servlet.ServletException
javax.faces.webapp.FacesServlet.service(Unknown Source)
cause mère
java.lang.NullPointerException
com.sun.faces.renderkit.SelectItemsIterator$GenericObjectSelectItemIterator$GenericObjectSelectItem.updateItem(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$GenericObjectSelectItemIterator$GenericObjectSelectItem.access$600(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$GenericObjectSelectItemIterator.getSelectItemFor(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$IterableItemIterator.next(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator$IterableItemIterator.next(Unknown Source)
com.sun.faces.renderkit.SelectItemsIterator.next(Unknown Source)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(Unknown Source)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(Unknown Source)
com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(Unknown Source)
javax.faces.component.UIComponentBase.encodeEnd(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(Unknown Source)
com.sun.faces.application.view.MultiViewHandler.renderView(Unknown Source)
com.sun.faces.lifecycle.RenderResponsePhase.execute(Unknown Source)
com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
com.sun.faces.lifecycle.LifecycleImpl.render(Unknown Source)
javax.faces.webapp.FacesServlet.service(Unknown Source)
I had the same issue and the rason was a List modified concurently by different HTTP threads in ViewScoped bean:
#ViewScoped
public class Bean {
private List<Object> list;
public List<Object> getList() {
this.list = new ArrayList<>();
// code which modifies list
return this.list;
}
}
Solution - synchronize access to list:
public synchronized List<Object> getList() {
In my case I had sometimes your exception and sometimes ConcurrentModificationException.
I have also found another explanation:
http://www.adam-bien.com/roller/abien/entry/jsf_nullpointerexception_in_selectitemsiterator_java
When SelectItem label is null - you can also get your exception.