NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Problems generating WSDL in NB6.8

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
zkidron



Joined: 02 Mar 2010
Posts: 13

PostPosted: Wed Mar 03, 2010 9:48 pm    Post subject: Problems generating WSDL in NB6.8 Reply with quote

So, Today I learned that NB 6.5 and 6.8 DO coexist as long as they each manage separate projects. NOT same projects. Which is logical and obvious (different conf files) except my combined JAVA+NB+Glassfish experience is all of 3 weeks...

But still I have the problem that NB6.8 will not generate my WSDL.

errors given are: "Could not create declaration for annotation type javax.ejb.Stateless" AND "Could not create declaration for annotation type javax.ejb.EJB"

From what I've read this problem stems from overloaded methods, which is not my case. I have only 1 method.

This exact same code worked fine with NB6.5.1 and GF2.1

Anyone can help on this?

Below my WS:



package Login;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
*
* @author xxxx
*/
@WebService
@Stateless
public class LoginWS {
@EJB
private LoginRemote ejbRef;// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Web Service Operation")

@WebMethod(operationName = "Validar")
public String Validar(@WebParam(name = "un")
String un, @WebParam(name = "pw")
String pw) {
return ejbRef.Validar(un, pw);
}

}



And my class:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package Login;

//import javax.annotation.Resource;
import javax.ejb.*;
import javax.persistence.*;
//import javax.sql.DataSource;

/**
*
* @author xxxx
*/
@Stateless
public class Login implements LoginRemote {

public Login() {
}

@PersistenceContext
EntityManager em;

public String Validar(String un, String pw) {

String u = finduser(un, pw);

if ( u.equals("")) {
System.err.println("Usuario no existe: "+un);
return u;}


System.err.println("Parameter USUARIO recibido:"+un);
System.err.println("Parameter PASSWORD recibido:"+pw);
System.err.println("-----------------------------------------------------");
System.err.println("-----------------------------------------------------");

return "Usuario: "+u;

// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}

public String finduser(String username, String clave) {
try {
return (String) em.createQuery("SELECT u FROM Usuarios u WHERE u.usuario = :usuario and u.passw= :passw").setParameter("usuario", username).setParameter("passw",clave).getSingleResult().toString();
} catch (NoResultException e) {
return "";
}
}
}
Back to top
zkidron



Joined: 02 Mar 2010
Posts: 13

PostPosted: Wed Mar 03, 2010 10:32 pm    Post subject: Confusing.... Reply with quote

Shocked

I created a new project, does nothing but the "add" WS.

Actually works and now I know 5+6 are still 11.

WSDL file STILL fails to generate, same error message.
Back to top
Jeff Rubinoff
Posted via mailing list.





PostPosted: Thu Mar 04, 2010 4:30 pm    Post subject: Re: Problems generating WSDL in NB6.8 Reply with quote

I've run into the same issue myself.
First, the (rather ugly) workaround:
  1. Comment out the @Stateless and @EJB annotations in your code. Clients of your WS don't need to know if it's an EJB or not.
  2. Generate the WSDL
  3. Uncomment the annotations
Now some background. This is not a NetBeans issue. This is an issue with the wsgen utility in JAX-WS, which does not recognize javax.ejb.* annotations. It does not recognize these annotations because they are only possible in web service code in the recently introduced EE 6 specification, and because they are irrelevant to how the web service is consumed. Unfortunately the wsgen utility has not been updated to ignore these annotations, or at least it doesn't ignore them when you generate the WSDL from the java code. (The automatic buildtime generated WSDL is fine.) I don't really understand the nuts and bolts of wsgen but the problem is something like this.
Note that EE 6 allows EJBs in web applications for the first time and uses stateless EJBs for JAX-WS services.
You would not have seen this issue in NB 6.5 because NB 6.5 did not support EE 6.
If you generated an EE 5 web service in NB 6.8, you would not see this issue, either. You also would not see @Stateless or @EJB annotations in your web service class.
I hope this helps. Keep in mind that the version of Java EE used in a web app is very important, and useful information is often conveyed in error statements.

Jeff

zkidron wrote:
Quote:
Quote:
So, Today I learned that NB 6.5 and 6.8 DO coexist as long as they each manage separate projects. NOT same projects. Which is logical and obvious (different conf files) except my combined JAVA+NB+Glassfish experience is all of 3 weeks...

But still I have the problem that NB6.8 will not generate my WSDL.

errors given are: "Could not create declaration for annotation type javax.ejb.Stateless" AND "Could not create declaration for annotation type javax.ejb.EJB"

From what I've read this problem stems from overloaded methods, which is not my case. I have only 1 method.

This exact same code worked fine with NB6.5.1 and GF2.1

Anyone can help on this?

Below my WS:



package Login;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
*
* @author xxxx
*/
@WebService
@Stateless
public class LoginWS {
@EJB
private LoginRemote ejbRef;// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Web Service Operation")

@WebMethod(operationName = "Validar")
public String Validar(@WebParam(name = "un")
String un, @WebParam(name = "pw")
String pw) {
return ejbRef.Validar(un, pw);
}

}



And my class:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package Login;

//import javax.annotation.Resource;
import javax.ejb.*;
import javax.persistence.*;
//import javax.sql.DataSource;

/**
*
* @author xxxx
*/
@Stateless
public class Login implements LoginRemote {

public Login() {
}

@PersistenceContext
EntityManager em;

public String Validar(String un, String pw) {

String u = finduser(un, pw);

if ( u.equals("")) {
System.err.println("Usuario no existe: "+un);
return u;}


System.err.println("Parameter USUARIO recibido:"+un);
System.err.println("Parameter PASSWORD recibido:"+pw);
System.err.println("-----------------------------------------------------");
System.err.println("-----------------------------------------------------");

return "Usuario: "+u;

// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}

public String finduser(String username, String clave) {
try {
return (String) em.createQuery("SELECT u FROM Usuarios u WHERE u.usuario = :usuario and u.passw= :passw").setParameter("usuario", username).setParameter("passw",clave).getSingleResult().toString();
} catch (NoResultException e) {
return "";
}
}
}




Back to top
zkidron



Joined: 02 Mar 2010
Posts: 13

PostPosted: Thu Mar 04, 2010 8:46 pm    Post subject: Reply with quote

Hi Jeff,

First of all: Thanks! Your work around works. My WSDL file has been generated.

Abusing your kindness though:

1. First issue is that the JACC Policy Provider Permissions Check fails. Security issue which I'm reading about. Not related I know.

2. Second and larger issue is that I upgraded to NB6.8 because:

I'm writing a J2ME application which will need to consume WSs.

In 6.5 the WSDL was generated all right, but then in J2ME the Web Service Client did not generate the stubs, something to do with path containing spaces (My Documents was in the way...)

Now I get the WSDL file, thanks to your help, but still in J2ME I get a message that this file has no port information, even though I see it in the file, see below....

NOW: when I tried to go back and copy the WSDL file it is GONE, erased when I ran the EE app. the whole generated directory is gone...

So I'm back to square 1... Very Happy Shocked Evil or Very Mad
Back to top
zkidron



Joined: 02 Mar 2010
Posts: 13

PostPosted: Thu Mar 04, 2010 9:06 pm    Post subject: Reply with quote

OK, I did it all over again and generated the WSDL and SCHEMA seen below. Any one can explain why I can't create client for this web service in J2ME, based on this WSDL file?

In the "wizard" window I get this message: "WSDL file does not contain port information"




<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-752-. -->
<definitions targetNamespace="http://Login/" name="LoginWSService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:tns="http://Login/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<types>
<xsd:schema>
<xsd:import namespace="http://Login/" schemaLocation="LoginWSService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="Validar">
<part name="parameters" element="tns:Validar"/>
</message>
<message name="ValidarResponse">
<part name="parameters" element="tns:ValidarResponse"/>
</message>
<portType name="LoginWS">
<operation name="Validar">
<input wsam:Action="http://Login/LoginWS/ValidarRequest" message="tns:Validar"/>
<output wsam:Action="http://Login/LoginWS/ValidarResponse" message="tns:ValidarResponse"/>
</operation>
</portType>
<binding name="LoginWSPortBinding" type="tns:LoginWS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="Validar">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="LoginWSService">
<port name="LoginWSPort" binding="tns:LoginWSPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>





<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://Login/" xmlns:tns="http://Login/" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Validar" type="tns:Validar"/>

<xs:element name="ValidarResponse" type="tns:ValidarResponse"/>

<xs:complexType name="Validar">
<xs:sequence>
<xs:element name="un" type="xs:string" minOccurs="0"/>
<xs:element name="pw" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ValidarResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Back to top
zkidron



Joined: 02 Mar 2010
Posts: 13

PostPosted: Fri Mar 05, 2010 7:19 pm    Post subject: FINALLY.....SUCCESS !!! Thanks Jeff Reply with quote

My Web Service WORKS !!!

Never been so happy before.... Cool Laughing

What I did was:

1. Return to NB6.5+GF2.1. For some reason or other I couldn't get it to work on NB6.8 + GF3.

IMPORTANT: When starting your project choose to store it in a folder (directory) whose path does NOT include spaces !!!! in my case G:\JAVAPROJECTS\. Otherwise you MAY have problems generating the stub classes.

2. Generate WSDL file from web service coded in EJB.

3. IMPORTANT: and not always obvious to us newbies: at the very end of the WSDL file you'll find this: "<soap:address location="REPLACE_WITH_ACTUAL_URL"/>". GO AHEAD AND ACTUALLY REPLACE this: "REPLACE_WITH_ACTUAL_URL" with my actual server location, in my case "http://localhost:8080/LoginWSService/LoginWS". Leave quotes in place.

4. Generate the stubs through WTK, as in this excellent advice: http://stackoverflow.com/questions/451479/returning-arrays-from-net-web-service-to-java-me-web-service-results-in-compile

5. Modify the stub class to include your WSDL file location as endPoint, in my case:
_propertyValues = new Object[] {"http://localhost:8080/LoginWSService/LoginWS?WSDL"};

6. Use the (modified) stub class methods generated in my application, as follows:

LoginWS_Stub LoginStub = new LoginWS_Stub(); //Instantiate WS
LoginStub._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE); //Set properties of WS

try {
String val = LoginStub.validar(name,password); //use WS and get result in "val"
// Here use "val" to do what you need

} catch (RemoteException e) {
// Here handle exception



IF it's of use to someone I'll be happy, I could not have done this if not for the information others have shared, especially Jeff Rubinoff from this forum.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo