Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Services and the fly likes Jax-WS restful web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Web Services
Bookmark "Jax-WS restful web service" Watch "Jax-WS restful web service" New topic
Author

Jax-WS restful web service

Eswar Varanasi
Greenhorn

Joined: Jun 03, 2007
Posts: 20
Dear members,

I'm new to web services development and wanted them to run in below environment.
1) jdk1.6.0_20
2) Jboss5.1.0_GA
3) JAX-WS (not using any other impl like jersey..etc)


I've tried to use JAX-WS and implement the restful web service for HTTP post method, having no WSDL or any other xml's.

1) Can you suggest me how to write the ant scripts for above project: say a dynamic web project
2) The HTTP GET method is not at all called even after i've provided required changes to the Provider service. (client calls using ajax get method, but no response). Any suggestion is greatly appreciated
3) I see unwanted deployment exceptions after deploying it. Stack trace is attached and JBoss expects wsdl for Restful Web service.!!!

The below is the provider service class i've used:

@WebServiceProvider
@BindingType(value = HTTPBinding.HTTP_BINDING)
@javax.xml.ws.ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE)
public class ValidateOrderWebService extends WebService implements Provider<Source> {
@Resource(type = Object.class)
protected WebServiceContext mContext;
@WebMethod
public Source invoke(Source pSource) {
PropertyConfigurator.configure(ValidateOrderWebService.class
.getClassLoader().getResource(
WebServiceConstants.LOG4_MESSAGES_PROPERTY_FILE_LOC));
logger.info(getProperties(WebServiceConstants.ENTERED_VALIDATE_ORDER));
JAXBSource reply = null;
try {
/**
* This is to identify the type of the request - GET - POST
*/
MessageContext mc = mContext.getMessageContext();
String method = (String) mc.get(MessageContext.HTTP_REQUEST_METHOD);
if ("GET".equals(method)) {
reply = getResponseSource();
}
if ("POST".equals(method) || "PUT".equals(method)) {
reply = getResponseSource();
logger.info(getProperties(WebServiceConstants.REQUEST_TYPE) + "");
}
} catch (JAXBException e) {
logger.error(getProperties(WebServiceConstants.ERROR_IN_VALIDATE)
+ e.getMessage());
} catch (WebServiceException e) {
logger.error(getProperties(WebServiceConstants.ERROR_IN_VALIDATE)
+ e.getMessage());
try {
reply = getResponseSource();
} catch (JAXBException e1) {
logger.error(getProperties(WebServiceConstants.ERROR_IN_VALIDATE)
+ e1.getMessage());
}
}
return reply;
}
}

-----------------web.xml---------------------entry for the above service------------------------
<servlet>
<servlet-name>ValidateOrder</servlet-name>
<servlet-class>
com.integration.ValidateOrderWebService</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ValidateOrder</servlet-name>
<url-pattern>/ValidateOrder</url-pattern>
</servlet-mapping>
-------------------------------------------

4) what is JBOSSWs used for any relevance when using JBOSS 5.1.0_GA.
(I need some sample ant build scripts to build jax-ws restful web service as the jwsc tag used only for weblogic and no sure for jboss)


Error Log:

12:22:58,352 ERROR [AbstractKernelController] Error installing to Real: name=vfsfile:/C:/DYS/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server/deploy/.war/ state=PreReal mode=Manual requiredState=Real
org.jboss.deployers.spi.DeploymentException: Error during deploy: vfsfile:/C:/DYS/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server/deploy/.war/
at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:177)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalStateException: Cannot obtain wsdl location for: {http://.integration..com/}ValidateOrderWebServiceService
at org.jboss.wsf.stack.jbws.WSDLFilePublisher.getPublishLocation(WSDLFilePublisher.java:327)
at org.jboss.wsf.stack.jbws.WSDLFilePublisher.publishWsdlFiles(WSDLFilePublisher.java:103)
at org.jboss.wsf.stack.jbws.PublishContractDeploymentAspect.start(PublishContractDeploymentAspect.java:50)
at org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl.deploy(DeploymentAspectManagerImpl.java:129)
at org.jboss.wsf.container.jboss50.deployer.ArchiveDeployerHook.deploy(ArchiveDeployerHook.java:76)
at org.jboss.wsf.container.jboss50.deployer.AbstractWebServiceDeployer.internalDeploy(AbstractWebServiceDeployer.java:60)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
... 24 more
12:22:58,352 WARN [HDScanner] Failed to process changes
org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
*** DEPLOYMENTS IN ERROR: Name -> Error
vfsfile:/C:/DYS/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server/deploy/.war/ -> org.jboss.deployers.spi.DeploymentException: Error during deploy: vfsfile:/C:/DYS/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server/deploy/.war/
DEPLOYMENTS IN ERROR:
Deployment "vfsfile:/C:/DYS/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server/deploy/.war/" is in error due to the following reason(s): java.lang.IllegalStateException: Cannot obtain wsdl location for: {http://.integration..com/}ValidateOrderWebServiceService
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:993)
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:939)
at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:873)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.checkComplete(MainDeployerAdapter.java:128)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:369)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)


Thanks,
eswar
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If you haven't seen it already, take a look at section 9.4 of my (free) electronic book: http://www.slideshare.net/krizsan/scdjws-5-study-notes-3085287
There you can see how to develop an XML web service that does not use SOAP with JAX-WS an also how to develop the corresponding client.
With minor modifications, you will be able to turn that into a RESTful web service with client.
Let me know if you need any clarifications of the information in the book!
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Eswar Varanasi
Greenhorn

Joined: Jun 03, 2007
Posts: 20
thanks for your reply. I see your book it has most of the WS details and wanted some info, as raised on the first message.

Please let me know if those specific questions can be answered.
Eswar Varanasi
Greenhorn

Joined: Jun 03, 2007
Posts: 20
Its resolved thanks
rambabu somu
Greenhorn

Joined: Apr 12, 2012
Posts: 1
Eswar Varanasi wrote:Its resolved thanks


I am also facing same issue in JBoss 4.2.0.GA. Please let me know how you fixed issue.


Please take a look at my provider endpoint and error message.

//Provider Endpoint implementation class.

package com.tomax.pojo.ws;

import java.io.FileNotFoundException;
import java.io.InputStream;

import javax.annotation.Resource;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.BindingType;
import javax.xml.ws.Provider;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.http.HTTPBinding;
import javax.xml.ws.http.HTTPException;

@WebServiceProvider
@BindingType(value=HTTPBinding.HTTP_BINDING)
public class RESTHelloProvider implements Provider<Source>{
@Resource
protected WebServiceContext wsContext;

public Source invoke(Source arg0) {
//MessageContext.QUERY_STRING
//MessageContext.PATH_INFO
Transformer transformer;
InputStream src;
try {
/******In bound Message Begin****************/
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(arg0,new StreamResult(System.out));
/******In bound Message End****************/

/******Out bound Message sending****************/
src = getClass().getResourceAsStream("/orders.xml");
if ( src == null ) {
throw new FileNotFoundException("/orders.xml");

}
/******Out bound Message sent****************/
} catch (Exception e) {
e.printStackTrace();
throw new HTTPException(500);

}
return new StreamSource(src);
}
}



//web.xml entry for service

<servlet>
<description>RESTHelloProvider</description>
<display-name>REST HelloP rovider</display-name>
<servlet-name>RESTHelloProvider</servlet-name>
<servlet-class>com.tomax.pojo.ws.RESTHelloProvider</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>RESTHelloProvider</servlet-name>
<url-pattern>/rest</url-pattern>
</servlet-mapping>





Error message while deploying web service........................



13:10:54,866 ERROR [ServiceEndpointDeployer] Cannot start service endpoint
java.lang.IllegalStateException: Cannot obtain wsdl location for: {http://ws.pojo.tomax.com/}RESTHelloProviderService
at org.jboss.ws.core.server.WSDLFilePublisher.getPublishLocation(WSDLFilePublisher.java:275)
at org.jboss.ws.core.server.WSDLFilePublisher.publishWsdlFiles(WSDLFilePublisher.java:89)
at org.jboss.ws.core.server.ServiceEndpointDeployer.start(ServiceEndpointDeployer.java:134)
at org.jboss.ws.integration.jboss42.DeployerInterceptor.startServiceEndpoint(DeployerInterceptor.java:144)
at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:96)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy46.start(Unknown Source)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy9.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
13:10:54,928 ERROR [MainDeployer] Could not start deployment: file:/D:/ramwork/AppServer/jboss/4.2.0.GA/server/default/tmp/deploy/tmp12488ejb3-2.1.0.ear-contents/practice.war
org.jboss.deployment.DeploymentException: Cannot start service endpoint; - nested throwable: (java.lang.IllegalStateException: Cannot obtain wsdl location for: {http://ws.pojo.tomax.com/}RES
THelloProviderService)
at org.jboss.deployment.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:53)
at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:101)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy46.start(Unknown Source)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy9.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
Caused by: java.lang.IllegalStateException: Cannot obtain wsdl location for: {http://ws.pojo.tomax.com/}RESTHelloProviderService
at org.jboss.ws.core.server.WSDLFilePublisher.getPublishLocation(WSDLFilePublisher.java:275)
at org.jboss.ws.core.server.WSDLFilePublisher.publishWsdlFiles(WSDLFilePublisher.java:89)
at org.jboss.ws.core.server.ServiceEndpointDeployer.start(ServiceEndpointDeployer.java:134)
at org.jboss.ws.integration.jboss42.DeployerInterceptor.startServiceEndpoint(DeployerInterceptor.java:144)
at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:96)
... 29 more



Advance thanks for helping me.

Thanks,
Rambabu Somu
 
GeeCON Prague 2014
 
subject: Jax-WS restful web service