Re: File access from a .war
Hi, Your post helped me - but in unexpected ways. :D I just added this line: private static final String PATH = "c:/primes.txt"; and used PATH instead getResourceAsStream() to my existing code and it worked. I guess it was a Java PATH issue. Thanks!On 7/12/06, Rodrigo Ruiz < [EMAIL PROTECTED]> wrote:Ok, I see some mistakes in the code. My comments inline... M S wrote:> Hi,>> Well this is my Web Service file:>>> import java.io.*;>> public class MyService2 {>> public String echo(String password) { I guess you will fix this signature later ;-D>> int ctr = 1;> FileInputStream fin;> try {> fin = (FileInputStream)> getClass().getClassLoader().getResourceAsStream(" prime.txt");ClassLoader.getResourceAsStream() searches within the classpath. Thismeans that the retrieved stream, if found, is read-only, and probablywithin your WEB-INF/classes, WEB-INF/lib, or the .aar archive itself. In any case, it will be read-only (it is an InputStream).The ServletContext has a method to obtain an absolute path from acontext relative path. With that path you can create FileReaders andFileWriters without problem. I know you can get an instance of this class from any service/module, but I don't know how.> BufferedReader br> = new BufferedReader(new InputStreamReader(fin));> ctr = Integer.parseInt(br.readLine());> fin.close();> } catch (Exception e) { System.out.println("prime.txt does> not exist. Creating prime.txt...");}>>> boolean primeReached = false;> while (!primeReached) { > ctr++;> if (isPrime(ctr) && ctr!=4) {> primeReached = true;> break;> }> }> PrintWriter fout;> try {> fout = new PrintWriter(new FileWriter("c:\\prime.txt"));The file you are writing is not the same you were reading before.> fout.println(String.valueOf(ctr));> fout.close ();> } catch (Exception e) {e.printStackTrace();}>>> return Integer.valueOf(ctr).toString();> }Looking at your code I see that using a file for storage is not (in general) a good idea. It will work if there is only one client. It willprobably fail very fast if you have several concurrent clients. So, ifyou know there will be only one client, ignore this comment ;-P try this modified version and tell me what happens:private static final String PATH = "c:/primes.txt";public int nextPrime() { int last = 1; BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(PATH));last = Integer.parseInt(reader.readLine()); } catch (Exception e) {e.printStackTrace(); } finally {close(reader); } do { last++; } while (!isPrime(last)); PrintWriter writer = null; try {writer = new PrintWriter(new FileWriter(PATH));writer.println(last); } catch (Exception e) {e.printStackTrace (); } finally {close(writer); } return last;}private void close(Object obj) { try {Method m = obj.getClass().getMethod("close", null);m.invoke(obj, null); } catch (Exception ignore) { }}It may have some typos. I am writing the code directly on my mailclient, and I have no plugins for Java spelling :-DWell, hope this helps youRodrigo Ruiz >> private boolean isPrime(int p) {> int i;> for(i=2;i<(p/2);i++) {> if ( i*(p/i) == p ) return(false);> }> return(true); > }>> }>> This is my services.xml:> > > > class="org.apache.axis2.rpc.receivers.RPCMessageReceiver "/>> > MyService2> >> This is my WSDL:> http://ws.apache.org/axis2">> -> > -> http:///xsd" > elementFormDefault="qualified" attributeFormDefault="qualified">> -> > -> > -> > > > > > -> > -> > -> > > > > > > > -> > > > -> > > > -> > -> > > > > > -> > name="MyService2SOAP11Binding">> > transport="http://schemas.xmlsoap.org/soap/http"/>> -> > > -> > > > -> > > > > > -> > name="MyService2SOAP12Binding">> > transport="http://schemas.xmlsoap.org/soap/http"/>> -> > > -> > > > -> > > > > > -> > name="MyService2HttpBinding"> > > -> > > -> > > > -> > > > &
Re: File access from a .war
ey may be not appropriate for enterprise> solutions, but for a single value they are more than enough. Moreover, > it is possible that you already use one for another service.>> - Use a distributed cache. Another overkill solution, but you may be> already using it for another service, or find out other places where it > may be useful ;-)>> These options, although more complex to implement, bring you an extra> feature. They make your service "distributable", that is, deployable on> a cluster of redundant servers. With local files, each node in the > cluster would have its own "counter".>> Hope this helps,> Rodrigo Ruiz>> Michael McIntosh wrote:>> Your problem seems very similar to mine - It would be great if someone >> would point us to the documentation for the rules related to file access>> (read/write, path, etc.)>>>> Thanks,>> Mike>>>> "M S" < [EMAIL PROTECTED]> wrote on 07/10/2006 10:40:47 AM:>>>>> Hi,>>>>>> I have a web service that is supposed to generate prime numbers. I>>> store the latest generated prime number in a file called prime.txt.>>> So for example, if the program is run and generated 3, 3 will be>>> stored in prime.txt and next time it will generate 5. If there is no>>> prime.txt, the program will generate 1 and try to create prime.txt.>>>>>> My problem is that my web service application does not seem to be>>> able to read/write a file. Any ideas on how this should be done?>>> Notice that the prime.txt must be able to saved for the duration of>>> the web service's lifetime.>>>>>> Regards>> - >> To unsubscribe, e-mail: [EMAIL PROTECTED]>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>>>>-GRIDSYSTEMSRodrigo Ruiz AguayoParc Bit - Son Espanyol07120 Palma de Mallorcamailto:[EMAIL PROTECTED]Baleares - España Tel:+34-971435085 Fax:+34-971435082http://www.gridsystems.com-No virus found in this outgoing message. Checked by AVG Free Edition.Version: 7.1.394 / Virus Database: 268.9.10/384 - Release Date: 10/07/2006-To unsubscribe, e-mail: [EMAIL PROTECTED]For additional commands, e-mail: [EMAIL PROTECTED]
Re: File access from a .war
Hi,Thank you for the exhaustive list of alternatives. I just have one small problem: I meant an .aar archive that is used for Axis2 web service deployments in the services directory (I incorrectly wrote .war in the subject of the original email). Do the same concepts apply (some of them, such as DBMS for example, obviously do, but I was hinting more towards the exploded archive option)? On 7/10/06, Rodrigo Ruiz <[EMAIL PROTECTED]> wrote: Depending on the servlet container you are using, war archives may beconsidered read-only. In this case you will not be able to write a filewithin the application context.Some alternatives you have are: - Deploy your application as an "exploded war" (the exact name will varyfrom container to container). When deploying in this mode, your classescan write files at any location within your context. - Use an absolute path for your file. The path may be configured throughJNDI, or System properties, or you might put it into a subfolder of theuser home (this is very common in *nix environments).Other options imply to use a different storage type: - Use the User Preferences API to store the value. This API is availablestarting from Java 1.4.- Store it into the JNDI tree. This only works if the JNDIimplementation is writeable and persistent. For example, AFAIK, it will not work in Tomcat- Use a DBMS. It may seem an overkill solution, but there are some verylightweight databases there. They may be not appropriate for enterprisesolutions, but for a single value they are more than enough. Moreover, it is possible that you already use one for another service.- Use a distributed cache. Another overkill solution, but you may bealready using it for another service, or find out other places where itmay be useful ;-) These options, although more complex to implement, bring you an extrafeature. They make your service "distributable", that is, deployable ona cluster of redundant servers. With local files, each node in the cluster would have its own "counter".Hope this helps,Rodrigo RuizMichael McIntosh wrote:> Your problem seems very similar to mine - It would be great if someone> would point us to the documentation for the rules related to file access > (read/write, path, etc.)>> Thanks,> Mike>> "M S" <[EMAIL PROTECTED]> wrote on 07/10/2006 10:40:47 AM:>>> Hi, >>>> I have a web service that is supposed to generate prime numbers. I>> store the latest generated prime number in a file called prime.txt.>> So for example, if the program is run and generated 3, 3 will be >> stored in prime.txt and next time it will generate 5. If there is no>> prime.txt, the program will generate 1 and try to create prime.txt.>>>> My problem is that my web service application does not seem to be >> able to read/write a file. Any ideas on how this should be done?>> Notice that the prime.txt must be able to saved for the duration of>> the web service's lifetime.>>>> Regards >> -> To unsubscribe, e-mail: [EMAIL PROTECTED]> For additional commands, e-mail: [EMAIL PROTECTED]>>>-GRIDSYSTEMSRodrigo Ruiz Aguayo Parc Bit - Son Espanyol07120 Palma de Mallorcamailto:[EMAIL PROTECTED]Baleares - España Tel:+34-971435085 Fax:+34-971435082 http://www.gridsystems.com-No virus found in this outgoing message.Checked by AVG Free Edition.Version: 7.1.394 / Virus Database: 268.9.10/383 - Release Date: 07/07/2006-To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
File access from a .war
Hi,I have a web service that is supposed to generate prime numbers. I store the latest generated prime number in a file called prime.txt. So for example, if the program is run and generated 3, 3 will be stored in prime.txt and next time it will generate 5. If there is no prime.txt, the program will generate 1 and try to create prime.txt. My problem is that my web service application does not seem to be able to read/write a file. Any ideas on how this should be done? Notice that the prime.txt must be able to saved for the duration of the web service's lifetime. Regards
Re: Axis2 / Axis RPC
Hi,Thank you very much for your help. That solved my problem! I hope that this is added to the next Axis2 RC. RegardsOn 7/9/06, Kinichiro Inoguchi <[EMAIL PROTECTED]> wrote:Hi, I sent you 1 jar file by another mail.I think you have 2 problems.One is "WSDL2Java code generation" issue,and another is "response message not qualified well" issue.WSDL2Java code generation issue seems still remain in nightly build 09-Jul-2006 01:35.I got these stack trace,---C:\work>set AXIS2_HOME=C:\work\axis2-std-SNAPSHOT-binC:\work>%AXIS2_HOME%\bin\wsdl2java -uri http://localhost:8080/axis2/services/MyService2?wsdl -p test -o stubException in thread "main"org.apache.axis2.wsdl.codegen.CodeGenerationException : java.lang.RuntimeException: java.lang.ClassNotFoundException:org.apache.axis2.schema.ExtensionUtilityatorg.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:235) at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:32)at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:21)Caused by: java.lang.RuntimeException:java.lang.ClassNotFoundException:org.apache.axis2.schema.ExtensionUtility atorg.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:52)atorg.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:188) ... 2 moreCaused by: java.lang.ClassNotFoundException:org.apache.axis2.schema.ExtensionUtilityat java.net.URLClassLoader$1.run(URLClassLoader.java:199)at java.security.AccessController.doPrivileged (Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:187)at java.lang.ClassLoader.loadClass(ClassLoader.java:289)atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java :274)at java.lang.ClassLoader.loadClass(ClassLoader.java:235)atjava.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(Class.java:141)atorg.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:44)... 3 moreC:\work>--- The jar file I sent (maybe) solves only response message issue.That does NOT solve WSDL2Java issue.If you want run through with your MyService2,how about using this coupling ?server side : nightly build war + jar I sent. code generation : std-1.0 release.This means,1. deploy nightly build war to your tomcat.2. replace jar with jar I sent in (tomcat)/webapps/axis2/WEB-INF/lib/ .3. drop your MyService2.aar to service folder. 4. set AXIS2_HOME to your std-1.0 release folder.5. generate client stub with WSDL2Java6. run the client.Regards,kinichiro--- M S <[EMAIL PROTECTED]> wrote: > Hi,>> I saw that you have added a solution to your JIRA... is it possible> for you> to give me a nightly build with the modifications you have?>> Regards>> On 7/6/06, Kinichiro Inoguchi < [EMAIL PROTECTED]> wrote:> >> > Hi,> >> > If you use Axis2 1.0 release version, it will work.> >> > RPCMessageReceiver of Nightly Builds have problem that returns > > "broken" qualified response.> > I created JIRA for this issue today.> >> > generated stub client send message like this,> > > > http:///xsd">> > from client app> > > > > > > > RPCMessageReceiver returns message like this,> > > > http:///xsd">> > from client app > > > > > >> > is NOT qualified with prefix "ns".> > your error message "Unexpected subelement return" of "return" means > > this.> >> > > claims> > > that this error message appears because axis2 does not support> RPC> > > Bindings.> >> > No, this means Axis2 does not support RPC/Encoded, > > As Anne mentioned before, RPC/literal is supported.> >> > Regards,> > kinichiro> >> > --- M S <[EMAIL PROTECTED]> wrote: > >> > > Hi,> > >> > > Basically what I'm trying to do is to create a simple Web Service> > > that will> > > receive a String and retun the same string, i.e. basically an> "echo"> > > web> > > service. I tried using the sample on the Axis2 documentation page> > > with> > > OMElement - it works fine.> > > > > > My problem is that I want to use String instead of OMElement on> both> > > sides> > > (server as well as client). Apparently, I cant do this un
Re: Axis2 / Axis RPC
Hi,I saw that you have added a solution to your JIRA... is it possible for you to give me a nightly build with the modifications you have?RegardsOn 7/6/06, Kinichiro Inoguchi <[EMAIL PROTECTED]> wrote: Hi,If you use Axis2 1.0 release version, it will work.RPCMessageReceiver of Nightly Builds have problem that returns"broken" qualified response.I created JIRA for this issue today. generated stub client send message like this, http:///xsd">from client app RPCMessageReceiver returns message like this, http:///xsd ">from client app is NOT qualified with prefix "ns".your error message "Unexpected subelement return" of "return" means this.> claims> that this error message appears because axis2 does not support RPC> Bindings.No, this means Axis2 does not support RPC/Encoded,As Anne mentioned before, RPC/literal is supported. Regards,kinichiro--- M S <[EMAIL PROTECTED]> wrote:> Hi,>> Basically what I'm trying to do is to create a simple Web Service> that will > receive a String and retun the same string, i.e. basically an "echo"> web> service. I tried using the sample on the Axis2 documentation page> with> OMElement - it works fine. >> My problem is that I want to use String instead of OMElement on both> sides> (server as well as client). Apparently, I cant do this unless I use> the RPC>> So what I have is a services.xml that looks like this:> - <#> > - <#> >> >> locked="*false*">MyService2> >> A MyService2.java that looks like this:>> public class MyService2 {> public String echo(String echostring) {> return echostring;> }>> }>> I can deploy this using axis2.war on JBoss. It deploys fine, and I> get the> following WSDL:>> http://schemas.xmlsoap.org/wsdl/" > xmlns:axis2="http://ws.apache.org/axis2" xmlns:mime="> http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http=" > http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http:///xsd"> xmlns:soap12=" http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="> http://org.apache.axis2/xsd"> xmlns:xs="http://www.w3.org/2001/XMLSchema "> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="> http://ws.apache.org/axis2 ">> xmlns:stn_3="http:///xsd"> targetNamespace="http:///xsd" elementFormDefault="qualified" > attributeFormDefault="qualified">> > > > > > > > > > > > > > > >> > name="part1"> />> element="ns0:echoResponse" name="part1"> />> name="MyService2PortType">> message="axis2:echoMessage" />> message="axis2:echoResponse" > />> type="axis2:MyService2PortType"> name="MyService2SOAP11Binding">> style="document" transport=" http://schemas.xmlsoap.org/soap/http"> />> soapAction="urn:echo" />> />> />> type="axis2:MyService2PortType" > name="MyService2SOAP12Binding">> transport="> http://schemas.xmlsoap.org/soap/http" />> name="echo">> />> />> />> type="axis2:MyService2PortType"> name="MyService2HttpBinding">> verb="POST" />> location="echo"> />> />> />> name="MyService2">> name="MyService2SOAP11port_http"> http://localhost:8080/axis2/services/MyService2"> />> binding="axis2:MyService2SOAP12Binding"> name="MyService2SOAP12port_http">http://localhost:8080/axis2/services/MyService2"> />> binding="axis2:MyService2HttpBinding" > name="MyService2Httpport0">http://localhost:8080/axis2/rest/MyService2"> /> > I then try to use WSDL2Java to create client stubs based on this> WSDL. It> does generate them, but when I try to run the client I get the> following> error:>>> Exception in thread "main" java.lang.RuntimeException:> java.lang.RuntimeException: Unexpected subelement return> at> org.apache.axis2.MyService2Stub.fromOM(MyService2Stub.java:665)> at> org.apache.axis2.MyService2Stub.echo (MyService2Stub.java:144)> at org.apache.axis2.Client.main(Client.java:16)> Caused by: java.lang.RuntimeException: Unexpected subelement return> at>org.apache.axis2.MyService2Stub$EchoResponse$Factory.parse (MyService2Stub.java:419)> at> org.apache.axis2.MyService2Stub.fromOM(MyService2Stub.java:657)> ... 2 more> I googled this and this page (> http://mail-archives.apache.org/mod_mbox/ws-axis-dev/200605.mbox/[EMAIL PROTECTED])> claims> that this error message appears because axis2 does not support RPC> Bindings. >> I'm confused - how do I generate a client for this WSDL?>__Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com-To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Axis2 / Axis RPC
Hi, I don't know what a JIRA is... but is there a way to get around this problem? I have been stuck with this problem for some time now and I tried everything possible I think this problem must be known, since the author of that page already pointed it out and it's been a while since Axis 2 1.0 was released. There has to be somebody out there with the same problem...On 7/7/06, Ajith Ranabahu <[EMAIL PROTECTED] > wrote:HmmSounds like a bug. Please file a Jira with your WSDL attached. AjithOn 7/7/06, M S <[EMAIL PROTECTED]> wrote:> Hi,>> Well the problem with using Axis2 1.0 is that it generates an erroneus> WSDL. I tried to reproduce the guide at > http://www.wso2.net/tutorials/axis2/java/2006/05/29/hello-world.> According to that page and according to my experience, it creates an > erroneus WSDL which in turn, leads to java stubs that do not contain inner> classes (the author of the above page also points out the fact that one> should use nightly builds). In anycase, I have tried using a nightly build > axis2.war (so that the WSDL is correct) and Axis2 1.0 WSDL2Java (so that the> stub generation is correct), but it doesnt work. Im out of ideas. Anyone?>> Regards>>> On 7/6/06, Kinichiro Inoguchi < [EMAIL PROTECTED]> wrote:> > Hi,> >> > If you use Axis2 1.0 release version, it will work.> >> > RPCMessageReceiver of Nightly Builds have problem that returns > > "broken" qualified response.> > I created JIRA for this issue today.> >> > generated stub client send message like this,> > > > http:///xsd">> > from client> app> > > > > >> > RPCMessageReceiver returns message like this,> > > > http:///xsd"> > > from client app> > > > > >> > is NOT qualified with prefix "ns". > > your error message "Unexpected subelement return" of "return" means> > this.> >> > > claims> > > that this error message appears because axis2 does not support RPC > > > Bindings.> >> > No, this means Axis2 does not support RPC/Encoded,> > As Anne mentioned before, RPC/literal is supported.> >> > Regards,> > kinichiro > >> > --- M S <[EMAIL PROTECTED]> wrote:> >> > > Hi,> > >> > > Basically what I'm trying to do is to create a simple Web Service > > > that will> > > receive a String and retun the same string, i.e. basically an "echo"> > > web> > > service. I tried using the sample on the Axis2 documentation page > > > with> > > OMElement - it works fine.> > >> > > My problem is that I want to use String instead of OMElement on both> > > sides> > > (server as well as client). Apparently, I cant do this unless I use > > > the RPC> > >> > > So what I have is a services.xml that looks like this:> > > - <#> > > > - <#> > > >> > > > > >> > > locked="*false*">MyService2> > > > > >> > > A MyService2.java that looks like this:> > >> > > public class MyService2 { > > > public String echo(String echostring) {> > > return echostring;> > > }> > >> > > }> > >> > > I can deploy this using axis2.war on JBoss. It deploys fine, and I> > > get the> > > following WSDL:> > >> > > > xmlns:wsdl=" http://schemas.xmlsoap.org/wsdl/"> > > xmlns:axis2="http://ws.apache.org/axis2" xmlns:mime="> > > http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="> > > http://schemas.xmlsoap.org/wsdl/http/"> xmlns:ns0=" http:///xsd"> > > xmlns:soap12=" http://schemas.xmlsoap.org/wsdl/soap12/"> xmlns:ns1="> > > http://org.apache.axis2/xsd"> > > xmlns:xs="http://www.w3.org/2001/XMLSchema "> > > xmlns:soap=" http://schemas.xmlsoap.org/wsdl/soap/"> targetNamespace="> > > http://ws.apache.org/axis2 ">> > > xmlns:stn_3=" http:///xsd"> > > targetNamespace="http:///xsd" elementFormDefault="qualified"> > > attributeFormDefault="qualified"> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > &g
Re: Axis2 / Axis RPC
Hi, Well the problem with using Axis2 1.0 is that it generates an erroneus WSDL. I tried to reproduce the guide at http://www.wso2.net/tutorials/axis2/java/2006/05/29/hello-world. According to that page and according to my experience, it creates an erroneus WSDL which in turn, leads to java stubs that do not contain inner classes (the author of the above page also points out the fact that one should use nightly builds). In anycase, I have tried using a nightly build axis2.war (so that the WSDL is correct) and Axis2 1.0 WSDL2Java (so that the stub generation is correct), but it doesnt work. Im out of ideas. Anyone? RegardsOn 7/6/06, Kinichiro Inoguchi <[EMAIL PROTECTED]> wrote: Hi,If you use Axis2 1.0 release version, it will work.RPCMessageReceiver of Nightly Builds have problem that returns"broken" qualified response.I created JIRA for this issue today. generated stub client send message like this, http:///xsd">from client app RPCMessageReceiver returns message like this, http:///xsd">from client app is NOT qualified with prefix "ns". your error message "Unexpected subelement return" of "return" meansthis.> claims> that this error message appears because axis2 does not support RPC> Bindings.No, this means Axis2 does not support RPC/Encoded, As Anne mentioned before, RPC/literal is supported.Regards,kinichiro--- M S <[EMAIL PROTECTED]> wrote:> Hi,>> Basically what I'm trying to do is to create a simple Web Service > that will> receive a String and retun the same string, i.e. basically an "echo"> web> service. I tried using the sample on the Axis2 documentation page> with> OMElement - it works fine. >> My problem is that I want to use String instead of OMElement on both> sides> (server as well as client). Apparently, I cant do this unless I use> the RPC>> So what I have is a services.xml that looks like this:> - <#> > - <#> >> >> locked="*false*">MyService2> >> A MyService2.java that looks like this:>> public class MyService2 {> public String echo(String echostring) {> return echostring;> }>> }>> I can deploy this using axis2.war on JBoss. It deploys fine, and I> get the> following WSDL:>> http://schemas.xmlsoap.org/wsdl/" > xmlns:axis2="http://ws.apache.org/axis2" xmlns:mime="> http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http=" > http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http:///xsd"> xmlns:soap12=" http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="> http://org.apache.axis2/xsd"> xmlns:xs="http://www.w3.org/2001/XMLSchema "> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="> http://ws.apache.org/axis2 ">> xmlns:stn_3="http:///xsd"> targetNamespace="http:///xsd" elementFormDefault="qualified" > attributeFormDefault="qualified">> > > > > > > > > > > > > > > >> > name="part1"> />> element="ns0:echoResponse" name="part1"> />> name="MyService2PortType">> message="axis2:echoMessage" />> message="axis2:echoResponse" > />> type="axis2:MyService2PortType"> name="MyService2SOAP11Binding">> style="document" transport=" http://schemas.xmlsoap.org/soap/http"> />> soapAction="urn:echo" />> />> />> type="axis2:MyService2PortType" > name="MyService2SOAP12Binding">> transport="> http://schemas.xmlsoap.org/soap/http" />> name="echo">> />> />> />> type="axis2:MyService2PortType"> name="MyService2HttpBinding">> verb="POST" />> location="echo"> />> />> />> name="MyService2">> name="MyService2SOAP11port_http"> http://localhost:8080/axis2/services/MyService2"> />> binding="axis2:MyService2SOAP12Binding"> name="MyService2SOAP12port_http">http://localhost:8080/axis2/services/MyService2"> />> binding="axis2:MyService2HttpBinding" > name="MyService2Httpport0">http://localhost:8080/axis2/rest/MyService2"> /> > I then try to use WSDL2Java to create client stubs based on this> WSDL. It> does generate them, but when I try to run the client I get the> following> error:>>> Exception in thread "main" java.lan
Re: Axis2 / Axis RPC
Hi, Basically what I'm trying to do is to create a simple Web Service that will receive a String and retun the same string, i.e. basically an "echo" web service. I tried using the sample on the Axis2 documentation page with OMElement - it works fine. My problem is that I want to use String instead of OMElement on both sides (server as well as client). Apparently, I cant do this unless I use the RPC So what I have is a services.xml that looks like this: -- operation> MyService2parameter > service> A MyService2.java that looks like this: public class MyService2 { public String echo(String echostring) { return echostring; } } I can deploy this using axis2.war on JBoss. It deploys fine, and I get the following WSDL: http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://ws.apache.org/axis2" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http:///xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://ws.apache.org/axis2">http:///xsd" targetNamespace="http:///xsd" elementFormDefault="qualified" attributeFormDefault="qualified"> http://schemas.xmlsoap.org/soap/http" />http://schemas.xmlsoap.org/soap/http" />http://localhost:8080/axis2/services/MyService2" />http://localhost:8080/axis2/services/MyService2" />http://localhost:8080/axis2/rest/MyService2" /> I then try to use WSDL2Java to create client stubs based on this WSDL. It does generate them, but when I try to run the client I get the following error: Exception in thread "main" java.lang.RuntimeException:java.lang.RuntimeException: Unexpected subelement returnat org.apache.axis2.MyService2Stub.fromOM(MyService2Stub.java:665)at org.apache.axis2.MyService2Stub.echo(MyService2Stub.java:144)at org.apache.axis2.Client.main(Client.java:16)Caused by: java.lang.RuntimeException: Unexpected subelement returnatorg.apache.axis2.MyService2Stub$EchoResponse$Factory.parse (MyService2Stub.java:419)at org.apache.axis2.MyService2Stub.fromOM(MyService2Stub.java:657)... 2 moreI googled this and this page ( http://mail-archives.apache.org/mod_mbox/ws-axis-dev/200605.mbox/[EMAIL PROTECTED]) claims that this error message appears because axis2 does not support RPC Bindings.I'm confused - how do I generate a client for this WSDL?
Re: Axis2 / Axis RPC
I tried to make my own by generating the stub files usingWSDL2Java from the WSDL generated by Axis.Everything seems fine, I deploy it, etc. but when I try to run the clientI get the following: Exception in thread "main" java.lang.RuntimeException:java.lang.RuntimeException: Unexpected subelement returnat org.apache.axis2.MyService2Stub.fromOM(MyService2Stub.java:665)at org.apache.axis2.MyService2Stub.echo (MyService2Stub.java:144)at org.apache.axis2.Client.main(Client.java:16)Caused by: java.lang.RuntimeException: Unexpected subelement returnatorg.apache.axis2.MyService2Stub$EchoResponse$Factory.parse (MyService2Stub.java:419)at org.apache.axis2.MyService2Stub.fromOM(MyService2Stub.java:657)... 2 moreI googled it and according to http://mail-archives.apache.org/mod_mbox/ws-axis-dev/200605.mbox/[EMAIL PROTECTED]this is because axis does not support RPC bindings. On 7/6/06, Anne Thomas Manes <[EMAIL PROTECTED]> wrote: Why were you unable to generate a client using Axis2?See http://ws.apache.org/axis2/tools/1_0/CodegenToolReference.html.Anne On 7/6/06, M S <[EMAIL PROTECTED]> wrote:> Hi,>> I am a newbie trying to create a RPC-based Web Service. I created this> using Axis2 (latest nightly build dated 5th July). The problem is that I > cannot use WSDL2Java to generate the Client stubs. So what I did is to use> the old Axis (1.4 from 22nd April) to do this.>> For some reason I don't get it to work. My Client code looks like this: >> package org.apache.ws.axis;>> import javax.xml.namespace.*;> import javax.xml.rpc.*;> import java.rmi.*;> import java.net.*;>> public class Client2 { >> public Client2() {}>> interface MyPrimeHandler extends Remote {> public String echo(String echostring) throws RemoteException;> }>> public void invokeService() { > String msg = "Det funkar";> try {> String wsdlLoc => "http://localhost:8080/axis2/services/MyService2?wsdl ";> QName serviceName = new> QName("http://localhost:8080/axis2/services/MyService2",> "MyService2"); > ServiceFactory sFactory = ServiceFactory.newInstance();> Service service = sFactory.createService(new URL(wsdlLoc),> serviceName);> MyPrimeHandler mp => (MyPrimeHandler)service.getPort(MyPrimeHandler.class);> String resp = mp.echo(msg); > System.out.println(resp);> }>> catch (Exception e) { e.printStackTrace();}> }>> public static void main(String[] args) {> Client2 cl2 = new Client2(); > cl2.invokeService();> }>> }>> The exception that I get is:>> - Unable to find required classes (javax.activation.DataHandler and> javax.mail.internet.MimeMultipart ). Attachment support is> disabled.> javax.xml.rpc.ServiceException: Error processing WSDL document:> javax.xml.rpc.ServiceException: Error processing WSDL document:> javax.xml.rpc.ServiceException : Cannot find service:> {http://localhost:8080/axis2/services/MyService2}MyService2> at> org.apache.axis.client.Service.initService (Service.java:250)> at org.apache.axis.client.Service.(Service.java:165)> at> org.apache.axis.client.ServiceFactory.createService(ServiceFactory.java:198)> at> org.apache.ws.axis.Client2.invokeService(Client2.java:22)> at org.apache.ws.axis.Client2.main(Client2.java:33)>>> I have checked and the EPR exists at the specified URL above.> > Does anyone have an idea on how I should solve this problem? Or am I> barking up the wrong tree? Perhaps there is some other way generating client> stubs with Axis2? Any help would be appreciated.> > Regards>>-To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Axis2 / Axis RPC
Hi, I am a newbie trying to create a RPC-based Web Service. I created this using Axis2 (latest nightly build dated 5th July). The problem is that I cannot use WSDL2Java to generate the Client stubs. So what I did is to use the old Axis (1.4 from 22nd April) to do this. For some reason I don't get it to work. My Client code looks like this: package org.apache.ws.axis; import javax.xml.namespace.*; import javax.xml.rpc.*; import java.rmi.*; import java.net.*; public class Client2 { public Client2() {} interface MyPrimeHandler extends Remote { public String echo(String echostring) throws RemoteException; } public void invokeService() { String msg = "Det funkar"; try { String wsdlLoc = "http://localhost:8080/axis2/services/MyService2?wsdl"; QName serviceName = new QName("http://localhost:8080/axis2/services/MyService2", "MyService2"); ServiceFactory sFactory = ServiceFactory.newInstance(); Service service = sFactory.createService(new URL(wsdlLoc), serviceName); MyPrimeHandler mp = (MyPrimeHandler)service.getPort(MyPrimeHandler.class); String resp = mp.echo(msg); System.out.println(resp); } catch (Exception e) { e.printStackTrace();} } public static void main(String[] args) { Client2 cl2 = new Client2(); cl2.invokeService(); } } The exception that I get is: - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled. javax.xml.rpc.ServiceException: Error processing WSDL document: javax.xml.rpc.ServiceException: Error processing WSDL document: javax.xml.rpc.ServiceException: Cannot find service: {http://localhost:8080/axis2/services/MyService2}MyService2 at org.apache.axis.client.Service.initService(Service.java:250) at org.apache.axis.client.Service.(Service.java:165) at org.apache.axis.client.ServiceFactory.createService(ServiceFactory.java:198) at org.apache.ws.axis.Client2.invokeService(Client2.java:22) at org.apache.ws.axis.Client2.main(Client2.java:33) I have checked and the EPR exists at the specified URL above. Does anyone have an idea on how I should solve this problem? Or am I barking up the wrong tree? Perhaps there is some other way generating client stubs with Axis2? Any help would be appreciated. Regards
1.2rc2 (Wrapped) Document/Literal soap response for array items xmlns set to ""
Hi, It looks like AXIS 1.2 RC2 is sometimes incorrectly setting/including the xmlns="" attribute for child "item"s of array elements when using Document/Literal (Wrapped). My .NET cilent cannot deserialize the requestedAttributes (NamedValue[]) section of complex type Item correctly, yet can correctly deserialize the top-level loginReturn (which is also NamedValue[]). Is this bug http://issues.apache.org/jira/browse/AXIS-1547 thanks, Matt. SOAP (Respone) Body Contents: http://xmlns.mycompany.com/ws"> LOGIN_USER http://xmlns.mycompany.com/ws"> 6678 sancho EMAIL_ADDRESS [EMAIL PROTECTED] PERSONAL_WORKSPACE:NAME sancho USER Relevant WSDL Sections: Find just what you're after with the new, more precise MSN Search - try it now!
Re: Using .NET how to deserialize obj from detail element of SOAP fault sentby AXIS?
Hi All, I switched the server over to utilize (Wrapped) Doc / Literal (using java2wsdl) and created new Web Reference in .NET. Once I did this, I was able to successfully deserialize using XmlSerializer after I put in an XmlRootAttribute setting on the generated FdkException class. For the life of me, I could not get the damn SoapFormatter to decode RPC/Encoded - kept complaining about missing top object or something along those lines. For those curious, the code I used was: FdkException fe = null; XmlReader reader = null; XmlWriter writer = null; MemoryStream mem = new MemoryStream(); reader = new XmlNodeReader(se.Detail.FirstChild); writer = new XmlTextWriter(mem, System.Text.Encoding.UTF8); writer.WriteNode(reader,true); writer.Flush(); mem.Position = 0; XmlSerializer serializer = new XmlSerializer(typeof(FdkException)); fe = (FdkException) serializer.Deserialize(mem); The crazy thing is that .NET was working perfectly with RPC / Encoded for everything other than my manual deserialization efforts. It would seem Doc / Literal is the way of the future anyway. thanks, Matt. >From: Anne Thomas Manes <[EMAIL PROTECTED]> >Reply-To: Anne Thomas Manes <[EMAIL PROTECTED]> >To: axis-user@ws.apache.org >Subject: Re: Using .NET how to deserialize obj from detail element of SOAP fault sentby AXIS? >Date: Wed, 16 Mar 2005 10:50:23 -0500 > >Per both the SOAP 1.1 spec and the WS-I BP, faults must be described >as document/literal -- even if the input and output messages are >rpc/encoded. Perhaps that's why .NET is having so much trouble. > >Anne > > >On Tue, 15 Mar 2005 20:11:45 -0800, Dino Chiesa <[EMAIL PROTECTED]> wrote: > > > > > Does .NET uses XMLSerializer behind the scenes to perform > > serialization/deserialization of SOAP messages? > > > > Yes, it can, but not SOAP Section-5 encoded messages. In .NET, that is done > > by the SOAP serializer. > > > > > Is there an alternative preferred/standard mechanism to define array types > > in the WSDL? > > > > Yes, see > > http://wiki.apache.org/ws/DotNetInteropArrays?action="" > > > > > Assuming I was not using the funky array stuff, and just trying to > > deserialize a standard object with xsd string/int attributes etc by using > > the detail element inside a SoapException, do you know how you would go > > about doing this? > > > > Like this? > > > > catch (System.Web.Services.Protocols.SoapException ex1) { > > Console.WriteLine("SOAP Exception: '{0}'", ex1.ToString()); > > if (ex1.Detail != null) { > > > > System.Xml.Serialization.XmlSerializer ser= new > > System.Xml.Serialization.XmlSerializer(typeof(FdkException)); > > > > System.IO.StringReader sr= new > > System.IO.StringReader(ex1.Detail.InnerXml); > > FdkException fault= (FdkException) ser.Deserialize(new > > System.Xml.XmlTextReader(sr)); > > > > Console.WriteLine("fault.errorCode: '{0}'", fault.errorCode); > > Console.WriteLine("fault.stack: '{0}'", fault.serverStackTraceId); > > // etc > > } > > else > > Console.WriteLine("detail is null!"); > > } > > > > > > The FdkException has to be exposed into the WSDL, so that it gets generated > > into the client-side proxy class. or it must otherwise be known to the > > client. > > > > > > > > From: M S [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, March 15, 2005 9:23 PM > > To: axis-user@ws.apache.org > > Subject: RE: Using .NET how to deserialize obj from detail element of SOAP > > fault sentby AXIS? > > > > > > > > > > > > > > Hi Dino, > > > > Thanks for your reply. > > > > Does .NET uses XMLSerializer behind the scenes to perform > > serialization/deserialization of SOAP messages? > > > > If so, it seems to support these complex array types (defined in the same > > .WSDL file) fine - and I didn't do anything tricky to make this happen > > either. I just used the web reference tool to point to the WSDL file and > > woila! > > > > > > For example, on a successful login, the server returns a loginResponse > > message that is defined as following: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
RE: Using .NET how to deserialize obj from detail element of SOAP fault sentby AXIS?
Hi Dino, Thanks for your reply. Does .NET uses XMLSerializer behind the scenes to perform serialization/deserialization of SOAP messages? If so, it seems to support these complex array types (defined in the same .WSDL file) fine - and I didn't do anything tricky to make this happen either. I just used the web reference tool to point to the WSDL file and woila! For example, on a successful login, the server returns a loginResponse message that is defined as following: Where: xmlns:impl="http://xmlns.mycompany.com/app/ws" and: xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"and: xmlns:xsd="http://www.w3.org/2001/XMLSchema" In my code, the following works perfectly: int sessionTimeout = -1, transactionTimeout = -1;Item user = null;NamedValue[] nvArray = null;try{ nvArray = rlManager.login(username,password);}catch(System.Web.Services.Protocols.SoapException e){ throw;}for (int i=0; i { switch (nvArray[i].name) { case WebServiceConstants.LOGIN_USER: if (!(nvArray[i].value is Item)) throw new exception.UnexpectedTypeException(WebServiceConstants.LOGIN_USER + " not an Item."); user = (Item) nvArray[i].value; if (user.type != ItemTypes.USER) throw new exception.UnexpectedTypeException(WebServiceConstants.LOGIN_USER + " not an Item of type " + ItemTypes.USER); break; case WebServiceConstants.SESSION_TIMEOUT: if (!(nvArray[i].value is Int32)) throw new exception.UnexpectedTypeException(WebServiceConstants.SESSION_TIMEOUT + " not an Int32."); sessionTimeout = (Int32) nvArray[i].value; break; case WebServiceConstants.TRANSACTION_TIMEOUT: if (!(nvArray[i].value is Int32)) throw new exception.UnexpectedTypeException(WebServiceConstants.TRANSACTION_TIMEOUT + " not an Int32."); transactionTimeout = (Int32) nvArray[i].value; break; default: break; }}if (user == null){ throw new exception.AccessDeniedException();} Is there an alternative preferred/standard mechanism to define array types in the WSDL? Assuming I was not using the funky array stuff, and just trying to deserialize a standard object with xsd string/int attributes etc by using the detail element inside a SoapException, do you know how you would go about doing this? many thanks, Matt. >From: "Dino Chiesa" <[EMAIL PROTECTED]> >Reply-To: axis-user@ws.apache.org >To: >Subject: RE: Using .NET how to deserialize obj from detail element of SOAP fault sentby AXIS? >Date: Tue, 15 Mar 2005 17:32:05 -0800 > >first, >get rid of that >soapenc:Array >stuff. > >.NET's XML Serializer won't handle that ! > >The SOAP serializer might, but >I can't help you there. > > > > > > > >From: M S [mailto:[EMAIL PROTECTED] >Sent: Tuesday, March 15, 2005 6:53 PM >To: axis-user@ws.apache.org >Subject: Using .NET how to deserialize obj from detail element of SOAP >fault sentby AXIS? > > > >Hello, > >I'm trying to build a C# client to consume an AXIS Web Service (running >SOAP over HTTP). The Web Service encodes full server-side exception >traces in the Soap Fault > Detail element using complex type structures >declared in the WSDL file. > > > >I have had absolutely no luck working out how I can deserialize the >custom server exception object out of the detail element using .NET >(C#). I' wondering if anyone in the AXIS community has done this >before? > > > >I have tried both SoapFormatter, and XmlSerializer with absolutely no >luck. > > > >try > >{ > > <<<< e.g. login operation >>>> > >} > >catch (System.Web.Services.Protocols.SoapException e) > >{ > > XmlReader reader = null; > > XmlWriter writer = null; > > MemoryStream mem = new MemoryStream(); > > FdkException fe = null; > > > > try > > { > > reader = new XmlNodeReader(e.Detail.FirstChild); > > writer = new XmlTextWriter(mem, System.Text.Encoding.UTF8); > > writer.WriteNode(reader,true); > > writer.Flush(); > > mem.Position = 0; > > > > <<<< Add deserialization code here >>>> > > fe = (FdkException) > > } > > catch (Exception ex) > > { > > System.Console.WriteLine(ex.toString()); > > throw; > > } > >} > > > >The first deserialization mechansim I tried was using >System.Runtime.Serialization.Formatters.Soap.SoapFormatter > > > >SoapFormatter sf = new SoapFormatter(); > >sf.Binder = new FdkExceptionDeserializationBinder(); > >fe = (FdkException) s
Using .NET how to deserialize obj from detail element of SOAP fault sentby AXIS?
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element using complex type structures declared in the WSDL file. I have had absolutely no luck working out how I can deserialize the custom server exception object out of the detail element using .NET (C#). I' wondering if anyone in the AXIS community has done this before? I have tried both SoapFormatter, and XmlSerializer with absolutely no luck. try { e.g. login operation } catch (System.Web.Services.Protocols.SoapException e) { XmlReader reader = null; XmlWriter writer = null; MemoryStream mem = new MemoryStream(); FdkException fe = null; try { reader = new XmlNodeReader(e.Detail.FirstChild); writer = new XmlTextWriter(mem, System.Text.Encoding.UTF8); writer.WriteNode(reader,true); writer.Flush(); mem.Position = 0; Add deserialization code here fe = (FdkException) } catch (Exception ex) { System.Console.WriteLine(ex.toString()); throw; } } The first deserialization mechansim I tried was using System.Runtime.Serialization.Formatters.Soap.SoapFormatter SoapFormatter sf = new SoapFormatter(); sf.Binder = new FdkExceptionDeserializationBinder(); fe = (FdkException) sf.Deserialize(mem); With FdkExceptionDeserializationBinder.cs looking like the following: public class FdkExceptionDeserializationBinder : System.Runtime.Serialization.SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { if (assemblyName.Equals("http://xmlns.mycompany.com/app/ws")) { switch (typeName) { case "FdkException" : return typeof(FdkException); break; case "ArrayOfFdkExceptionEntry" : return typeof(FdkExceptionEntry[]); break; } } return Type.GetType(String.Format("{0}, {1}", typeName, assemblyName)); } } This deserialization approach resulted in an exception: Exception Type: System.Runtime.Serialization.SerializationException Message: No Top Object Source: System.Runtime.Serialization.Formatters.Soap The second deserialization mechanism I tried was using XmlSerializer: XmlTypeMapping myMapping = (new SoapReflectionImporter().ImportTypeMapping(typeof(FdkException))); XmlSerializer serializer = new XmlSerializer(myMapping); fe = (FdkException) serializer.Deserialize(mem); I set Soap options in the FdkException class: using System; using System.Xml.Serialization; ... [Serializable] [SoapTypeAttribute(Namespace="http://xmlns.mycompany.com/app/ws", TypeName=fault)] public class FdkException { public string errorCode; public FdkExceptionEntry[] exceptionEntries; public string serverStackTraceId; } using System; using System.Xml.Serialization; [Serializable] [SoapTypeAttribute(Namespace="http://xmlns.mycompany.com/app/ws", TypeName=FdkExceptionEntry)] public class FdkExceptionEntry { public string errorCode; public long id; public string serverStackTraceId; } I got the following exception: Message: There is an error in XML Document (1,541). Exception Type: System.InvalidOperationException Source: System.Xml Inner Exception: Message: Cannot assign object of type System.Xml.XmlNode[] to an object of type FdkException Exception Type: System.InvalidCastException Below is the SOAP message returned from the server on an invalid logon attempt (including Fault):- soapenv:Server.userException AccessDenied AccessDenied - Invalid Credentials Below is relevant pieces of the WSDL file relating to the FdkException object: Has anyone out there been able to deserialize from SOAP fault detail element using C#? many thanks, Matt. Try the new Beta version of MSN Messenger - it's FREE!