rpcproxytests.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 422 行 · 第 1/2 页
JAVA
422 行
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axis2.jaxws.proxy;
import java.io.File;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Holder;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceException;
import junit.framework.TestCase;
import org.apache.axis2.jaxws.proxy.rpclit.RPCLitImpl;
import org.apache.axis2.jaxws.proxy.rpclit.sei.RPCFault;
import org.apache.axis2.jaxws.proxy.rpclit.sei.RPCLit;
import org.apache.axis2.jaxws.TestLogger;
import org.test.proxy.rpclit.ComplexAll;
import org.test.proxy.rpclit.Enum;
public class RPCProxyTests extends TestCase {
private QName serviceName = new QName(
"http://org.apache.axis2.jaxws.proxy.rpclit", "RPCLitService");
private String axisEndpoint = "http://localhost:8080/axis2/services/RPCLitService";
private QName portName = new QName("http://org.apache.axis2.jaxws.proxy.rpclit",
"RPCLit");
private String wsdlLocation = System.getProperty("basedir",".")+"/"+"test/org/apache/axis2/jaxws/proxy/rpclit/META-INF/RPCLit.wsdl";
/**
* Utility method to get the proxy
* @return RPCLit proxy
* @throws MalformedURLException
*/
public RPCLit getProxy() throws MalformedURLException {
File wsdl= new File(wsdlLocation);
URL wsdlUrl = wsdl.toURL();
Service service = Service.create(null, serviceName);
Object proxy =service.getPort(portName, RPCLit.class);
BindingProvider p = (BindingProvider)proxy;
p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,axisEndpoint);
return (RPCLit)proxy;
}
/**
* Utility Method to get a Dispatch<String>
* @return
* @throws MalformedURLException
*/
public Dispatch<String> getDispatch() throws MalformedURLException {
File wsdl= new File(wsdlLocation);
URL wsdlUrl = wsdl.toURL();
Service service = Service.create(null, serviceName);
service.addPort(portName, null, axisEndpoint);
Dispatch<String> dispatch = service.createDispatch(portName, String.class, Service.Mode.PAYLOAD);
return dispatch;
}
/**
* Simple test that ensures that we can echo a string to an rpc/lit web service
*/
public void testSimple() throws Exception {
try{
RPCLit proxy = getProxy();
String request = "This is a test...";
String response = proxy.testSimple(request);
assertTrue(response != null);
assertTrue(response.equals(request));
}catch(Exception e){
e.printStackTrace();
fail("Exception received" + e);
}
}
/**
* Simple test that ensures that we can echo a string to an rpc/lit web service
*/
public void testSimpleInOut() throws Exception {
try{
RPCLit proxy = getProxy();
String request = "This is a test...";
Holder<String> requestParam = new Holder<String>();
requestParam.value = request;
String response = proxy.testSimpleInOut(requestParam);
assertTrue(response != null);
assertTrue(response.equals(request));
assertTrue(requestParam.value.equals(request));
}catch(Exception e){
e.printStackTrace();
fail("Exception received" + e);
}
}
/**
* Simple test that ensures that we can echo a string to an rpc/lit web service
*/
public void testSimple2() throws Exception {
try{
RPCLit proxy = getProxy();
String request1 = "hello";
String request2 = "world";
String response = proxy.testSimple2(request1, request2);
assertTrue(response != null);
assertTrue(response.equals("helloworld"));
}catch(Exception e){
e.printStackTrace();
fail("Exception received" + e);
}
}
/**
* Simple test that ensures that we can echo a string to an rpc/lit web service.
* This test passes the information in headers
*/
public void testHeader() throws Exception {
RPCLit proxy = getProxy();
String request1 = "hello";
String request2 = "world";
String response = proxy.testHeader(request1, request2);
assertTrue(response != null);
assertTrue(response.equals("helloworld"));
}
/**
* Simple test that ensures that a service fault is thrown correctly
*/
public void testFault() throws Exception {
try{
RPCLit proxy = getProxy();
proxy.testFault();
fail("Expected RPCFault");
} catch(RPCFault rpcFault){
assertTrue(rpcFault.getMessage().equals("Throw RPCFault"));
assertTrue(rpcFault.getFaultInfo() == 123);
} catch(Exception e){
e.printStackTrace();
fail("Exception received" + e);
}
}
/**
* Simple test that ensures that we can echo a string to an rpc/lit web service
*/
public void testForNull() throws Exception {
try{
RPCLit proxy = getProxy();
String request = null;
String response = proxy.testSimple(request);
fail("RPC/LIT should throw webserviceException when operation is invoked with null input parameter");
}catch(Exception e){
assertTrue(e instanceof WebServiceException);
TestLogger.logger.debug(e.getMessage());
}
}
/**
* Simple test that ensures that we can echo a string to an rpc/lit web service
*/
public void testForNullReturn() throws Exception {
try{
RPCLit proxy = getProxy();
String response = proxy.testSimple("returnNull");
fail("RPC/LIT should throw webserviceException when operation is invoked with null out parameter");
}catch(Exception e){
assertTrue(e instanceof WebServiceException);
TestLogger.logger.debug(e.getMessage());
}
}
public void testSimple_Dispatch() throws Exception {
// Send a payload that simulates
// the rpc message
String request = "<tns:testSimple xmlns:tns='http://org/apache/axis2/jaxws/proxy/rpclit'>" +
"<simpleIn xsi:type='xsd:string' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
"PAYLOAD WITH XSI:TYPE" +
"</simpleIn></tns:testSimple>";
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?