I would like to implement a web service that reads two files one in xml and other in xslt and do the transformation then output a third transformed file How can I do that ? My problem is how to pass files and output it?
What is the method required to pass an xml file and xslt then the output willl be xhtml using Eclipse platform my code is as follows but it is not working
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35220
7
posted
0
it is not working
What does this mean? Are there any error messages? if so, post the stack traces.
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
I am getting the following error:
HTTP Status 404 - /XSLTTransform/WEB-INF/classes/chap5/XSLTTransform.java
feda alshahwan wrote:I mean by URI or give me any other way for passing files written in XML to web service
A URI isn't useful unless the service can retrieve the files itself - which in many cases it can't unless special arrangements have been made (e.g. file is stored on an anonymously accessible FTP site). So sending the files to the web service is the usual solution.
I would like to implement a web service that reads two files one in xml and other in xslt and do the transformation then output a third transformed file How can I do that ? My problem is how to pass files and output it?
The web service "reading" the files isn't practical - you are going to have to pass them to it - that is provide the content of the files in the web service request. Both the data XML and the XSLT file are pure XML - the output of an XSLT transformation could be anything text based. Now when transferring the content of arbitrary types of files usually some kind of attachment technology is involved as Ulf has already mentioned. Another more recent but not that widely supported standard is MTOM (JAX-WS: Binary Attachments (MTOM)) - however no standard is universally supported, so sometimes it makes sense to do the encoding/decoding yourself (Send binary data without using attachments).
However in your case the complexity of attachments isn't necessary as the both inputs are XML and the output is plain text. Plain SOAP can handle XML and plain text.
What is the method required to pass an xml file and xslt then the output will be xhtml
This means that we can constrain the solution even further because the output is also XML.
A "simple" example of a JAX-WS (as included in the plain JDK 1.6) service that can handle that is shown below:
(This service will not work if the XSLT transform doesn't produce well-formed XML)
The one thing that is peculiar about the WebMethod is that it accepts java.lang.Object parameters. A web method cannot accept org.w3c.dom.Document objects because the RequestWrapper is always one single XML document. So multiple "XML Documents" can only be wrapped into a single XML Document by transferring each document's "document root org.w3c.dom.Element" into the wrapping document. JAX-WS strips off the transformRequestRequestWrapper and simply hands you the org.w3c.dom.Element objects that correspond to your method parameters. Now JAXB can't handle org.w3c.dom.Element because it can only marshal and unmarshal classes, not interfaces. However if you hand it the org.w3c.dom.Element objects as java.lang.Object objects it "goes that the extra mile" and figures out that it can simply use the raw XML. You still need a class to do the DOM related grunt work.
Something still has to run the web service
Now you have enough for your web service. Compile it:
javac -d . DomUtil.java
javac -d . Xslt2XmlImpl.java
javac -d . Main.java
wsgen -cp . -s src com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
Run it:
java com.coderanch.jaxws.passxml.provider.Main
You should now be able to access the following URIs with your browser:
http://localhost:8080/wsdemo/xslt2xml?wsdl http://localhost:8080/wsdemo/xslt2xml?xsd=1 http://localhost:8080/wsdemo/xslt2xml?xsd=2
There is a feature in the schema that deserves some attention. For example:
<xs:element name="data" type="xs:anyType" minOccurs="0"/>
{http://www.w3.org/2001/XMLSchema}anyType allows any well-formed XML fragment at that point in the XML document. In this particular case "data" is the XML fragment that holds the XML data for your transformation. However the root element that you hand JAX-WS will become the "data" element in the transformRequestRequestWrapper. In this case we want to preserve the original element root so we have to wrap the original root in another element that can then become the "data" element in transformRequest. On the provider side we receive the "data" element which then has to be stripped off to expose the original root element. The same applies to the "style" element of the transformRequestRequestWrapper and the "output" element of the transformResponseResponseWrapper.
Now it's time to generate the consumer side artifacts (while the service is running):
wsimport -p com.coderanch.jaxws.passxml.consumer -s src http://localhost:8080/wsdemo/xslt2xml?wsdl
Once those are generated we can use them in the consumer:
Compile the client:
javac -d . Xslt2XmlSoapClient.java
And run it:
java -cp . com.coderanch.jaxws.passxml.consumer.Xslt2XmlSoapClient cdcatalog.xml cdcatalog.xsl
Thank you but when running the application I got the following
transform Method invocation
Method parameter(s)
Type Value
com.coderanch.jaxws.passxml.server.TransformRequest C:\Documents and Settings\PAAET
User\My Documents\NetBeansProjects\XSLT\xmlfilename C:\Documents and Settings\PAAET User\My Documents\NetBeansProjects\XSLT\xsltfilename.xml.xsl
Service invocation threw an exception with message : null; Refer to the server log for more details
Exceptions details : java.lang.reflect.InvocationTargetException javax.servlet.ServletException: java.lang.reflect.InvocationTargetException at com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:345) at com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:121) at com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:148) at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214) at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:316) ... 36 more Caused by: javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:187) at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116) at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:254) at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:224) at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:117) at $Proxy96.transform(Unknown Source) ... 41 more Caused by: javax.xml.ws.WebServiceException: java.lang.NullPointerException at com.sun.enterprise.security.jmac.config.PipeHelper.makeFaultResponse(PipeHelper.java:328) at com.sun.enterprise.security.jmac.config.PipeHelper.getFaultResponse(PipeHelper.java:366) at com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:223) at com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:129) at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115) at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595) at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554) at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539) at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436) at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243) at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444) at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244) at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135) at com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:159) ... 34 more Caused by: java.lang.NullPointerException at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36) at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18) at java.lang.reflect.Field.get(Field.java:358) at com.sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.get(Accessor.java:231) at com.sun.xml.bind.v2.runtime.reflect.Accessor.getUnadapted(Accessor.java:147) at com.sun.xml.bind.v2.runtime.JAXBContextImpl$6.get(JAXBContextImpl.java:917) at com.sun.xml.ws.server.sei.EndpointArgumentsBuilder$DocLit$PartBuilder.readRequest(EndpointArgumentsBuilder.java:548) at com.sun.xml.ws.server.sei.EndpointArgumentsBuilder$DocLit.readRequest(EndpointArgumentsBuilder.java:512) at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:243) at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93) at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595) at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554) at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539) at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436) at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106) at com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:147) at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115) at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595) at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554) at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539) at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436) at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106) at com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:218) ... 45 more
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
Dump the IDE - it is not helping you, it is setting up barriers against you.
Put the files into a single directory and work from the console command line ...
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
I am familiar with netbeans or eclipse but I have not much information about command line what are the required commands
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
feda alshahwan wrote:but I have not much information about command line what are the required commands
The "required commands" are given in between the source code listings.
I am familiar with netbeans or eclipse
Apparently not to the point that you can diagnose and correct any problems that the IDE environment or application server "magic" may introduce.
IDEs are great tools to automate tedious and mundane activities and tasks for developers who already know and understand the intricacies of the development and deployment process (and have a good knowledge of the IDEs configuration options). However all too often people take the attitude that "if the IDE can do it, I don't need to know how it works" which will ultimately get them into trouble because there will always be situations where the generic "IDE logic/scripting" isn't quite up to the task and will fail. When learning new technologies it's usually best to remove any variables that introduce technological complexities - and IDEs and application servers introduce technological complexities. Dropping down to the command line and command line tools gives you full control and it also forces you to understand what is going on.
The above example simply works with the com.sun.net.httpserver.HttpServer that ships with the 1.6 JDK - not even a servlet container. Once you get that working you may want to find out how to get JAX-WS working on a plain Tomcat installation
JAX-WS 2.0 Samples on Tomcat 5.5.x Running JAX-WS Samples with Tomcat 6.x preferably by setting it up manually. Then try to get the Xslt2Xml service running on Tomcat - again, preferably by setting it up manually.
After that you may want to contemplate trying it on an IDE (after you have convinced yourself that it can actually work with your previous experiments). Always start simply and introduce elements with complexities (even if this complexity occurs behind the scenes) gradually and in small increments.
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
When I am compiling Xslt2XMlImpl file I got The following errors ???
C:\Documents and Settings\Welcome\workspace\transform\src>javac "com\coderanch\j
axws\passxml\provider\Xslt2XmlImpl.java"
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:6: package javax.jws does
not exist
import javax.jws.WebMethod;
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:7: package javax.jws does
not exist
import javax.jws.WebService;
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:8: package javax.jws does
not exist
import javax.jws.WebParam;
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:9: package javax.jws does
not exist
import javax.jws.WebResult;
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:10: package javax.xml.ws
does not exist
import javax.xml.ws.RequestWrapper;
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:11: package javax.xml.ws
does not exist
import javax.xml.ws.ResponseWrapper;
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:12: package javax.xml.ws
does not exist
import javax.xml.ws.WebFault;
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:17: cannot find symbol
symbol: class WebService @WebService(name="Xslt2Xml", serviceName="Xslt2XmlService")
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:44: cannot find symbol
symbol : class WebParam location: class com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
@WebParam(name="data")
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:46: cannot find symbol
symbol : class WebParam location: class com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
@WebParam(name="style")
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:19: cannot find symbol
symbol : class WebFault location: class com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
@WebFault(
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:31: cannot find symbol
symbol : class RequestWrapper location: class com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
@RequestWrapper(
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:36: cannot find symbol
symbol : class ResponseWrapper location: class com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
@ResponseWrapper(
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:41: cannot find symbol
symbol : class WebResult location: class com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
@WebResult(name="output")
^
com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java:42: cannot find symbol
symbol : class WebMethod location: class com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
@WebMethod()
^
15 errors
C:\Documents and Settings\Welcome\workspace\transform\src>
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
Do you have JDK/JRE 1.6 installed? That is, try:
>java -version
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
Do you have the JAVA_HOME environment variable set? Example:
>set java_home
java_home=C:\opt\Java\jdk1.6.0_11
You seem to have "a" java version in your PATH environment variable. Example:
>set PATH
Path=C:\opt\Java\jdk1.6.0_11\bin;C:\opt\maven2\bin;C:\Windows\system32;... blah blah blah
Do you have your CLASSPATH environment variable set? Example:
>set CLASSPATH
CLASSPATH=.;C:\opt\log\lib\log4j-1.2.15.jar;C:\opt\log\lib\slf4j-api-1.5.6.jar;C:\opt\log\lib\slf4j-log4j12-1.5.6.jar
(the C:\opt\log\lib\ jar archives aren't necessary but serve as examples of additional, non-JDK libraries)
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Welcome>java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
C:\Documents and Settings\Welcome>set java_home
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_16\bin
C:\Documents and Settings\Welcome>set path
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\My
SQL\MySQL Server 5.0\bin;c:\program files\java\jdk1.5.0_16\bin;.
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
C:\Documents and Settings\Welcome>set classpath
CLASSPATH=.;
This is because I am using Eclipse I didnot set the Dos for web services How can I do that?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35220
7
posted
0
So you have two JREs installed, one for Java 5 and one for Java 6. You need to use Java 6 for the javax.jws.* classes.
I'd start by changing the JAVA_HOME and PATH variables to use the Java 6 installation.
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
What is the syntax of wsgen if the class files are in C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\provider and DomUtil is in C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
feda alshahwan wrote:What is the syntax of wsgen if the class files are in C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\provider and DomUtil is in C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml
What are the class files doing under the src directory? Do you mean source files?
create C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\DomUtil.java
create C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java
create C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\provider\Main.java
Now on the command line start by changing to the correct directory:
cd "C:\Documents and Settings\Welcome\workspace\transform"
javac -d . src\com\coderanch\jaxws\passxml\DomUtil.java
javac -d . src\com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.java
javac -d . src\com\coderanch\jaxws\passxml\provider\Main.java
wsgen -cp . -s src com.coderanch.jaxws.passxml.provider.Xslt2XmlImpl
javac will create the following class files:
C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\DomUtil.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\DomUtil$DomUtilException.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl$Xslt2XmlException.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\provider\Xslt2XmlImpl$Xslt2XmlServiceFault.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\provider\Main.class
wsgen will create the following source files
C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\provider\TransformRequest.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\provider\TransformResponse.java and wsgen will create the following class files
C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\provider\TransformRequest.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\provider\TransformResponse.class
Now you should be able to run the service:
cd "C:\Documents and Settings\Welcome\workspace\transform"
java com.coderanch.jaxws.passxml.provider.Main
Once the service is running (and you successfully accessed its WSDL and XSDs) run
cd "C:\Documents and Settings\Welcome\workspace\transform"
wsimport -p com.coderanch.jaxws.passxml.consumer -s src http://localhost:8080/wsdemo/xslt2xml?wsdl
wsimport will create the following source files
C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\TransformRequest.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\TransformResponse.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\ObjectFactory.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\package-info.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\Xslt2Xml.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\Xslt2XmlService.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\Xslt2XmlServiceFault.java C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\Xslt2XmlServiceFault_Exception.java and wsimport will create the following class files
C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\TransformRequest.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\TransformResponse.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\ObjectFactory.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\package-info.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Xslt2Xml.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Xslt2XmlService.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Xslt2XmlServiceFault.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Xslt2XmlServiceFault_Exception.class
create C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\Xslt2XmlSoapClient.java
Compile the consumer:
cd "C:\Documents and Settings\Welcome\workspace\transform"
javac -d . src\com\coderanch\jaxws\passxml\consumer\Xslt2XmlSoapClient.java
javac will create the following class files:
C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Client.class C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Xslt2XmlSoapClient..class
Now run the consumer with files that are stored under "C:\Documents and Settings\Welcome\workspace\transform" cd "C:\Documents and Settings\Welcome\workspace\transform"
java -cp . com.coderanch.jaxws.passxml.consumer.Xslt2XmlSoapClient cdcatalog.xml cdcatalog.xsl
Both files cdcatalog.xml and cdcatalog.xsl came from here
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
I followed up the perfecto detailed steps but I got stuck when trying to run main the cursor was blinking and nothing came out on the screen
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Welcome>cd C:\Documents and Settings\Welcome\workspace
\transform
C:\Documents and Settings\Welcome\workspace\transform>javac -d . src\com\coderan
ch\jaxws\passxml\DomUtil.java
C:\Documents and Settings\Welcome\workspace\transform>javac -d . src\com\coderan
ch\jaxws\passxml\provider\Xslt2XmlImpl.java
C:\Documents and Settings\Welcome\workspace\transform>javac -d . src\com\coderan
ch\jaxws\passxml\provider\mail.java
C:\Documents and Settings\Welcome\workspace\transform>wsgen -cp . -s src com.cod
eranch.jaxws.passxml.provider.Xslt2XmlImpl
C:\Documents and Settings\Welcome\workspace\transform>java com.coderanch.jaxws.p
assxml.provider.Main
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
feda alshahwan wrote:I followed up the perfecto detailed steps but I got stuck when trying to run main the cursor was blinking and nothing came out on the screen
That means its working i.e. the com.sun.net.httpserver.HttpServer is hosting your web service.
At this point you should be able to see the WSDL and XSD in a browser.
To proceed with the consumer you will have to open a second command line console window.
To eventually terminate the com.sun.net.httpserver.HttpServer in the first window use Ctrl-C and respond with 'Y'.
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
i cannot see the wsdl in a browser , Do I have to start tomcat before or it is automatically started like eclipse.
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
java com.coderanch.jaxws.passxml.provider.Main is running com.sun.net.httpserver.HttpServer so when you see
feda alshahwan wrote:the cursor was blinking and nothing came out on the screen
then try
http://localhost:8080/wsdemo/xslt2xml?wsdl in your browser.
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
You mentioned the following :
create C:\Documents and Settings\Welcome\workspace\transform\src\com\coderanch\jaxws\passxml\consumer\Xslt2XmlSoapClient.java
Compile the consumer:
cd "C:\Documents and Settings\Welcome\workspace\transform"
javac -d . src\com\coderanch\jaxws\passxml\consumer\Xslt2XmlSoapClient.java
javac will create the following class files:
C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Client.class
C:\Documents and Settings\Welcome\workspace\transform\com\coderanch\jaxws\passxml\consumer\Xslt2XmlSoapClient..class
Now run the consumer with files that are stored under "C:\Documents and Settings\Welcome\workspace\transform"
cd "C:\Documents and Settings\Welcome\workspace\transform"
java -cp . com.coderanch.jaxws.passxml.consumer.Xslt2XmlSoapClient cdcatalog.xml cdcatalog.xsl
But how do I create Xslt2XmlSoapClient.java
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
feda alshahwan wrote:But how do I create Xslt2XmlSoapClient.java
How did you create DomUtil.java?
The Xslt2XmlSoapClient.java code is the last code listing in this post.
feda alshahwan
Ranch Hand
Joined: Jul 26, 2008
Posts: 170
posted
0
I did all the steps but it has an error when executing it with other files such as the following
<!-- simply copy the message to the result tree -->
<xsl:template match="/">
<xsl:value-of select="message"/>
</xsl:template>
</xsl:stylesheet>
[/code]
[code for xml]
<?xml version="1.0" encoding="UTF-8"?>
<message>Yep, it worked!</message>
[/code]
C:\Documents and Settings\Welcome\workspace\transform>java -cp . com.coderanch.j
axws.passxml.consumer.Xslt2XmlSoapClient xmlFile.xml xsltFile.xsl
[Fatal Error] xsltFile.xsl:8:6: The processing instruction target matching "[xX]
[mM][lL]" is not allowed.
com.coderanch.jaxws.passxml.DomUtil$DomUtilException:
Error with file: xsltFile.xsl** Parsing error, line 8, uri file:/C:/Documents%20
and%20Settings/Welcome/workspace/transform/xsltFile.xsl
The processing instruction target matching "[xX][mM][lL]" is not allowed.
at com.coderanch.jaxws.passxml.DomUtil.readDocumentFile(DomUtil.java:66)
at com.coderanch.jaxws.passxml.consumer.Client.transform(Xslt2XmlSoapCli
ent.java:85)
at com.coderanch.jaxws.passxml.consumer.Xslt2XmlSoapClient.main(Xslt2Xml
SoapClient.java:32)
Caused by: org.xml.sax.SAXParseException: The processing instruction target matc
hing "[xX][mM][lL]" is not allowed.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown So
urce)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unk
nown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.coderanch.jaxws.passxml.DomUtil.readDocumentFile(DomUtil.java:59)
... 2 more
No result document.
C:\Documents and Settings\Welcome\workspace\transform>
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
That XSLT does'nt produce well formed XML - so the service fails as I remarked above. A more general version would return a String result not an XML Document.
The XSLT identity transform works:
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
[Fatal Error] xsltFile.xsl:8:6: The processing instruction target matching "[xX][mM][lL]" is not allowed.
Also, you are getting that error because you have whitespace in front of the <?xml version="1.0" encoding="ISO-8859-1"?> XML prolog.
Get rid of the whitespace - otherwise the XSLT and XML file isn't a well formed XML document.