KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > jbws425 > JBWS425TestCase


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.jbws425;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.net.URL JavaDoc;
26
27 import javax.naming.InitialContext 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 import javax.xml.soap.MessageFactory JavaDoc;
33 import javax.xml.soap.MimeHeaders JavaDoc;
34 import javax.xml.soap.SOAPConnection JavaDoc;
35 import javax.xml.soap.SOAPConnectionFactory JavaDoc;
36 import javax.xml.soap.SOAPElement JavaDoc;
37 import javax.xml.soap.SOAPMessage JavaDoc;
38
39 import junit.framework.Test;
40
41 import org.jboss.test.webservice.WebserviceTestBase;
42
43 /**
44  * No SOAPAction when message is sent with SOAPConnection
45  *
46  * http://jira.jboss.com/jira/browse/JBWS-425
47  *
48  * @author Thomas.Diesler@jboss.org
49  * @since 30-Nov-2005
50  */

51 public class JBWS425TestCase extends WebserviceTestBase
52 {
53    private static final String JavaDoc SOAP_ACTION = "\"urn:some-soap-action\"";
54
55    private static Hello endpoint;
56
57    public JBWS425TestCase(String JavaDoc name)
58    {
59       super(name);
60    }
61
62    public static Test suite() throws Exception JavaDoc
63    {
64       return getDeploySetup(JBWS425TestCase.class, "ws4ee-jbws425.war, ws4ee-jbws425-client.jar");
65    }
66
67    public void setUp() throws Exception JavaDoc
68    {
69       super.setUp();
70       if (endpoint == null)
71       {
72          InitialContext JavaDoc iniCtx = getClientContext();
73          Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/HelloService");
74          endpoint = (Hello)service.getPort(Hello.class);
75       }
76    }
77
78    public void testClientActionFromWSDL() throws Exception JavaDoc
79    {
80       String JavaDoc soapAction = endpoint.hello("Hello Server");
81       assertEquals(SOAP_ACTION, soapAction);
82    }
83
84    // [JBWS-983] Configure SOAPAction on the Call object
85
public void testCallActionFromProperty() throws Exception JavaDoc
86    {
87        ServiceFactory JavaDoc factory = ServiceFactory.newInstance();
88       URL JavaDoc wsdlUrl = new URL JavaDoc("http://" + getServerHost() + ":8080/ws4ee-jbws425?wsdl");
89       QName JavaDoc serviceName = new QName JavaDoc("http://org.jboss.test.webservice/jbws425", "HelloService");
90       QName JavaDoc portName = new QName JavaDoc("http://org.jboss.test.webservice/jbws425", "HelloPort");
91       Service JavaDoc service = factory.createService(wsdlUrl, serviceName);
92       Call JavaDoc call = service.createCall(portName, "hello");
93       call.setProperty(Call.SOAPACTION_URI_PROPERTY, "uri:property-action");
94       String JavaDoc soapAction = (String JavaDoc)call.invoke(new Object JavaDoc[] {"Hello Server"});
95       assertEquals("\"uri:property-action\"", soapAction);
96    }
97
98    public void testMessageAccess() throws Exception JavaDoc
99    {
100       String JavaDoc reqEnv =
101          "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" +
102          " <soapenv:Body>" +
103          " <ns1:hello xmlns:ns1='http://org.jboss.test.webservice/jbws425'>" +
104          " <String_1>Hello Server</String_1>" +
105          " </ns1:hello>" +
106          " </soapenv:Body>" +
107          "</soapenv:Envelope>";
108
109       MessageFactory JavaDoc msgFactory = MessageFactory.newInstance();
110       SOAPConnection JavaDoc con = SOAPConnectionFactory.newInstance().createConnection();
111
112       MimeHeaders JavaDoc mimeHeaders = new MimeHeaders JavaDoc();
113       mimeHeaders.addHeader("SOAPAction", SOAP_ACTION);
114
115       SOAPMessage JavaDoc reqMsg = msgFactory.createMessage(mimeHeaders, new ByteArrayInputStream JavaDoc(reqEnv.getBytes()));
116
117       URL JavaDoc epURL = new URL JavaDoc("http://" + getServerHost() + ":8080/ws4ee-jbws425");
118       SOAPMessage JavaDoc resMsg = con.call(reqMsg, epURL);
119
120       SOAPElement JavaDoc soapElement = (SOAPElement JavaDoc)resMsg.getSOAPBody().getChildElements().next();
121       soapElement = (SOAPElement JavaDoc)soapElement.getChildElements().next();
122       String JavaDoc soapAction = soapElement.getValue();
123       assertEquals(SOAP_ACTION, soapAction);
124    }
125
126 }
127
Popular Tags