NetBeans 5.5/Tomcat and WebServices

I am between a project that uses JSP and Servlet technologies in it. These are the project environment that i used up to now for this purpose.

IDE: NetBeans 5.5

Application Server : apache-tomcat-5.5.17

Now i need to Add a web service to my project. but once i tried to do that i am getting a Error from the Netbeans that says;

To create a web service in this project, java source level must be at least JDK 1.5

Once i start a new web project with SJSAS 9 I can set the source level to j2EE 5.

And i can create the web service.

My Question is i couldn't rollback my project back to Sun java system application server 9. is there any way to create a web service with TomCat by upgrading the App server or JDK source level.

[793 byte] By [Ajaxranda] at [2007-11-27 5:20:03]
# 1

According to the message you stated below, you need to specify the JDK 1.5 source leve., not J2ee 5. To set the JDK source level, select your project under that project tab in NBs. Right click on it and select "properties". Under Category "Sources" should be highlighted, at the bottom right change "Source Level" from 1.4 to 1.5.

dkohlerta at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

> According to the message you stated below, you need

> to specify the JDK 1.5 source leve., not J2ee 5. To

> set the JDK source level, select your project under

> that project tab in NBs. Right click on it and

> select "properties". Under Category "Sources" should

> be highlighted, at the bottom right change "Source

> Level" from 1.4 to 1.5.

Thanks a lot. I think its my mistake its not J2EE 5, it should be JDK 1.5.

and i made the changes to current web project and i added the web service.

But didn't execute the web service. Thanks again, I'll give it a try.

Ajaxranda at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Hi I changed the source level to 1.5.

now the error is not getting and i tried to continue with this

http://qa.netbeans.org/modules/j2ee/promo-g/end2end/hello_ws.html

I made this web services. as per the sample.

with no errors.

package org.netbeans.end2end.hellosample;

import javax.jws.HandlerChain;

import javax.jws.WebMethod;

import javax.jws.WebService;

import javax.jws.WebParam;

@WebService(serviceName="GreeterWs")

@HandlerChain(name = "HelloWebService_handlerChain", file = "HelloWebService_handler.xml")

public class HelloWebService

{

/**

* Web service operation

*/

@WebMethod(operationName="sayHi")

public String operation(@WebParam(name="name")String param)

{

// TODO implement operation

return "Hi"+ param;

}

@WebMethod()

public String sayHello(String s)

{

// TODO implement operation

return "Hello"+ s;

}

}

but here there is error.

package org.netbeans.end2end.hellosample;

import java.util.Collections;

import java.util.Set;

import javax.xml.namespace.QName;

import javax.xml.soap.SOAPMessage;

import javax.xml.ws.handler.MessageContext;

import javax.xml.ws.handler.soap.SOAPHandler;

import javax.xml.ws.handler.soap.SOAPMessageContext;

public class MessageHandler implements SOAPHandler<SOAPMessageContext>

{

public boolean handleMessage(SOAPMessageContext messageContext)

{

//SOAPMessage msg = messageContext.getMessage();

log(messageContext);

return true;

}

private void log(SOAPMessageContext messageContext)

{

Boolean outcoming = (Boolean)

messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

if(outcoming.booleanValue())

{

System.out.println("\nOutcoming Message:");

}else

{

System.out.println("\nIncoming Message:");

}

SOAPMessage message= messageContext.getMessage();

try{

message.writeTo(System.out);

System.out.println("\n");

}catch(Exception e)

{

System.out.println("Exception "+e);

}

}

}

The Error is :

C:\Sun\SDK\samples\javaee5\webservices\HelloWs\src\java\org\netbeans\end2end\hellosample\MessageHandler.java:12: org.netbeans.end2end.hellosample.MessageHandler is not abstract and does not override abstract method getHeaders() in javax.xml.ws.handler.soap.SOAPHandler

public class MessageHandler implements SOAPHandler<SOAPMessageContext>

Ajaxranda at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Looks like the sample handler is missing an implementation for the following method.

java.util.Set<javax.xml.namespace.QName> getHeaders()

Gets the header blocks that can be processed by this Handler instance.

Returns:

Set of QNames of header blocks processed by this handler instance. QName is the qualified name of the outermost element of the Header block.

Try adding

public Set<QName> getHeaders() { return new HashSet<QName>(); }

dkohlerta at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
How did you create the handler? Using the wizard (New File -> Web Services -> Message Handler) or by hand?
jungiCza at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
Netbeans provides a wizard for creating Message Handler template code. From the project node, select New/File/Folder/Webservices/MessageHander.
rico_cruza at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

I created the MessageHandler using the wizard.

and add the coding to as looks like in tutorial.

http://qa.netbeans.org/modules/j2ee/promo-g/end2end/hello_ws.html#creatingHandler

package org.netbeans.end2end.hellosample;

import java.util.Collections;

import java.util.Set;

import javax.xml.namespace.QName;

import javax.xml.soap.SOAPMessage;

import javax.xml.ws.handler.MessageContext;

import javax.xml.ws.handler.soap.SOAPHandler;

import javax.xml.ws.handler.soap.SOAPMessageContext;

public class MessageHandler implements SOAPHandler<SOAPMessageContext>

{

public boolean handleMessage(SOAPMessageContext messageContext)

{

//SOAPMessage msg = messageContext.getMessage();

log(messageContext);

return true;

}

private void log(SOAPMessageContext messageContext)

{

Boolean outcoming = (Boolean)

messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

if(outcoming.booleanValue())

{

System.out.println("\nOutcoming Message:");

}else

{

System.out.println("\nIncoming Message:");

}

SOAPMessage message= messageContext.getMessage();

try{

message.writeTo(System.out);

System.out.println("\n");

}catch(Exception e)

{

System.out.println("Exception "+e);

}

}

}

So what might be the reson for this error.

Ajaxranda at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
> Try adding > public Set<QName> getHeaders() { return new> HashSet<QName>(); }To where i should add these.and what is QName here?
Ajaxranda at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9

I think i made a mistake i removed some methods first time from the handler.

After creating the handler tried this way.

web services --> myweb service Name -->(right click)-->configure handler

but it does not add the xml file to the package.

package org.netbeans.end2end.hellosample;

import java.util.Collections;

import java.util.Set;

import javax.xml.namespace.QName;

import javax.xml.soap.SOAPMessage;

import javax.xml.ws.handler.MessageContext;

import javax.xml.ws.handler.soap.SOAPHandler;

import javax.xml.ws.handler.soap.SOAPMessageContext;

public class MessageHandler implements SOAPHandler<SOAPMessageContext>

{

public boolean handleMessage(SOAPMessageContext messageContext)

{

//SOAPMessage msg = messageContext.getMessage();

log(messageContext);

return true;

}

private void log(SOAPMessageContext messageContext)

{

Boolean outcoming = (Boolean)

messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

if(outcoming.booleanValue())

{

System.out.println("\nOutcoming Message:");

}else

{

System.out.println("\nIncoming Message:");

}

SOAPMessage message= messageContext.getMessage();

try{

message.writeTo(System.out);

System.out.println("\n");

}catch(Exception e)

{

System.out.println("Exception "+e);

}

}

public Set<QName> getHeaders()

{

return Collections.EMPTY_SET;

}

public boolean handleFault(SOAPMessageContext messageContext)

{

return true;

}

public void close(MessageContext context)

{

}

}

Ajaxranda at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10

I re-created my web service.

Now there is a new error.

init:

deps-module-jar:

deps-ear-jar:

deps-jar:

Created dir: D:\NetBeans\WS\HelloWs\build\web\WEB-INF\classes

Created dir: D:\NetBeans\WS\HelloWs\build\web\META-INF

Copying 1 file to D:\NetBeans\WS\HelloWs\build\web\META-INF

Copying 3 files to D:\NetBeans\WS\HelloWs\build\web

library-inclusion-in-archive:

library-inclusion-in-manifest:

Compiling 2 source files to D:\NetBeans\WS\HelloWs\build\web\WEB-INF\classes

Note: D:\NetBeans\WS\HelloWs\src\java\org\netbeans\end2end\hellosample\MessageHandler.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

Copying 1 file to D:\NetBeans\WS\HelloWs\build\web\WEB-INF\classes

compile:

compile-jsps:

Created dir: D:\NetBeans\WS\HelloWs\dist

Building jar: D:\NetBeans\WS\HelloWs\dist\HelloWs.war

do-dist:

dist:

In-place deployment at D:\NetBeans\WS\HelloWs\build\web

Start registering the project's server resources

Finished registering server resources

moduleID=HelloWs

deployment started : 0%

Deploying application in domain failed; com.sun.tools.apt.Main.process(Lcom/sun/mirror/apt/AnnotationProcessorFactory;[Ljava/lang/String;)I

D:\NetBeans\WS\HelloWs\nbproject\build-impl.xml:453: Deployment error:

The module has not been deployed.

See the server log for details.

BUILD FAILED (total time: 6 seconds)

Ajaxranda at 2007-7-12 11:43:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...