KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > addressrewrite > AddressRewriteTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.webservice.addressrewrite;
23
24 import java.net.URL JavaDoc;
25
26 import javax.management.Attribute JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.xml.namespace.QName JavaDoc;
29 import javax.xml.rpc.Call JavaDoc;
30 import javax.xml.rpc.Service JavaDoc;
31 import javax.xml.rpc.ServiceFactory JavaDoc;
32
33 import org.jboss.test.JBossTestCase;
34
35 /**
36  * Test soap:address rewriting in the WSDL.
37  *
38  * @author jason.greene@jboss.com
39  */

40 public class AddressRewriteTestCase extends JBossTestCase
41 {
42    private static String JavaDoc NAMESPACE = "http://test.jboss.org/ws4eesimple";
43    private String JavaDoc WSDL_LOCATION = "http://" + getServerHost() + ":8080/ws4ee-addressrewrite?wsdl";
44    private String JavaDoc WSDL_LOCATION_SEC = "http://" + getServerHost() + ":8080/ws4ee-addressrewrite-sec?wsdl";
45
46    private ObjectName JavaDoc objectName;
47    private Boolean JavaDoc alwaysModifySOAPAddress;
48    private String JavaDoc wsHost;
49
50    /**
51     * Construct the test case with a given name
52     */

53    public AddressRewriteTestCase(String JavaDoc name)
54    {
55       super(name);
56    }
57
58    public void setUp() throws Exception JavaDoc
59    {
60       ObjectName JavaDoc ws4eeServiceName = new ObjectName JavaDoc("jboss.ws4ee:service=AxisService");
61       ObjectName JavaDoc jbosswsServiceName = new ObjectName JavaDoc("jboss.ws:service=ServiceEndpointManager");
62
63       if (getServer().isRegistered(ws4eeServiceName))
64          objectName = ws4eeServiceName;
65       else if (getServer().isRegistered(jbosswsServiceName))
66          objectName = jbosswsServiceName;
67
68       alwaysModifySOAPAddress = (Boolean JavaDoc)getServer().getAttribute(objectName, "AlwaysModifySOAPAddress");
69       wsHost = (String JavaDoc)getServer().getAttribute(objectName, "WebServiceHost");
70    }
71
72    public void tearDown() throws Exception JavaDoc
73    {
74       Attribute JavaDoc attr = new Attribute JavaDoc("AlwaysModifySOAPAddress", alwaysModifySOAPAddress);
75       getServer().setAttribute(objectName, attr);
76    }
77
78    public void testRewrite() throws Exception JavaDoc
79    {
80       setupAlwaysModify(new Boolean JavaDoc(true));
81       deploy("ws4ee-addressrewrite.war");
82       try
83       {
84          ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
85
86          Service JavaDoc service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "ValidURLService"));
87          Call JavaDoc call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "ValidURLPort"), "sayHello");
88          assertEquals("http://" + wsHost + ":8080/ws4ee-addressrewrite", call.getTargetEndpointAddress());
89
90          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "InvalidURLService"));
91          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "InvalidURLPort"), "sayHello");
92          assertEquals("http://" + wsHost + ":8080/ws4ee-addressrewrite", call.getTargetEndpointAddress());
93
94          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "ValidSecureURLService"));
95          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "ValidSecureURLPort"), "sayHello");
96          assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite", call.getTargetEndpointAddress());
97
98          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "InvalidSecureURLService"));
99          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "InvalidSecureURLPort"), "sayHello");
100          assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite", call.getTargetEndpointAddress());
101       }
102       finally
103       {
104          undeploy("ws4ee-addressrewrite.war");
105       }
106    }
107
108    /**
109     * Rewrite soap:address URL according to transport guarantee
110     *
111     * http://jira.jboss.org/jira/browse/JBWS-454
112     */

113    public void testSecureRewrite() throws Exception JavaDoc
114    {
115       deploy("ws4ee-addressrewrite-sec.war");
116       try
117       {
118          ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
119
120          Service JavaDoc service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION_SEC), new QName JavaDoc(NAMESPACE, "ValidURLService"));
121          Call JavaDoc call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "ValidURLPort"), "sayHello");
122          assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress());
123
124          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION_SEC), new QName JavaDoc(NAMESPACE, "InvalidURLService"));
125          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "InvalidURLPort"), "sayHello");
126          assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress());
127
128          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION_SEC), new QName JavaDoc(NAMESPACE, "ValidSecureURLService"));
129          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "ValidSecureURLPort"), "sayHello");
130          assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress());
131
132          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION_SEC), new QName JavaDoc(NAMESPACE, "InvalidSecureURLService"));
133          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "InvalidSecureURLPort"), "sayHello");
134          assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress());
135       }
136       finally
137       {
138          undeploy("ws4ee-addressrewrite-sec.war");
139       }
140    }
141
142    public void testNoRewrite() throws Exception JavaDoc
143    {
144       setupAlwaysModify(new Boolean JavaDoc(false));
145       deploy("ws4ee-addressrewrite.war");
146       try
147       {
148          ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
149
150          Service JavaDoc service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "ValidURLService"));
151          Call JavaDoc call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "ValidURLPort"), "sayHello");
152          assertEquals("http://somehost:80/somepath", call.getTargetEndpointAddress());
153
154          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "InvalidURLService"));
155          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "InvalidURLPort"), "sayHello");
156          assertEquals("http://" + wsHost + ":8080/ws4ee-addressrewrite", call.getTargetEndpointAddress());
157
158          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "ValidSecureURLService"));
159          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "ValidSecureURLPort"), "sayHello");
160          assertEquals("https://somehost:443/some-secure-path", call.getTargetEndpointAddress());
161
162          service = serviceFactory.createService(new URL JavaDoc(WSDL_LOCATION), new QName JavaDoc(NAMESPACE, "InvalidSecureURLService"));
163          call = (Call JavaDoc)service.createCall(new QName JavaDoc(NAMESPACE, "InvalidSecureURLPort"), "sayHello");
164          assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite", call.getTargetEndpointAddress());
165       }
166       finally
167       {
168          undeploy("ws4ee-addressrewrite.war");
169       }
170    }
171
172    private void setupAlwaysModify(Boolean JavaDoc value) throws Exception JavaDoc
173    {
174       Attribute JavaDoc attr = new Attribute JavaDoc("AlwaysModifySOAPAddress", value);
175       getServer().setAttribute(objectName, attr);
176    }
177 }
Popular Tags