The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20121231

eclipse svn cant commit file - at least one resource should be selected

i came across something weird when i was manually merging 2 projects (compare with > each other). i had copied a folder from Project A to Project B, then tried to commit the folder in Project B, but got the following message:

at least one resource should be selected



then when i deleted the folder and tried to commit the deletion instead (not knowing it wasn't in svn at all) i got the following message:

Some of selected resources were not added to version control.
Some of selected resources were not committed.
svn: Can't add '/home/me/workspaceJuno/projectB/testfolder/testfile.txt' to a parent directory scheduled for deletion

svn: Working copy '/home/me/workspaceJuno/
projectB/testfolder' locked



i finally figured out that the problem was that when i copy/pasted the testfolder inside eclipse, from Project A to Project B, it had copied the .svn folder inside testfolder as well, so eclipse thought it was already in svn in Project B. so when you copy folders inside eclipse from one project to another, you need to manually delete the .svn folder in a normal file browser, e.g. nautilus, then you will be able to commit the folder.

20121219

eclipse f3 stateless bean interface class name opening binary class file instead of java source file

i was editing a bean and when i clicked on the class name it implemented, eclipse opened a binary class file instead of the java source.

the problem was the order of my classpath entries. to fix this i right clicked on my project > properties > java build path > order and export

then i moved all the source folders to the top.

this page helped me out:
http://www.herikstad.net/2011/04/eclipse-opens-class-instead-of-java.html


apache directory studio not showing userPassword field

in an earlier post, i wrote about how to find ldap user passwords:
http://nickhumphreyit.blogspot.no/2012/01/how-to-list-openldap-ldap-user-info-in.html

but yesterday when i tried to view a user's password in apache directory studio, the record for a particular user wasn't showing any userPassword field. i finally figured out that my java code was accidentally setting the user's password to null, thus removing the userPassword field from the record, so it wasn't showing because it didn't exist! (facepalm) ;)

javax.persistence.PersistenceException: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance

i was trying to perform a simple delete operation in our ejb3/hibernate application and was getting the following error:
javax.persistence.PersistenceException: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: com.myapp.domainentitiesEJB3.party.Party.references
Transaction failed


the problem was in our Party entity class:
public void setReferences(List<Reference> references_) {
    this.references = references_;
}


it had to be changed to:
public void setReferences(List<Reference> references_) {
    if(this.references != null && references_ != null && !references_.isEmpty()){
        this.references.clear();
        for(int i = 0; i < references_.size(); i++){
            Reference lp = references_.get(i);
                this.references.add(lp);
        }
        this.references.addAll(references_);
    }
    else this.references.clear();
}


the problem was that we were trying to overwrite the collection, but by doing that, hibernate lost "ownership" of the collection and threw an error. it's best explained in the article Let's Play "Who Owns That Collection?" With Hibernate

20121218

sahi sah test script - ERROR missing ( before function parameters

i tried running a seemingly well-coded sahi test script, but i only got FAILURE every time i ran it. the log output was simply that my script was missing a left parenthesis somewhere (which wasn't the case i found out):
ERROR
missing ( before function parameters.


here's the sahi code that was failing:
...
view_invoice_specification_list();
...

and here's that function code:
function view_invoice_specification_list(){
    _click(_span("Fakturaspesifikasjon"));
    _assert(_isVisible(_tableHeader("Fakturaspesifikasjon")));
}



in the sahi dashboard i clicked "view parsed script" and saw the following weird output:
function view_invoice_specification_sahi._list(){
...
}

...
view_invoice_specification_sahi._list();
...


the problem turned out to be the use of the word "list" in the function name. i renamed the function name to view_invoice_specification_lst(), and then it worked. it also works if i put an underscore after "list", e.g. view_invoice_specification_list_()

20121216

java webservices basic auth username password WebServiceException: Failed to access the WSDL Server returned HTTP response code 401

in my post java webservices wsimport - parsing WSDL [ERROR] Server returned HTTP response code: 401 for URL: http://?wsdl needs authorization

i explained how i got an authentication error when trying to create webservices client code using wsimport and how i fixed the problem.

when i tried using the code to test my webservice i got a similar error when running my test code:

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://localhost:9001/wservice3/services/AdminWebService?wsdl. It failed with:
    Server returned HTTP response code: 401 for URL: http://localhost:9001/wservice3/services/AdminWebService?wsdl.
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:151)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
    at javax.xml.ws.Service.<init>(Service.java:76)
    at com.myapp.test.wservice3.server3.AdminWebServiceService.<init>(AdminWebServiceService.java:46)
    at com.myapp.test.wservice3.server3.Test.main(Test.java:8)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:9001/wservice3/services/AdminWebService?wsdl
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1403)
    at java.net.URL.openStream(URL.java:1031)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:793)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:251)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:118)
    ... 7 more



it's basically the same error i got when running wsimport because the service requires authentication to fix the problem i had to insert authorization code into the service.

here's a sample of the webservice code generated by wsimport in AdminWebServiceService:
static {
    URL url = null;
    try {
        URL baseUrl;
        baseUrl = com.myapp.test.wservice3.server3.AdminWebServiceService.class.getResource(".");
        url = new URL(baseUrl, "http://localhost:9001/wservice3/services/AdminWebService?wsdl");
    } catch (MalformedURLException e) {
        logger.warning("Failed to create URL for the wsdl Location: 'http://localhost:9001/wservice3/services/AdminWebService?wsdl', retrying as a local file");
        logger.warning(e.getMessage());
    }
    ADMINWEBSERVICESERVICE_WSDL_LOCATION = url;
}

 


to get things rolling i had to make the code look like this:
static {
    Authenticator.setDefault(new Authenticator() {
     @Override
     protected PasswordAuthentication getPasswordAuthentication() {
       return new PasswordAuthentication(
         "myusername",
         "mypassword".toCharArray());
     }
    });

    URL url = null;
    try {
        URL baseUrl;
        baseUrl = com.myapp.test.wservice3.server3.AdminWebServiceService.class.getResource(".");
        url = new URL(baseUrl, "http://localhost:9001/wservice3/services/AdminWebService?wsdl");
    } catch (MalformedURLException e) {
        logger.warning("Failed to create URL for the wsdl Location: 'http://localhost:9001/wservice3/services/AdminWebService?wsdl', retrying as a local file");
        logger.warning(e.getMessage());
    }
    ADMINWEBSERVICESERVICE_WSDL_LOCATION = url;
}


posts that helped me figure this out:
http://www.xinotes.org/notes/note/1081/
http://etfdevlab.blogspot.no/2009/12/http-basic-authentication-with-jax-ws.html

in the last post it mentions putting the Authenticator code in the constructor, but that wasn't the case for my code generated by wsimport. i had to put the Authenticator code into the static block at the top of the webservice service class.






 

here's what the full webservice service class code looks like:

package com.myapp.test.wservice3.server3;

import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.logging.Logger;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;


@WebServiceClient(name = "AdminWebServiceService", targetNamespace = "http://server3.wservice3", wsdlLocation = "http://localhost:9001/wservice3/services/AdminWebService?wsdl")
public class AdminWebServiceService
    extends Service
{

    private final static URL ADMINWEBSERVICESERVICE_WSDL_LOCATION;
    private final static Logger logger = Logger.getLogger(com.myapp.test.wservice3.server3.AdminWebServiceService.class.getName());

    static {
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
              return new PasswordAuthentication(
                "myusername",
                "mypassword".toCharArray());
            }
           });
        URL url = null;
        try {
            URL baseUrl;
            baseUrl = com.myapp.test.wservice3.server3.AdminWebServiceService.class.getResource(".");
            url = new URL(baseUrl, "http://localhost:9001/wservice3/services/AdminWebService?wsdl");
        } catch (MalformedURLException e) {
            logger.warning("Failed to create URL for the wsdl Location: 'http://localhost:9001/wservice3/services/AdminWebService?wsdl', retrying as a local file");
            logger.warning(e.getMessage());
        }
        ADMINWEBSERVICESERVICE_WSDL_LOCATION = url;
    }

    public AdminWebServiceService(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public AdminWebServiceService() {
        super(ADMINWEBSERVICESERVICE_WSDL_LOCATION, new QName("http://server3.wservice3", "AdminWebServiceService"));
    }
 

    @WebEndpoint(name = "AdminWebService")
    public AdminWebService getAdminWebService() {
        return super.getPort(new QName("http://server3.wservice3", "AdminWebService"), AdminWebService.class);
    }


    @WebEndpoint(name = "AdminWebService")
    public AdminWebService getAdminWebService(WebServiceFeature... features) {
        return super.getPort(new QName("http://server3.wservice3", "AdminWebService"), AdminWebService.class, features);
    }
}



and here's what my test class looks like that calls the webservice:

package com.myapp.test.wservice3.server3;

public class Test {
    public static void main(String[] args) {
        AdminWebServiceService awss = new AdminWebServiceService();
        AdminWebService aws = awss.getAdminWebService();
        System.out.println(aws.maxIdFromMessageCounter());
    }
}

three dots (ellipsis)/periods/full stops in java method parameter: "WebServiceFeature... features"

in my last post:
java webservices wsimport - parsing WSDL [ERROR] Server returned HTTP response code: 401 for URL: http://?wsdl needs authorization

i created a webservice client by using the commandline tool wsimport. in the generated code i noticed that one of the methods looked like this:

@WebEndpoint(name = "AdminWebService")
public AdminWebService getAdminWebService(WebServiceFeature... features) {
    return super.getPort(new QName("http://server3.wservice3", "AdminWebService"), AdminWebService.class, features);
}


notice the three dots (ellipsis) in the method parameters:
getAdminWebService(WebServiceFeature... features)

i wondered if this was an error, but it's also in the api:
http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/class-use/WebServiceFeature.html


then i found the java documentation about Arbitrary Number of Arguments:

You can use a construct called varargs to pass an arbitrary number of values to a method. You use varargs when you don't know how many of a particular type of argument will be passed to the method. It's a shortcut to creating an array manually...

To use varargs, you follow the type of the last parameter by an ellipsis (three dots, ...), then a space, and the parameter name. The method can then be called with any number of that parameter, including none.

20121214

java webservices wsimport - parsing WSDL [ERROR] Server returned HTTP response code: 401 for URL: http://?wsdl needs authorization

i tried automatically creating a java webservices client for the following wsdl:
http://localhost:9001/wservice3/services/AdminWebService?wsdl

but running the following command in a terminal:
wsimport -keep -verbose http://localhost:9001/wservice3/services/AdminWebService?wsdl

gave me the following error:
parsing WSDL...

[ERROR] Server returned HTTP response code: 401 for URL: http://localhost:9001/wservice3/services/AdminWebService?wsdl,  "http://localhost:9001/wservice3/services/AdminWebService?wsdl" needs authorization, please provide authorization file with read access at /home/me/.metro/auth or use -Xauthfile to give the authorization file and on each line provide authorization information using this format : http[s]://user:password@host:port//<url-path>


so to make it work i had to first create an authfile composed of the wsdl URI plus my username and password:
echo http://myUsername:myPassword@localhost:9001/wservice3/services/AdminWebService?wsdl > wsxauthfile

then i ran the wsimport command again, this time with the flag -Xauthfile:
wsimport -keep -verbose -Xauthfile wsxauthfile http://localhost:9001/wservice3/services/AdminWebService?wsdl

and it generated the code for me in the current directory (i ran it from ~/Downloads/)

:)

-------------------FYI----------------------
here's the output i saw:

parsing WSDL...
[INFO] Trying to read authorization file : "wsxauthfile"...
generating code...
wservice3/server3/AdminWebService.java
wservice3/server3/AdminWebServiceService.java
wservice3/server3/GetNextThousandNewMessageCounter.java
wservice3/server3/GetNextThousandNewMessageCounterResponse.java
wservice3/server3/GetNextThousandNewTransportRequest.java
wservice3/server3/GetNextThousandNewTransportRequestResponse.java
wservice3/server3/MaxIdFromMessageCounter.java
wservice3/server3/MaxIdFromMessageCounterResponse.java
wservice3/server3/MaxIdFromTransportRequest.java
wservice3/server3/MaxIdFromTransportRequestResponse.java
wservice3/server3/MinIdFromMessageCounter.java
wservice3/server3/MinIdFromMessageCounterResponse.java
wservice3/server3/MinIdFromTransportRequest.java
wservice3/server3/MinIdFromTransportRequestResponse.java
wservice3/server3/ObjectFactory.java
wservice3/server3/package-info.java

compiling code...

javac -d /home/me/Downloads/. -classpath /usr/lib/jvm/java-6-openjdk-amd64/lib/tools.jar:/usr/lib/jvm/java-6-openjdk-amd64/classes -Xbootclasspath/p:/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar /home/me/Downloads/./wservice3/server3/AdminWebService.java /home/me/Downloads/./wservice3/server3/AdminWebServiceService.java /home/me/Downloads/./wservice3/server3/GetNextThousandNewMessageCounter.java /home/me/Downloads/./wservice3/server3/GetNextThousandNewMessageCounterResponse.java /home/me/Downloads/./wservice3/server3/GetNextThousandNewTransportRequest.java /home/me/Downloads/./wservice3/server3/GetNextThousandNewTransportRequestResponse.java /home/me/Downloads/./wservice3/server3/MaxIdFromMessageCounter.java /home/me/Downloads/./wservice3/server3/MaxIdFromMessageCounterResponse.java /home/me/Downloads/./wservice3/server3/MaxIdFromTransportRequest.java /home/me/Downloads/./wservice3/server3/MaxIdFromTransportRequestResponse.java /home/me/Downloads/./wservice3/server3/MinIdFromMessageCounter.java /home/me/Downloads/./wservice3/server3/MinIdFromMessageCounterResponse.java /home/me/Downloads/./wservice3/server3/MinIdFromTransportRequest.java /home/me/Downloads/./wservice3/server3/MinIdFromTransportRequestResponse.java /home/me/Downloads/./wservice3/server3/ObjectFactory.java /home/me/Downloads/./wservice3/server3/package-info.java

20121206

how to add jboss 7 server in eclipse juno on ubuntu 12.04 - Missing classpath entry ...jboss-as-7.1.1.Final/bin/run.jar, no new server runtime environments were found

i imported a project of ours that uses jboss 7, but i wasn't able to create a new jboss 7 server instance in eclipse (on ubuntu linux 12.04). i got the following errors:
"Missing classpath entry /home/me/workspaceJuno/myJBoss7Project/jboss-as-7.1.1.Final/bin/run.jar"
and when i tried to use eclipse's "search" function:
window > preferences > server > runtime environments > search > (select jboss 7 folder "jboss-as-7.1.1.Final")i got the following error:
"no new server runtime environments were found"

in order to fix this i followed the suggestion here:
http://stackoverflow.com/questions/6802754/how-to-run-jboss-as-7-with-eclipse-3-6helios

and did this:
eclipse > help > install new software > work with: http://download.jboss.org/jbosstools/updates/development/juno/ > (hit enter) > JBoss Web and Java EE Development > (check) JBossAS Tools > next > next > (accept) > finish

you need to restart eclipse before you can proceed.

window > preferences > server > runtime environments > add > jboss community > (select) jboss 7.1 runtime > next > (set the home directory for your jboss 7 installation, e.g. for me it is /home/me/workspaceJuno/myJBoss7Project/jboss-as-7.1.1.Final) > (set your JRE, e.g. for me, i am using java-6-openjdk-amd64) > finish