Alfresco 5.0: AuthenticationUtils.startSession generate 404 - java

I'm working on an old project and, due to the short time to deploy new release, I cannot migrate the upload of content using CMIS so, I need to use old WebServiceFactory code to create binary into Alfresco.
But, with the new release of Alfresco (5.0.a) I'm not able to obtain the authorization using:
WebServiceFactory.setEndpointAddress("http://localhost:8080/alfresco/api");
AuthenticationUtils.startSession(userName, password);
This is the error I'm getting:
Caused by: (404)Not Found
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
Any clue? Do you know if there a really (really really) fast way to create folder and update binary from Java classes?
thanks,
Andrea

Go grab the File Loader example from this code, edit the pom.xml to the latest version of everything, point it at your server, run, enjoy.

The problem is related only to the start of the first session, in our case, because the WebServiceFactory try to load the file "alfresco/webserviceclient.properties" by default.
We've resolved the issue with this workaround:
public static void startSession(String endpoint, String username, String password)
throws Exception {
try {
if (_log.isDebugEnabled()) {
_log.debug("Connecting to: " + endpoint);
}
/** fix for http 404 error during start first session
* needs to init {#link WebServiceFactory#loadedProperties} field to true and nothing else
*/
WebServiceFactory.getEndpointAddress();
/** fix for http 404 error during start first session*/
WebServiceFactory.setEndpointAddress(endpoint);
AuthenticationUtils.startSession(username, password);
if (_log.isDebugEnabled()) {
_log.debug("Start session with ticket: " + AuthenticationUtils.getTicket());
}
}
catch (Exception e) {
_log.error("Can not initiate session with Alfresco server.");
throw e;
}
}

Related

SVNKit java.lang.IndexOutOfBoundsException

I am using svnkit (standalone 1.8.12) to checkout an svn repository with java.
I tried several possibilities to do so (1, 2). Unfortunately, as soon as SVNkit starts to connect to the SVN server it crashes with the following stack trace (checkout, test connection, get revision number and so on). Checkout via terminal works just fine (using Ubuntu 14 with subversion installed), also open the used repo-url with a browser works just fine.
Exception in thread "main" java.lang.IndexOutOfBoundsException: Bounds exceeds available space : size=7, offset=8
at com.sun.jna.Memory.boundsCheck(Memory.java:185)
at com.sun.jna.Memory.getPointer(Memory.java:509)
at org.tmatesoft.svn.core.internal.util.jna.SVNGnomeKeyring.setPassword(SVNGnomeKeyring.java:334)
at org.tmatesoft.svn.core.internal.util.jna.SVNGnomeKeyring.setPassword(SVNGnomeKeyring.java:308)
at org.tmatesoft.svn.core.internal.util.jna.SVNJNAUtil.addPasswordToGnomeKeyring(SVNJNAUtil.java:170)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNPersistentAuthenticationProvider$GnomeKeyringPasswordStorage.savePassword(DefaultSVNPersistentAuthenticationProvider.java:696)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNPersistentAuthenticationProvider.savePasswordCredential(DefaultSVNPersistentAuthenticationProvider.java:416)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNPersistentAuthenticationProvider.saveAuthentication(DefaultSVNPersistentAuthenticationProvider.java:323)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager.acknowledgeAuthentication(DefaultSVNAuthenticationManager.java:274)
at org.tmatesoft.svn.core.auth.BasicAuthenticationManager.acknowledgeAuthentication(BasicAuthenticationManager.java:105)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:771)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:398)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:386)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.performHttpRequest(DAVConnection.java:863)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.exchangeCapabilities(DAVConnection.java:699)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.open(DAVConnection.java:118)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.openConnection(DAVRepository.java:1049)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.testConnection(DAVRepository.java:100)
at Main.svnCheckout(Main.java:131)
at Main.svnCheckoutPrep(Main.java:106)
at Main.main(Main.java:76)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
The code that produces this error is the following
static void svnCheckout(String url, String dest) throws SVNException {
/* Setup SVNKIT library */
setupSVNKit();
SVNRepository repository = null;
try {
repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
} catch (SVNException svne) {
System.err.println("error while creating an SVNRepository for the location '"
+ url + "': " + svne.getMessage());
System.exit(1);
}
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("someName", "somePWD");
repository.setAuthenticationManager(authManager);
repository.testConnection();
}
...
static void setupSVNKit(){
/* For using http:// and https:// */
DAVRepositoryFactory.setup();
}
Does anyone have an idea what I do wrong?
I would be so happy, if only the testConnection() function would work.
Since it is https, do I need to setup SVNkit to accept the fingerprint or similar?
Any help is highly appreciated!
markus
Alright, after many trials and errors I figured it out. Actually, I run into a different error using another repository. I did two things (not sure which one was the actual reason, maybe both of them).
Added the untrusted certificate (yes it was not validated) to the JVM
Added the following line to the VM options: -Dsvnkit.library.gnome-keyring.enabled=false
Further Reading:
Point 1: https://issues.tmatesoft.com/issueMobile/SVNOLD-290
Point 2: https://issues.tmatesoft.com/issue/SVNKIT-231

java.lang.NoSchMethodError: oracle.i118n.text.converter.CharacterConverterOGS.getInstancec(I)Loracle/i18n/text/converter/ChatacterConverter;

Ok this problem has stumped me completly, and I sure hope someone has an answer before I give up on this project completly.
Basicly I am trying to connect from a website pointing to a java servlet(2.5) and from there I want to use JDBC to connect to the DB.
The user and password are the DB credentials.
Now when I use the same dbconn file with a java class (printing success to the console) everything works like a charm, but if I try doing the same thing with the servlet it produces the error which can be seen below.
HTTP ERROR 500
Problem accessing /ClassChat/LogonSRV. Reason:
Server Error
Caused by:
java.lang.NoSchMethodError: oracle.i118n.text.converter.CharacterConverterOGS.getInstancec(I)Loracle/i18n/text/converter/ChatacterConverter;
at oracle.sql.converter.CharacterConverterFactoryOGS.make(CharacterConverterFactoryOGS.java:43)
at oracle.sql.CharacterSetWithConverter.getInstance(CharacterSetWithConverter.java:95)
at oracle.sql.CharacterSetFactoryThin.make(CharacterSetFactoryThin.java:95)
at oracle.sql.CharacterSet.make(CharacterSet.java:450)
at oracle.jdbc.driver.DBConversion.init(DBConversion.java:151)
at oracle.jdbc.driver.DBConversion.<init>(DBConversion.java:112)
at oracle.jdbc.driver.T4CConection.connect(T4CConection.java:1075)
at oracle.jdbc.driver.T4CConection.logon(T4CConection.java:301)
at oracle.jdbc.driver.PhysicalConnection.<init>(T4CConection.java:221)
at oracle.jdbc.driver.T4CConection.<init>(DBConversion.java:151)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at bl.dbConn.getConnection(dbConn.java:32)
at bl.Conny.Conns(Conny.java:30)
at bl.LogonSRV.service(LogonSRV.java:26)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
....
....
a link to the full error list : http://i.stack.imgur.com/O9DrL.jpg
I have attached the correct Jars for JDBC & Servlets, and tried every trick in the book including calling a regular java class which in turn calls the connection.
To make it easier to find the error, here is some of the code I am using:
[Line 26 in bl.LogonSRV] (the line producing the error).
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get the data from the jsp.
String strUser = request.getParameter("username");
String strPass = request.getParameter("password");
// In case this is the first time the page is loading.
if (strUser == null) {
// Redirect to login page.
request.getRequestDispatcher("Login.jsp").forward(request, response);
} else {
// Connect to the DB (the line producing the error).
String Error = Conny.Conns(strUser, strPass);
request.getRequestDispatcher("Success.jsp").forward(request, response);
}
}
[Line 30 in bl.Conny] (the line producing the error).
public static String Conns(String User, String Pass) {
Connection conni = null;
String Error = null;
try {
conni = dbConn.getInstance().getConnection(User, Pass);
} catch (SQLException ex) {
Error = "Error in connection";
}
return (Error)
}
[Line 32 in bl.dbConn] (the line producing the error).
// Connect to the DB.
public Connection getConnection(String Username, String Password) throws SQLException {
return (DriverManager.getConnection(SERVER_ADDRESS, Username, Password));
}
P.S. I know the connection needs to be closed, and that sending password is not safe, but first I want to see that it works, and how to fix this error.
Thank you all for the help, the problem ended up being that i had a previous .jar file on the project which was deleted but i didnt go through the deployment process again after deleting it.
I gues there are somethings you can only learn the hard way...
It may also occur when one has incompatible ojdbc driver and JDK along with orai18n.jar.
Using compatible ojdbc solved the problem for me.
Check the Oracle compatibility matrices for the appropriate ojdbc version.

Executing jar fails on a remote machine

I'm developing a RESTful web-service using Jersey. I am using maven to manage my dependencies and eclipse export method to create the jar.
When running the jar on my Ubuntu pc, everything is working fine, but when I'm executing the same jar on a remote Openshift server I'm experiencing this weird thing:
The server start and running, executing a GET request returns the expected answer.
Executing a POST method return a 500 server error, when on my local machine it returns the expected result.
Diving into this problem I have realised the following facts:
The last line the program is printing is validate.fullmessage: ... and the correct String message representation of the JSONObject. The "1" line is not printed to the log. No exception is thrown or written to the log as well!
public static boolean validate(String fullMessage) {
...
try {
System.out.println("validate.fullmessage: " + fullMessage);
JSONObject jsonMessage = new JSONObject(fullMessage);
System.out.println("1");
...
} catch (Exception e) {
System.out.println("validation exception");
e.printStackTrace();
}
...
}
Moreover, whenever I return 200 ok or server error I'm writing it to the log, but no error is written to the log. It seems like the server return 500 server error with no reason and not from my code...
RESTHandler:
#POST
#Consumes(MediaType.APPLICATION_JSON)
#Path("/createPlayer")
public Response createUser(String strPlayer) {
System.out.println("createPlayer. strPlayer: " + strPlayer);
Response r;
System.out.println("validating");
if (!ValidateHandler.validate(strPlayer)) {
System.out.println("validation failed!");
r = Response.serverError().build();
}
...
System.out.println("finished");
return r;
}
The "finished" is also not written to the log.
Can anyone help me figure out this weird behaviour?
Ok. So after temporarily changing the Exception handling to catch all Throwables (this way catching RuntimeErrors also, not only Exceptions), the problem turned out to be java versioning issue.
On the remote machine you are using a different version of java, probably older than the one which was used to compile one of your libraries.
The easy solution (if this is available) is upgrading your remote server java version to the one that is used on your computer locally.
If that is not an option, then you need to analyze the error and find and downgrade the library which is incompatible with your outdated server java version.

Connect Java Websocket endpoint to mySQL

We are building a websocket webapp for a school project and would like to store the incoming information to MySQL. Currently we are using netbeans and the Server Endpoint is written in Java. The info sent from the client side is a JSON obj. We can decode it but dont't know how to insert it into the table
Problems we are facing
1.We are used to programming Java application and using mysql JDBC but this time we cannot find the library to add, like we use to do.
2.We have tried AJAX but since the PHP is on a different server we cant do it, and I can't find the option to add a PHP file to the current project in netbeans. -- Currently I'm trying to learn how to do AJAX with JSP
3.We think we need to spin a thread so that the reply doesn't have to wait for the insert to complete but when we try to spin a thread the Endpoint no longer works, so we commented it out
4.We are trying to keep third party Frame works to a minimum
Below is the code to our Server Endpoint
public void onMessage(String message, Session session) {
// Create JsonObject from message
JsonObject jsonObject = new Message(message).getJObject();
// Decode JsonObject
message = Decoder(jsonObject);
for (Session peer : peers) {
try {
if (!peer.equals(session)) {
peer.getBasicRemote().sendText(message);
}
} catch (IOException ex) {
Logger.getLogger(ServerEndpoint.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
This is our current decoder. We wanted to spin a thread from this function, I don't know if that is a good idea or not
public String Decoder(JsonObject jObject) {
String message;
message = jObject.getString("msg");
return message;
}
Since Netbeans use Glassfish, I downloaded the MySQL JDBC and put it in the lib folder as I would if I was running Tomcat. Then I go into the Admin console and added the JDBC Connector then added the JDBC Resource. Next restart the server then redeploy the app.

How can i check if MySQL and Tomcat are running?

I've created a Java application that is split in different subcomponents, each of those runs on a separate Tomcat instance. Also, some components use a MySQL db through Hibernate.
I'm now creating an administration console where it's reported the status of all my Tomcat instances and of MySQL. I don't need detailed information, but knowing if they are running or not it's enough.
What could be the best solution to do that?
Thanks
Most straightforward way would be to just connect the server and see if it succeeds.
MySQL:
Connection connection = null;
try {
connection = DriverManager.getConnection(url, username, password);
// Succes!
} catch (SQLException e) {
// Fail!
} finally {
if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}
Tomcat:
try {
new URL(url).openConnection().connect();
// Succes!
} catch (IOException e) {
// Fail!
}
If you want a bit more specific status, e.g. checking if a certain DB table is available or a specific webapp resource is available, then you have to fire a more specific SELECT statement or HTTP request respectively.
I assume that you know the ports of which are running in advance (or from configuration files). The easiest way to check is to make socket connections to those ports like a telnet program does. Something like:
public boolean isServerUp(int port) {
boolean isUp = false;
try {
Socket socket = new Socket("127.0.0.1", port);
// Server is up
isUp = true;
socket.close();
}
catch (IOException e)
{
// Server is down
}
return isUp;
}
Usage:
isTomcatUp = isServerUp(8080);
isMysqlUp = isServerUp(3306);
However, I would say that is a false-negative check.. Sometimes it says server UP but the server is stuck or not responding...
I would make sure that what ever monitoring you setup is actually exercising some code. Monitoring the JVM via jmx can also be helpful after the fact. Check out http://www.cacti.net/ .
Firing a simple fixed query through MySQL
SELECT 'a-ok';
and have the .jsp return that a-ok text. If it times out and/or doesn't respond with a-ok, then something's hinky. If you need something more detailed, you can add extra checks, like requesting now() or something bigger, like SHOW INNODB STATUS.
The easiest thing is to look for the MySQL and Tomcat PID files. You need to look at your start scripts to make sure of the exact location, but once you find it, you simply test for existence of the pid file.
Create a servlet as a status page. In the servlet perform a cheap query, if the query succeeds let the servlet print OK otherwise Error. Put the servlet into a war and deploy it to all instances.
This could be used for checks in yor admin console by doing a loop over all instances.
I'd create a simple REST webservice that runs on each Tomcat instance and does a no-op query against the database. That makes it easy to drive from anywhere (command line, web app, GUI app, etc.)
If these are publicly available servers you can use a service like binarycanary.com to poll a page or service in your app.

Categories