Bonjour à tous,
Voilà, je suis entrain de mettre en place un mécanisme d'authentification avec Http Basic Authentication pour accéder à mon web service HelloWorl, j'ai donc voulu tester avec un client Axis sous eclipse (qui l'a generé à partir du wsdl).
J'ai ajouter des paramètre (Username et Password) dans le HelloWorldImplServiceSoapBindingStub comme suit :
Voici un test Junit sur le client :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public java.lang.String sayHi(java.lang.String nom, java.lang.String text) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[0]); _call.setUseSOAPAction(true); _call.setSOAPActionURI("http://spring.demo/sayHi"); _call.setEncodingStyle(null); System.out.println("ESSAI AUTH DEBUT"); try { AuthToken t = AuthSingleton.getInstance().getToken(1); _call.setProperty(org.apache.axis.client.Call.USERNAME_PROPERTY, t.getUsername()); _call.setProperty(org.apache.axis.client.Call.PASSWORD_PROPERTY, t.getPassword()); } catch (Exception e) { System.out.println(e.getMessage()); } System.out.println("ESSAI AUTH FIN"); _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE); _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); _call .setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName( "http://spring.demo/", "sayHi")); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] { nom, text }); if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException) _resp; } else { extractAttachments(_call); try { return (java.lang.String) _resp; } catch (java.lang.Exception _exception) { return (java.lang.String) org.apache.axis.utils.JavaUtils .convert(_resp, java.lang.String.class); } } } catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } }
J'ai ainsi une erreur 404 de la sorte et je ne sais pas d'où vient le problème.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 public class test extends TestCase { public void testSayHi() throws ServiceException, RemoteException { demo.spring.HelloWorldImplService service = new demo.spring.HelloWorldImplServiceLocator(); demo.spring.HelloWorld port = service.getHelloWorldPort(); // final String test = port.sayHi("toto", "titi"); try { System.out.println(port.sayHi("toto", "titi")); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Avez vous une idée?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 AxisFault faultCode: {http://xml.apache.org/axis/}HTTP faultSubcode: faultString: (404)Introuvable faultActor: faultNode: faultDetail: {}:return code: 404 <html><body>No service was found.</body></html> {http://xml.apache.org/axis/}HttpErrorCode:404 (404)Introuvable at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744) at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165) at org.apache.axis.client.Call.invokeEngine(Call.java:2784) at org.apache.axis.client.Call.invoke(Call.java:2767) at org.apache.axis.client.Call.invoke(Call.java:2443) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) at demo.spring.HelloWorldImplServiceSoapBindingStub.sayHi(HelloWorldImplServiceSoapBindingStub.java:143) at demo.spring.test.testSayHi(test.java:18) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Partager