Reorganized directories structure
This commit is contained in:
100
src/BeSimple/SoapClient/Tests/AxisInterop/MTOM.php
Normal file
100
src/BeSimple/SoapClient/Tests/AxisInterop/MTOM.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||
|
||||
require '../bootstrap.php';
|
||||
|
||||
class base64Binary
|
||||
{
|
||||
public $_;
|
||||
public $contentType;
|
||||
}
|
||||
|
||||
class AttachmentType
|
||||
{
|
||||
public $fileName;
|
||||
public $binaryData;
|
||||
}
|
||||
|
||||
class AttachmentRequest extends AttachmentType
|
||||
{
|
||||
}
|
||||
|
||||
class base64Binary
|
||||
{
|
||||
public $_;
|
||||
public $contentType;
|
||||
}
|
||||
|
||||
class AttachmentType
|
||||
{
|
||||
public $fileName;
|
||||
public $binaryData;
|
||||
}
|
||||
|
||||
class AttachmentRequest extends AttachmentType
|
||||
{
|
||||
}
|
||||
|
||||
class base64Binary
|
||||
{
|
||||
public $_;
|
||||
public $contentType;
|
||||
}
|
||||
|
||||
class AttachmentType
|
||||
{
|
||||
public $fileName;
|
||||
public $binaryData;
|
||||
}
|
||||
|
||||
class AttachmentRequest extends AttachmentType
|
||||
{
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'soap_version' => SOAP_1_1,
|
||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
||||
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
|
||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||
'classmap' => array(
|
||||
'base64Binary' => 'base64Binary',
|
||||
'AttachmentRequest' => 'AttachmentRequest',
|
||||
),
|
||||
);
|
||||
|
||||
/*
|
||||
* Deploy "axis_services/sample-mtom.aar" to Apache Axis2 to get this
|
||||
* example to work.
|
||||
*
|
||||
* Apache Axis2 MTOM example.
|
||||
*
|
||||
*/
|
||||
$sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
|
||||
|
||||
//var_dump($sc->__getFunctions());
|
||||
//var_dump($sc->__getTypes());
|
||||
|
||||
try {
|
||||
$b64 = new base64Binary();
|
||||
$b64->_ = 'This is a test. :)';
|
||||
$b64->contentType = 'text/plain';
|
||||
|
||||
$attachment = new AttachmentRequest();
|
||||
$attachment->fileName = 'test123.txt';
|
||||
$attachment->binaryData = $b64;
|
||||
|
||||
var_dump($sc->attachment($attachment));
|
||||
|
||||
} catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
|
||||
// var_dump(
|
||||
// $sc->__getLastRequestHeaders(),
|
||||
// $sc->__getLastRequest(),
|
||||
// $sc->__getLastResponseHeaders(),
|
||||
// $sc->__getLastResponse()
|
||||
// );
|
89
src/BeSimple/SoapClient/Tests/AxisInterop/MTOM.wsdl
Normal file
89
src/BeSimple/SoapClient/Tests/AxisInterop/MTOM.wsdl
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definitions targetNamespace="http://ws.apache.org/axis2/mtomsample/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.apache.org/axis2/mtomsample/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
|
||||
<types>
|
||||
<xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.apache.org/axis2/mtomsample/" xmlns="http://schemas.xmlsoap.org/wsdl/">
|
||||
<xsd:import namespace="http://www.w3.org/2005/05/xmlmime"/>
|
||||
<xsd:complexType name="AttachmentType">
|
||||
<xsd:sequence>
|
||||
<xsd:element minOccurs="0" name="fileName" type="xsd:string"/>
|
||||
<xsd:element minOccurs="0" name="binaryData" type="xmime:base64Binary"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:element name="AttachmentRequest" type="tns:AttachmentType"/>
|
||||
<xsd:element name="AttachmentResponse" type="xsd:string"/>
|
||||
</xsd:schema>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://www.w3.org/2005/05/xmlmime">
|
||||
<xs:attribute name="contentType">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:minLength value="3"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="expectedContentTypes" type="xs:string"/>
|
||||
<xs:complexType name="base64Binary">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:base64Binary">
|
||||
<xs:attribute ref="xmime:contentType"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="hexBinary">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:hexBinary">
|
||||
<xs:attribute ref="xmime:contentType"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
|
||||
</types>
|
||||
<message name="AttachmentResponse">
|
||||
<part name="part1" element="tns:AttachmentResponse">
|
||||
</part>
|
||||
</message>
|
||||
<message name="AttachmentRequest">
|
||||
<part name="part1" element="tns:AttachmentRequest">
|
||||
</part>
|
||||
</message>
|
||||
<portType name="MTOMServicePortType">
|
||||
<operation name="attachment">
|
||||
<input message="tns:AttachmentRequest" wsaw:Action="attachment">
|
||||
</input>
|
||||
<output message="tns:AttachmentResponse" wsaw:Action="http://schemas.xmlsoap.org/wsdl/MTOMServicePortType/AttachmentResponse">
|
||||
</output>
|
||||
</operation>
|
||||
</portType>
|
||||
<binding name="MTOMServiceSOAP11Binding" type="tns:MTOMServicePortType">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<operation name="attachment">
|
||||
<soap:operation soapAction="attachment" style="document"/>
|
||||
<input>
|
||||
<soap:body use="literal"/>
|
||||
</input>
|
||||
<output>
|
||||
<soap:body use="literal"/>
|
||||
</output>
|
||||
</operation>
|
||||
</binding>
|
||||
<binding name="MTOMServiceSOAP12Binding" type="tns:MTOMServicePortType">
|
||||
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<operation name="attachment">
|
||||
<soap12:operation soapAction="attachment" style="document"/>
|
||||
<input>
|
||||
<soap12:body use="literal"/>
|
||||
</input>
|
||||
<output>
|
||||
<soap12:body use="literal"/>
|
||||
</output>
|
||||
</operation>
|
||||
</binding>
|
||||
<service name="MTOMSample">
|
||||
<port name="MTOMSampleSOAP12port_http" binding="tns:MTOMServiceSOAP12Binding">
|
||||
<soap12:address location="http://localhost:8080/axis2/services/MTOMSample.MTOMSampleSOAP12port_http/"/>
|
||||
</port>
|
||||
<port name="MTOMSampleSOAP11port_http" binding="tns:MTOMServiceSOAP11Binding">
|
||||
<soap:address location="http://localhost:8080/axis2/services/MTOMSample.MTOMSampleSOAP11port_http/"/>
|
||||
</port>
|
||||
</service>
|
||||
</definitions>
|
84
src/BeSimple/SoapClient/Tests/AxisInterop/SwA.php
Normal file
84
src/BeSimple/SoapClient/Tests/AxisInterop/SwA.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||
|
||||
require '../bootstrap.php';
|
||||
|
||||
$options = array(
|
||||
'soap_version' => SOAP_1_1,
|
||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
||||
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_SWA,
|
||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||
);
|
||||
|
||||
/*
|
||||
* Deploy "axis_services/besimple-swa.aar" to Apache Axis2 to get this
|
||||
* example to work.
|
||||
*
|
||||
* Run ant to rebuild aar.
|
||||
*
|
||||
* Example based on:
|
||||
* http://axis.apache.org/axis2/java/core/docs/mtom-guide.html#a3
|
||||
* http://wso2.org/library/1675
|
||||
*
|
||||
* Doesn't work directly with ?wsdl served by Apache Axis!
|
||||
*
|
||||
*/
|
||||
|
||||
$sc = new BeSimpleSoapClient('SwA.wsdl', $options);
|
||||
|
||||
//var_dump($sc->__getFunctions());
|
||||
//var_dump($sc->__getTypes());
|
||||
|
||||
try {
|
||||
$file = new stdClass();
|
||||
$file->name = 'upload.txt';
|
||||
$file->data = 'This is a test text!';
|
||||
$result = $sc->uploadFile($file);
|
||||
|
||||
var_dump(
|
||||
$result->return
|
||||
);
|
||||
|
||||
$file = new stdClass();
|
||||
$file->name = 'upload.txt';
|
||||
$result = $sc->downloadFile($file);
|
||||
|
||||
var_dump(
|
||||
$result->data
|
||||
);
|
||||
|
||||
$file = new stdClass();
|
||||
$file->name = 'image.jpg'; // source: http://www.freeimageslive.com/galleries/light/pics/swirl3768.jpg
|
||||
$file->data = file_get_contents('image.jpg');
|
||||
$result = $sc->uploadFile($file);
|
||||
|
||||
var_dump(
|
||||
$result->return
|
||||
);
|
||||
|
||||
$crc32 = crc32($file->data);
|
||||
|
||||
$file = new stdClass();
|
||||
$file->name = 'image.jpg';
|
||||
$result = $sc->downloadFile($file);
|
||||
|
||||
file_put_contents('image2.jpg', $result->data);
|
||||
|
||||
|
||||
var_dump(
|
||||
crc32($result->data) === $crc32
|
||||
);
|
||||
|
||||
} catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
|
||||
// var_dump(
|
||||
// $sc->__getLastRequestHeaders(),
|
||||
// $sc->__getLastRequest(),
|
||||
// $sc->__getLastResponseHeaders(),
|
||||
// $sc->__getLastResponse()
|
||||
// );
|
162
src/BeSimple/SoapClient/Tests/AxisInterop/SwA.wsdl
Normal file
162
src/BeSimple/SoapClient/Tests/AxisInterop/SwA.wsdl
Normal file
@ -0,0 +1,162 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://service.besimple" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://service.besimple">
|
||||
<wsdl:documentation>BeSimpleSwaService</wsdl:documentation>
|
||||
<wsdl:types>
|
||||
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.besimple">
|
||||
<xs:complexType name="Exception">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:element name="Exception">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="Exception" nillable="true" type="ns:Exception"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="uploadFile">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="data" nillable="true" type="xs:base64Binary"/>
|
||||
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="uploadFileResponse">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="downloadFile">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="downloadFileResponse">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="data" nillable="true" type="xs:base64Binary"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="downloadFileRequest">
|
||||
<wsdl:part name="parameters" element="ns:downloadFile"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="downloadFileResponse">
|
||||
<wsdl:part name="parameters" element="ns:downloadFileResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="Exception">
|
||||
<wsdl:part name="parameters" element="ns:Exception"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="uploadFileRequest">
|
||||
<wsdl:part name="parameters" element="ns:uploadFile"/>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="uploadFileResponse">
|
||||
<wsdl:part name="parameters" element="ns:uploadFileResponse"/>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="BeSimpleSwaServicePortType">
|
||||
<wsdl:operation name="downloadFile">
|
||||
<wsdl:input message="ns:downloadFileRequest" wsaw:Action="urn:downloadFile"/>
|
||||
<wsdl:output message="ns:downloadFileResponse" wsaw:Action="urn:downloadFileResponse"/>
|
||||
<wsdl:fault message="ns:Exception" name="Exception" wsaw:Action="urn:downloadFileException"/>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="uploadFile">
|
||||
<wsdl:input message="ns:uploadFileRequest" wsaw:Action="urn:uploadFile"/>
|
||||
<wsdl:output message="ns:uploadFileResponse" wsaw:Action="urn:uploadFileResponse"/>
|
||||
<wsdl:fault message="ns:Exception" name="Exception" wsaw:Action="urn:uploadFileException"/>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="BeSimpleSwaServiceSoap11Binding" type="ns:BeSimpleSwaServicePortType">
|
||||
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
|
||||
<wsdl:operation name="downloadFile">
|
||||
<soap:operation soapAction="urn:downloadFile" style="document"/>
|
||||
<wsdl:input>
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="Exception">
|
||||
<soap:fault use="literal" name="Exception"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="uploadFile">
|
||||
<soap:operation soapAction="urn:uploadFile" style="document"/>
|
||||
<wsdl:input>
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="Exception">
|
||||
<soap:fault use="literal" name="Exception"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:binding name="BeSimpleSwaServiceSoap12Binding" type="ns:BeSimpleSwaServicePortType">
|
||||
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
|
||||
<wsdl:operation name="downloadFile">
|
||||
<soap12:operation soapAction="urn:downloadFile" style="document"/>
|
||||
<wsdl:input>
|
||||
<soap12:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<soap12:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="Exception">
|
||||
<soap12:fault use="literal" name="Exception"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="uploadFile">
|
||||
<soap12:operation soapAction="urn:uploadFile" style="document"/>
|
||||
<wsdl:input>
|
||||
<soap12:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<soap12:body use="literal"/>
|
||||
</wsdl:output>
|
||||
<wsdl:fault name="Exception">
|
||||
<soap12:fault use="literal" name="Exception"/>
|
||||
</wsdl:fault>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:binding name="BeSimpleSwaServiceHttpBinding" type="ns:BeSimpleSwaServicePortType">
|
||||
<http:binding verb="POST"/>
|
||||
<wsdl:operation name="downloadFile">
|
||||
<http:operation location="BeSimpleSwaService/downloadFile"/>
|
||||
<wsdl:input>
|
||||
<mime:content type="text/xml" part="downloadFile"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<mime:content type="text/xml" part="downloadFile"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="uploadFile">
|
||||
<http:operation location="BeSimpleSwaService/uploadFile"/>
|
||||
<wsdl:input>
|
||||
<mime:content type="text/xml" part="uploadFile"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output>
|
||||
<mime:content type="text/xml" part="uploadFile"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="BeSimpleSwaService">
|
||||
<wsdl:port name="BeSimpleSwaServiceHttpSoap11Endpoint" binding="ns:BeSimpleSwaServiceSoap11Binding">
|
||||
<soap:address location="http://localhost:8080/axis2/services/BeSimpleSwaService.BeSimpleSwaServiceHttpSoap11Endpoint/"/>
|
||||
</wsdl:port>
|
||||
<wsdl:port name="BeSimpleSwaServiceHttpSoap12Endpoint" binding="ns:BeSimpleSwaServiceSoap12Binding">
|
||||
<soap12:address location="http://localhost:8080/axis2/services/BeSimpleSwaService.BeSimpleSwaServiceHttpSoap12Endpoint/"/>
|
||||
</wsdl:port>
|
||||
<wsdl:port name="BeSimpleSwaServiceHttpEndpoint" binding="ns:BeSimpleSwaServiceHttpBinding">
|
||||
<http:address location="http://localhost:8080/axis2/services/BeSimpleSwaService.BeSimpleSwaServiceHttpEndpoint/"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
38
src/BeSimple/SoapClient/Tests/AxisInterop/SwA/build.xml
Normal file
38
src/BeSimple/SoapClient/Tests/AxisInterop/SwA/build.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<project name="BeSimpleSwaService" default="generate.service">
|
||||
<property environment="env" />
|
||||
<property name="axis2.home" value="C:/axis2" />
|
||||
<property name="axis2.repo" value="${axis2.home}/repository" />
|
||||
<property name="build.dir" value="build" />
|
||||
<property name="filename" value="besimple-swa.aar" />
|
||||
|
||||
<path id="axis.classpath">
|
||||
<fileset dir="${axis2.home}/lib">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<target name="generate.service" depends="compile">
|
||||
<jar destfile="${build.dir}/${filename}">
|
||||
<fileset dir="resources/">
|
||||
<include name="META-INF/services.xml" />
|
||||
</fileset>
|
||||
<fileset dir="${build.dir}/classes">
|
||||
<include name="besimple/service/**/*.class" />
|
||||
</fileset>
|
||||
</jar>
|
||||
<copy file="${build.dir}/${filename}" tofile="../axis_services/${filename}" overwrite="true" />
|
||||
<copy file="${build.dir}/${filename}" tofile="${axis2.repo}/services/${filename}" overwrite="true" />
|
||||
<antcall target="clean" />
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="${build.dir}/classes" />
|
||||
<javac debug="on" srcdir="src" destdir="${build.dir}/classes">
|
||||
<classpath refid="axis.classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}" />
|
||||
</target>
|
||||
</project>
|
@ -0,0 +1,15 @@
|
||||
<serviceGroup>
|
||||
<service name="BeSimpleSwaService">
|
||||
<description>BeSimple test service for SwA.</description>
|
||||
<parameter name="enableSwA">true</parameter>
|
||||
<parameter name="ServiceClass" locked="false">besimple.service.BeSimpleSwaService</parameter>
|
||||
<operation name="uploadFile">
|
||||
<actionMapping>urn:uploadFile</actionMapping>
|
||||
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
|
||||
</operation>
|
||||
<operation name="downloadFile">
|
||||
<actionMapping>urn:downloadFile</actionMapping>
|
||||
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
|
||||
</operation>
|
||||
</service>
|
||||
</serviceGroup>
|
@ -0,0 +1,78 @@
|
||||
package besimple.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
|
||||
import org.apache.axiom.attachments.Attachments;
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.om.OMAttribute;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMFactory;
|
||||
import org.apache.axiom.om.OMNamespace;
|
||||
|
||||
import org.apache.axis2.context.MessageContext;
|
||||
import org.apache.axis2.context.OperationContext;
|
||||
import org.apache.axis2.wsdl.WSDLConstants;
|
||||
|
||||
public class BeSimpleSwaService {
|
||||
|
||||
String namespace = "http://service.besimple";
|
||||
|
||||
public OMElement uploadFile(OMElement element) throws Exception {
|
||||
OMElement dataElement = (OMElement)element.getFirstChildWithName(new QName(namespace, "data"));
|
||||
OMAttribute hrefAttribute = dataElement.getAttribute(new QName("href"));
|
||||
|
||||
String contentID = hrefAttribute.getAttributeValue();
|
||||
contentID = contentID.trim();
|
||||
if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
|
||||
contentID = contentID.substring(4);
|
||||
}
|
||||
OMElement nameElement = (OMElement)element.getFirstChildWithName(new QName(namespace, "name"));
|
||||
String name = nameElement.getText();
|
||||
|
||||
MessageContext msgCtx = MessageContext.getCurrentMessageContext();
|
||||
Attachments attachment = msgCtx.getAttachmentMap();
|
||||
DataHandler dataHandler = attachment.getDataHandler(contentID);
|
||||
|
||||
File file = new File(name);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
dataHandler.writeTo(fileOutputStream);
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
|
||||
OMFactory factory = OMAbstractFactory.getOMFactory();
|
||||
OMNamespace omNs = factory.createOMNamespace(namespace, "swa");
|
||||
OMElement wrapperElement = factory.createOMElement("uploadFileResponse", omNs);
|
||||
OMElement returnElement = factory.createOMElement("return", omNs, wrapperElement);
|
||||
returnElement.setText("File saved succesfully.");
|
||||
|
||||
return wrapperElement;
|
||||
}
|
||||
|
||||
public OMElement downloadFile(OMElement element) throws Exception {
|
||||
OMElement nameElement = (OMElement)element.getFirstChildWithName(new QName(namespace, "name"));
|
||||
String name = nameElement.getText();
|
||||
|
||||
MessageContext msgCtxIn = MessageContext.getCurrentMessageContext();
|
||||
OperationContext operationContext = msgCtxIn.getOperationContext();
|
||||
MessageContext msgCtxOut = operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
|
||||
|
||||
FileDataSource fileDataSource = new FileDataSource(name);
|
||||
DataHandler dataHandler = new DataHandler(fileDataSource);
|
||||
|
||||
String contentID = "cid:" + msgCtxOut.addAttachment(dataHandler);
|
||||
|
||||
OMFactory factory = OMAbstractFactory.getOMFactory();
|
||||
OMNamespace omNs = factory.createOMNamespace(namespace, "swa");
|
||||
OMElement wrapperElement = factory.createOMElement("downloadFileResponse", omNs);
|
||||
OMElement dataElement = factory.createOMElement("data", omNs, wrapperElement);
|
||||
dataElement.addAttribute("href", contentID, null);
|
||||
|
||||
return wrapperElement;
|
||||
}
|
||||
}
|
73
src/BeSimple/SoapClient/Tests/AxisInterop/WsAddressing.php
Normal file
73
src/BeSimple/SoapClient/Tests/AxisInterop/WsAddressing.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||
use BeSimple\SoapClient\WsAddressingFilter as BeSimpleWsAddressingFilter;
|
||||
|
||||
require '../bootstrap.php';
|
||||
|
||||
$options = array(
|
||||
'soap_version' => SOAP_1_2,
|
||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
||||
);
|
||||
|
||||
/*
|
||||
* Deploy "axis_services/version2.aar" to Apache Axis2 to get this example to
|
||||
* work.
|
||||
*
|
||||
* To rebuild the "axis_services/version2.aar" the following steps need to be
|
||||
* done to build a working Apache Axis2 version service with SOAP session
|
||||
* enabled.
|
||||
*
|
||||
* 1) Go to $AXIS_HOME/samples/version and edit the following files:
|
||||
*
|
||||
* resources/META-INF/services.xml:
|
||||
* <service name="Version2" scope="soapsession">
|
||||
* ...
|
||||
* </service>
|
||||
*
|
||||
* build.xml:
|
||||
* replace version.aar with version2.aar
|
||||
*
|
||||
* 2) Run ant build.xml in "$AXIS_HOME/samples/version"
|
||||
*
|
||||
*/
|
||||
|
||||
$sc = new BeSimpleSoapClient('http://localhost:8080/axis2/services/Version2?wsdl', $options);
|
||||
$soapKernel = $sc->getSoapKernel();
|
||||
$wsaFilter = new BeSimpleWsAddressingFilter();
|
||||
$soapKernel->registerFilter($wsaFilter);
|
||||
|
||||
//var_dump($sc->__getFunctions());
|
||||
//var_dump($sc->__getTypes());
|
||||
|
||||
try {
|
||||
$wsaFilter->setReplyTo(BeSimpleWsAddressingFilter::ENDPOINT_REFERENCE_ANONYMOUS);
|
||||
$wsaFilter->setMessageId();
|
||||
|
||||
var_dump($sc->getVersion());
|
||||
|
||||
$soapSessionId1 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId');
|
||||
echo 'ID1: ' .$soapSessionId1 . PHP_EOL;
|
||||
|
||||
$wsaFilter->addReferenceParameter('http://ws.apache.org/namespaces/axis2', 'axis2', 'ServiceGroupId', $soapSessionId1);
|
||||
|
||||
var_dump($sc->getVersion());
|
||||
|
||||
$soapSessionId2 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId');
|
||||
echo 'ID2: ' . $soapSessionId2 . PHP_EOL;
|
||||
|
||||
if ($soapSessionId1 == $soapSessionId2) {
|
||||
echo PHP_EOL;
|
||||
echo 'SOAP session worked :)';
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
|
||||
// var_dump(
|
||||
// $sc->__getLastRequestHeaders(),
|
||||
// $sc->__getLastRequest(),
|
||||
// $sc->__getLastResponseHeaders(),
|
||||
// $sc->__getLastResponse()
|
||||
// );
|
116
src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEnc.php
Normal file
116
src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEnc.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
use ass\XmlSecurity\Key as XmlSecurityKey;
|
||||
|
||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||
use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
|
||||
use BeSimple\SoapCommon\WsSecurityKey as BeSimpleWsSecurityKey;
|
||||
|
||||
require '../bootstrap.php';
|
||||
|
||||
echo '<pre>';
|
||||
|
||||
$options = array(
|
||||
'soap_version' => SOAP_1_2,
|
||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
||||
);
|
||||
|
||||
/*
|
||||
* Deploy "axis_services/library-signencr.aar" to Apache Axis2 to get this
|
||||
* example to work.
|
||||
*
|
||||
* Links:
|
||||
* http://www.dcc.uchile.cl/~pcamacho/tutorial/web/xmlsec/xmlsec.html
|
||||
* http://www.aleksey.com/xmlsec/xmldsig-verifier.html
|
||||
*
|
||||
* Using code from axis example:
|
||||
* http://www.ibm.com/developerworks/java/library/j-jws5/index.html
|
||||
*
|
||||
* Download key tool to export private key
|
||||
* http://couchpotato.net/pkeytool/
|
||||
*
|
||||
* keytool -export -alias serverkey -keystore server.keystore -storepass nosecret -file servercert.cer
|
||||
* openssl x509 -out servercert.pem -outform pem -in servercert.pem -inform der
|
||||
*
|
||||
* keytool -export -alias clientkey -keystore client.keystore -storepass nosecret -file clientcert.cer
|
||||
* openssl x509 -out clientcert.pem -outform pem -in clientcert.pem -inform der
|
||||
* java -jar pkeytool.jar -exportkey -keystore client.keystore -storepass nosecret -keypass clientpass -rfc -alias clientkey -file clientkey.pem
|
||||
*
|
||||
* C:\Program Files\Java\jre6\bin\keytool -export -alias serverkey -keystore server.keystore -storepass nosecret -file servercert.cer
|
||||
* C:\xampp\apache\bin\openssl x509 -out servercert.pem -outform pem -in servercert.cer -inform der
|
||||
*
|
||||
* C:\Program Files\Java\jre6\bin\keytool -export -alias clientkey -keystore client.keystore -storepass nosecret -file clientcert.cer
|
||||
* C:\xampp\apache\bin\openssl x509 -out clientcert.pem -outform pem -in clientcert.cer -inform der
|
||||
* java -jar C:\axis2\pkeytool\pkeytool.jar -exportkey -keystore client.keystore -storepass nosecret -keypass clientpass -rfc -alias clientkey -file clientkey.pem
|
||||
*
|
||||
* build.properties:
|
||||
* server-policy=hash-policy-server.xml
|
||||
*
|
||||
* allows both text and digest!
|
||||
*/
|
||||
|
||||
class getBook {}
|
||||
class getBookResponse {}
|
||||
class getBooksByType {}
|
||||
class getBooksByTypeResponse {}
|
||||
class addBook {}
|
||||
class addBookResponse {}
|
||||
class BookInformation {}
|
||||
|
||||
$options['classmap'] = array(
|
||||
'getBook' => 'getBook',
|
||||
'getBookResponse' => 'getBookResponse',
|
||||
'getBooksByType' => 'getBooksByType',
|
||||
'getBooksByTypeResponse' => 'getBooksByTypeResponse',
|
||||
'addBook' => 'addBook',
|
||||
'addBookResponse' => 'addBookResponse',
|
||||
'BookInformation' => 'BookInformation',
|
||||
);
|
||||
|
||||
$sc = new BeSimpleSoapClient('WsSecuritySigEnc.wsdl', $options);
|
||||
|
||||
$wssFilter = new BeSimpleWsSecurityFilter();
|
||||
// user key for signature and encryption
|
||||
$securityKeyUser = new BeSimpleWsSecurityKey();
|
||||
$securityKeyUser->addPrivateKey(XmlSecurityKey::RSA_SHA1, 'clientkey.pem', true);
|
||||
$securityKeyUser->addPublicKey(XmlSecurityKey::RSA_SHA1, 'clientcert.pem', true);
|
||||
$wssFilter->setUserSecurityKeyObject($securityKeyUser);
|
||||
// service key for encryption
|
||||
$securityKeyService = new BeSimpleWsSecurityKey();
|
||||
$securityKeyService->addPrivateKey(XmlSecurityKey::TRIPLEDES_CBC);
|
||||
$securityKeyService->addPublicKey(XmlSecurityKey::RSA_1_5, 'servercert.pem', true);
|
||||
$wssFilter->setServiceSecurityKeyObject($securityKeyService);
|
||||
// TOKEN_REFERENCE_SUBJECT_KEY_IDENTIFIER | TOKEN_REFERENCE_SECURITY_TOKEN | TOKEN_REFERENCE_THUMBPRINT_SHA1
|
||||
$wssFilter->setSecurityOptionsSignature(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_SECURITY_TOKEN);
|
||||
$wssFilter->setSecurityOptionsEncryption(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_THUMBPRINT_SHA1);
|
||||
|
||||
$soapKernel = $sc->getSoapKernel();
|
||||
$soapKernel->registerFilter($wssFilter);
|
||||
|
||||
//var_dump($sc->__getFunctions());
|
||||
//var_dump($sc->__getTypes());
|
||||
|
||||
try {
|
||||
$gb = new getBook();
|
||||
$gb->isbn = '0061020052';
|
||||
var_dump($sc->getBook($gb));
|
||||
|
||||
$ab = new addBook();
|
||||
$ab->isbn = '0445203498';
|
||||
$ab->title = 'The Dragon Never Sleeps';
|
||||
$ab->author = 'Cook, Glen';
|
||||
$ab->type = 'scifi';
|
||||
var_dump($sc->addBook($ab));
|
||||
|
||||
// getBooksByType("scifi");
|
||||
} catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
|
||||
//var_dump(
|
||||
// $sc->__getLastRequestHeaders(),
|
||||
// $sc->__getLastRequest(),
|
||||
// $sc->__getLastResponseHeaders(),
|
||||
// $sc->__getLastResponse()
|
||||
//);
|
184
src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEnc.wsdl
Normal file
184
src/BeSimple/SoapClient/Tests/AxisInterop/WsSecuritySigEnc.wsdl
Normal file
@ -0,0 +1,184 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions targetNamespace="http://ws.sosnoski.com/library/wsdl"
|
||||
xmlns:wns="http://ws.sosnoski.com/library/wsdl"
|
||||
xmlns:tns="http://ws.sosnoski.com/library/types"
|
||||
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<wsdl:types>
|
||||
|
||||
<schema elementFormDefault="qualified"
|
||||
targetNamespace="http://ws.sosnoski.com/library/wsdl"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<import namespace="http://ws.sosnoski.com/library/types"/>
|
||||
|
||||
<element name="getBook">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="isbn" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="getBookResponse">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="getBookReturn" minOccurs="0" type="tns:BookInformation"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="getBooksByType">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="type" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="getBooksByTypeResponse">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="getBooksByTypeReturn" minOccurs="0" maxOccurs="unbounded" type="tns:BookInformation"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="addBook">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="type" type="string"/>
|
||||
<element name="isbn" type="string"/>
|
||||
<element name="author" minOccurs="0" maxOccurs="unbounded" type="string"/>
|
||||
<element name="title" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="addBookResponse">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="addBookReturn" type="boolean"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
</schema>
|
||||
|
||||
<schema elementFormDefault="qualified"
|
||||
targetNamespace="http://ws.sosnoski.com/library/types"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<complexType name="BookInformation">
|
||||
<sequence>
|
||||
<element name="author" minOccurs="0" maxOccurs="unbounded" type="string"/>
|
||||
<element name="title" type="string"/>
|
||||
</sequence>
|
||||
<attribute name="type" use="required" type="string"/>
|
||||
<attribute name="isbn" use="required" type="string"/>
|
||||
</complexType>
|
||||
|
||||
</schema>
|
||||
|
||||
</wsdl:types>
|
||||
|
||||
<wsdl:message name="getBookRequest">
|
||||
<wsdl:part element="wns:getBook" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="getBookResponse">
|
||||
<wsdl:part element="wns:getBookResponse" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="getBooksByTypeRequest">
|
||||
<wsdl:part element="wns:getBooksByType" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="getBooksByTypeResponse">
|
||||
<wsdl:part element="wns:getBooksByTypeResponse" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="addBookRequest">
|
||||
<wsdl:part element="wns:addBook" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="addBookResponse">
|
||||
<wsdl:part element="wns:addBookResponse" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:portType name="Library">
|
||||
|
||||
<wsdl:operation name="getBook">
|
||||
<wsdl:input message="wns:getBookRequest" name="getBookRequest"/>
|
||||
<wsdl:output message="wns:getBookResponse" name="getBookResponse"/>
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="getBooksByType">
|
||||
<wsdl:input message="wns:getBooksByTypeRequest" name="getBooksByTypeRequest"/>
|
||||
<wsdl:output message="wns:getBooksByTypeResponse" name="getBooksByTypeResponse"/>
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="addBook">
|
||||
<wsdl:input message="wns:addBookRequest" name="addBookRequest"/>
|
||||
<wsdl:output message="wns:addBookResponse" name="addBookResponse"/>
|
||||
</wsdl:operation>
|
||||
|
||||
</wsdl:portType>
|
||||
|
||||
<wsdl:binding name="LibrarySoapBinding" type="wns:Library">
|
||||
|
||||
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
|
||||
<wsdl:operation name="getBook">
|
||||
|
||||
<wsdlsoap:operation soapAction="urn:getBook"/>
|
||||
|
||||
<wsdl:input name="getBookRequest">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
|
||||
<wsdl:output name="getBookResponse">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="getBooksByType">
|
||||
|
||||
<wsdlsoap:operation soapAction="urn:getBooksByType"/>
|
||||
|
||||
<wsdl:input name="getBooksByTypeRequest">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
|
||||
<wsdl:output name="getBooksByTypeResponse">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="addBook">
|
||||
|
||||
<wsdlsoap:operation soapAction="urn:addBook"/>
|
||||
|
||||
<wsdl:input name="addBookRequest">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
|
||||
<wsdl:output name="addBookResponse">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
|
||||
</wsdl:operation>
|
||||
|
||||
</wsdl:binding>
|
||||
|
||||
<wsdl:service name="library-signencr">
|
||||
|
||||
<wsdl:port binding="wns:LibrarySoapBinding" name="library">
|
||||
<wsdlsoap:address location="http://localhost:8080/axis2/services/library-signencr"/>
|
||||
</wsdl:port>
|
||||
|
||||
</wsdl:service>
|
||||
|
||||
</wsdl:definitions>
|
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||
use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
|
||||
|
||||
require '../bootstrap.php';
|
||||
|
||||
$options = array(
|
||||
'soap_version' => SOAP_1_2,
|
||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
||||
);
|
||||
|
||||
/*
|
||||
* Deploy "axis_services/library-username-digest.aar" to Apache Axis2 to get
|
||||
* this example to work.
|
||||
*
|
||||
* Using code from axis example:
|
||||
* http://www.ibm.com/developerworks/java/library/j-jws4/index.html
|
||||
*
|
||||
* build.properties:
|
||||
* server-policy=hash-policy-server.xml
|
||||
*
|
||||
* allows both text and digest!
|
||||
*/
|
||||
|
||||
class getBook {}
|
||||
class getBookResponse {}
|
||||
class getBooksByType {}
|
||||
class getBooksByTypeResponse {}
|
||||
class addBook {}
|
||||
class addBookResponse {}
|
||||
class BookInformation {}
|
||||
|
||||
$options['classmap'] = array(
|
||||
'getBook' => 'getBook',
|
||||
'getBookResponse' => 'getBookResponse',
|
||||
'getBooksByType' => 'getBooksByType',
|
||||
'getBooksByTypeResponse' => 'getBooksByTypeResponse',
|
||||
'addBook' => 'addBook',
|
||||
'addBookResponse' => 'addBookResponse',
|
||||
'BookInformation' => 'BookInformation',
|
||||
);
|
||||
|
||||
$sc = new BeSimpleSoapClient('WsSecurityUserPass.wsdl', $options);
|
||||
|
||||
$wssFilter = new BeSimpleWsSecurityFilter(true, 600);
|
||||
$wssFilter->addUserData('libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_TEXT);
|
||||
//$wssFilter->addUserData( 'libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_DIGEST );
|
||||
|
||||
$soapKernel = $sc->getSoapKernel();
|
||||
$soapKernel->registerFilter($wssFilter);
|
||||
|
||||
//var_dump($sc->__getFunctions());
|
||||
//var_dump($sc->__getTypes());
|
||||
|
||||
try {
|
||||
$gb = new getBook();
|
||||
$gb->isbn = '0061020052';
|
||||
var_dump($sc->getBook($gb));
|
||||
|
||||
$ab = new addBook();
|
||||
$ab->isbn = '0445203498';
|
||||
$ab->title = 'The Dragon Never Sleeps';
|
||||
$ab->author = 'Cook, Glen';
|
||||
$ab->type = 'scifi';
|
||||
var_dump($sc->addBook($ab));
|
||||
|
||||
// getBooksByType("scifi");
|
||||
} catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
|
||||
//var_dump(
|
||||
// $sc->__getLastRequestHeaders(),
|
||||
// $sc->__getLastRequest(),
|
||||
// $sc->__getLastResponseHeaders(),
|
||||
// $sc->__getLastResponse()
|
||||
//);
|
@ -0,0 +1,184 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions targetNamespace="http://ws.sosnoski.com/library/wsdl"
|
||||
xmlns:wns="http://ws.sosnoski.com/library/wsdl"
|
||||
xmlns:tns="http://ws.sosnoski.com/library/types"
|
||||
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/">
|
||||
<wsdl:types>
|
||||
|
||||
<schema elementFormDefault="qualified"
|
||||
targetNamespace="http://ws.sosnoski.com/library/wsdl"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<import namespace="http://ws.sosnoski.com/library/types"/>
|
||||
|
||||
<element name="getBook">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="isbn" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="getBookResponse">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="getBookReturn" minOccurs="0" type="tns:BookInformation"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="getBooksByType">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="type" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="getBooksByTypeResponse">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="getBooksByTypeReturn" minOccurs="0" maxOccurs="unbounded" type="tns:BookInformation"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="addBook">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="type" type="string"/>
|
||||
<element name="isbn" type="string"/>
|
||||
<element name="author" minOccurs="0" maxOccurs="unbounded" type="string"/>
|
||||
<element name="title" type="string"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="addBookResponse">
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element name="addBookReturn" type="boolean"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
</schema>
|
||||
|
||||
<schema elementFormDefault="qualified"
|
||||
targetNamespace="http://ws.sosnoski.com/library/types"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<complexType name="BookInformation">
|
||||
<sequence>
|
||||
<element name="author" minOccurs="0" maxOccurs="unbounded" type="string"/>
|
||||
<element name="title" type="string"/>
|
||||
</sequence>
|
||||
<attribute name="type" use="required" type="string"/>
|
||||
<attribute name="isbn" use="required" type="string"/>
|
||||
</complexType>
|
||||
|
||||
</schema>
|
||||
|
||||
</wsdl:types>
|
||||
|
||||
<wsdl:message name="getBookRequest">
|
||||
<wsdl:part element="wns:getBook" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="getBookResponse">
|
||||
<wsdl:part element="wns:getBookResponse" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="getBooksByTypeRequest">
|
||||
<wsdl:part element="wns:getBooksByType" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="getBooksByTypeResponse">
|
||||
<wsdl:part element="wns:getBooksByTypeResponse" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="addBookRequest">
|
||||
<wsdl:part element="wns:addBook" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:message name="addBookResponse">
|
||||
<wsdl:part element="wns:addBookResponse" name="parameters"/>
|
||||
</wsdl:message>
|
||||
|
||||
<wsdl:portType name="Library">
|
||||
|
||||
<wsdl:operation name="getBook">
|
||||
<wsdl:input message="wns:getBookRequest" name="getBookRequest"/>
|
||||
<wsdl:output message="wns:getBookResponse" name="getBookResponse"/>
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="getBooksByType">
|
||||
<wsdl:input message="wns:getBooksByTypeRequest" name="getBooksByTypeRequest"/>
|
||||
<wsdl:output message="wns:getBooksByTypeResponse" name="getBooksByTypeResponse"/>
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="addBook">
|
||||
<wsdl:input message="wns:addBookRequest" name="addBookRequest"/>
|
||||
<wsdl:output message="wns:addBookResponse" name="addBookResponse"/>
|
||||
</wsdl:operation>
|
||||
|
||||
</wsdl:portType>
|
||||
|
||||
<wsdl:binding name="LibrarySoapBinding" type="wns:Library">
|
||||
|
||||
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
|
||||
<wsdl:operation name="getBook">
|
||||
|
||||
<wsdlsoap:operation soapAction="urn:getBook"/>
|
||||
|
||||
<wsdl:input name="getBookRequest">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
|
||||
<wsdl:output name="getBookResponse">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="getBooksByType">
|
||||
|
||||
<wsdlsoap:operation soapAction="urn:getBooksByType"/>
|
||||
|
||||
<wsdl:input name="getBooksByTypeRequest">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
|
||||
<wsdl:output name="getBooksByTypeResponse">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
|
||||
</wsdl:operation>
|
||||
|
||||
<wsdl:operation name="addBook">
|
||||
|
||||
<wsdlsoap:operation soapAction="urn:addBook"/>
|
||||
|
||||
<wsdl:input name="addBookRequest">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
|
||||
<wsdl:output name="addBookResponse">
|
||||
<wsdlsoap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
|
||||
</wsdl:operation>
|
||||
|
||||
</wsdl:binding>
|
||||
|
||||
<wsdl:service name="library-username">
|
||||
|
||||
<wsdl:port binding="wns:LibrarySoapBinding" name="library">
|
||||
<wsdlsoap:address location="http://localhost:8080/axis2/services/library-username"/>
|
||||
</wsdl:port>
|
||||
|
||||
</wsdl:service>
|
||||
|
||||
</wsdl:definitions>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
src/BeSimple/SoapClient/Tests/AxisInterop/clientcert.pem
Normal file
17
src/BeSimple/SoapClient/Tests/AxisInterop/clientcert.pem
Normal file
@ -0,0 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICoDCCAgkCBEnhw2IwDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNVBAYTAk5aMRMw
|
||||
EQYDVQQIEwpXZWxsaW5ndG9uMRowGAYDVQQHExFQYXJhcGFyYXVtdSBCZWFjaDEq
|
||||
MCgGA1UEChMhU29zbm9za2kgU29mdHdhcmUgQXNzb2NpYXRlcyBMdGQuMRAwDgYD
|
||||
VQQLEwdVbmtub3duMRgwFgYDVQQDEw9EZW5uaXMgU29zbm9za2kwHhcNMDkwNDEy
|
||||
MTAzMzA2WhcNMzYwODI3MTAzMzA2WjCBljELMAkGA1UEBhMCTloxEzARBgNVBAgT
|
||||
CldlbGxpbmd0b24xGjAYBgNVBAcTEVBhcmFwYXJhdW11IEJlYWNoMSowKAYDVQQK
|
||||
EyFTb3Nub3NraSBTb2Z0d2FyZSBBc3NvY2lhdGVzIEx0ZC4xEDAOBgNVBAsTB1Vu
|
||||
a25vd24xGDAWBgNVBAMTD0Rlbm5pcyBTb3Nub3NraTCBnzANBgkqhkiG9w0BAQEF
|
||||
AAOBjQAwgYkCgYEAhOVyNK8xyxtb4DnKtU6mF9KoiFqCk7eKoLE26+9h410CtTkx
|
||||
zWAfgnR+8i+LPbdsPY+yXAo6NYpCCKolXfDLe+AG2GwnMZGrIl6+BLF3hqTmIXBF
|
||||
TLGUmC7A7uBTivaWgdH1w3hb33rASoVU67BVtQ3QQi99juZX4vU9o9pScocCAwEA
|
||||
ATANBgkqhkiG9w0BAQUFAAOBgQBMNPo1KAGbz8Jl6HGbtAcetieSJ3bEAXmv1tcj
|
||||
ysBS67AXzdu1Ac+onHh2EpzBM7kuGbw+trU+AhulooPpewIQRApXP1F0KHRDcbqW
|
||||
jwvknS6HnomN9572giLGKn2601bHiRUj35hiA8aLmMUBppIRPFFAoQ0QUBCPx+m8
|
||||
/0n33w==
|
||||
-----END CERTIFICATE-----
|
14
src/BeSimple/SoapClient/Tests/AxisInterop/clientkey.pem
Normal file
14
src/BeSimple/SoapClient/Tests/AxisInterop/clientkey.pem
Normal file
@ -0,0 +1,14 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAITlcjSvMcsbW+A5yrVOphfSqIha
|
||||
gpO3iqCxNuvvYeNdArU5Mc1gH4J0fvIviz23bD2PslwKOjWKQgiqJV3wy3vgBthsJzGRqyJevgSx
|
||||
d4ak5iFwRUyxlJguwO7gU4r2loHR9cN4W996wEqFVOuwVbUN0EIvfY7mV+L1PaPaUnKHAgMBAAEC
|
||||
gYAZ6UqtLwN8YGc3fs0hMKZ9upsViuAuwPiMgED/G3twgzAF+ZLWQkmie+hMfCyf6eV200+pVm0n
|
||||
Bz/8xH/oowxpX0Kk3szoB4vFghjU84GKUcrbhu/NRIm7l3drnfbzqhQkHDCx6n1CotI4Gs49cDWu
|
||||
4uEAuxJkEIVY553unZjZgQJBAOJVIallNKmD0iQlvtWRmRzpmYDjt9vhNY6WBTIOx6SDn9SRaoSA
|
||||
fkipQ2HXo04r78TQ674+zfZ1lRTkFG7px6ECQQCWUPHp3pSZOM1oGzJrNvNaw+MizZAZjq34npHm
|
||||
9GRquFLG7BlCaI9QNGE7pN2ryYsYCRUMaM2e4GR0tUXxVGknAkAgrxqFU9AfCqI2Bh1gyf3KZxF7
|
||||
w2axofwR8ygc6nV6FGfoUneHWubhp0/LuVAj4cRmL6Vbe8ZSaPh2Y9lviuMBAkEAicP8Q+1E4j1m
|
||||
PPEYP51oYprANOiUFmhnWEL00+jPk+QFsd03tV6hYs/vAbwzkjuwqMHCMdJoCiH8z95IEUvc5wJA
|
||||
MvLOuZdu4dmhOXg/YKsbMSPjFNEVskLQNSXqw6O2wIrpPg1NQvBBAOTbiuZj3vind4VPos1wc4vB
|
||||
QocvdUC6dA==
|
||||
-----END PRIVATE KEY-----
|
BIN
src/BeSimple/SoapClient/Tests/AxisInterop/image.jpg
Normal file
BIN
src/BeSimple/SoapClient/Tests/AxisInterop/image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
17
src/BeSimple/SoapClient/Tests/AxisInterop/servercert.pem
Normal file
17
src/BeSimple/SoapClient/Tests/AxisInterop/servercert.pem
Normal file
@ -0,0 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICoDCCAgkCBEnhwzMwDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNVBAYTAk5aMRMw
|
||||
EQYDVQQIEwpXZWxsaW5ndG9uMRowGAYDVQQHExFQYXJhcGFyYXVtdSBCZWFjaDEq
|
||||
MCgGA1UEChMhU29zbm9za2kgU29mdHdhcmUgQXNzb2NpYXRlcyBMdGQuMRAwDgYD
|
||||
VQQLEwdVbmtub3duMRgwFgYDVQQDEw9EZW5uaXMgU29zbm9za2kwHhcNMDkwNDEy
|
||||
MTAzMjE5WhcNMzYwODI3MTAzMjE5WjCBljELMAkGA1UEBhMCTloxEzARBgNVBAgT
|
||||
CldlbGxpbmd0b24xGjAYBgNVBAcTEVBhcmFwYXJhdW11IEJlYWNoMSowKAYDVQQK
|
||||
EyFTb3Nub3NraSBTb2Z0d2FyZSBBc3NvY2lhdGVzIEx0ZC4xEDAOBgNVBAsTB1Vu
|
||||
a25vd24xGDAWBgNVBAMTD0Rlbm5pcyBTb3Nub3NraTCBnzANBgkqhkiG9w0BAQEF
|
||||
AAOBjQAwgYkCgYEA1H3mjQCF9uce2jmm/Yq9kE4ytfvkp4c8G90cDfJXJvOiGQds
|
||||
p2vDZXKuCkHQ7vsBBXPNTt8J/d8ZbEwyuB9Ccz5pJqi6Ig6Y2/mEsPthDyh5SrJV
|
||||
yQ/wxUGwmfSuwdrIMnplMTq+OR9BOfT3CvjSvuy9d6BQNo4wOMkDvmZTtI8CAwEA
|
||||
ATANBgkqhkiG9w0BAQUFAAOBgQCqv4475QaqlKcN2QCZJbLVKZEX+76XLQurGkgf
|
||||
2fCgesRHjfUfOHyTTlhWQdEKTcBB2XviUyyW6I//fmKfXUIiQqvgh4LHdXRPEXDf
|
||||
Y9nr89MjyQpDlnl6AlrvSej30a9iwVRUeVk4d6gxWHMRonKBFgh+TGexxUXHtPkf
|
||||
B1Pdtg==
|
||||
-----END CERTIFICATE-----
|
183
src/BeSimple/SoapClient/Tests/CurlTest.php
Normal file
183
src/BeSimple/SoapClient/Tests/CurlTest.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapClient.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapClient\Tests;
|
||||
|
||||
use BeSimple\SoapClient\Curl;
|
||||
|
||||
/**
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
class CurlTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $webserverProcessId;
|
||||
|
||||
protected function startPhpWebserver()
|
||||
{
|
||||
$this->markTestSkipped('Start a local webserver is not the best practice');
|
||||
|
||||
$dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures';
|
||||
if ('Windows' == substr(php_uname('s'), 0, 7)) {
|
||||
$powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
|
||||
$shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
|
||||
} else {
|
||||
$shellCommand = "nohup php -S localhost:8000 -t ".$dir." &";
|
||||
}
|
||||
$output = array();
|
||||
exec($shellCommand, $output);
|
||||
$this->webserverProcessId = $output[0]; // pid is in first element
|
||||
}
|
||||
|
||||
protected function stopPhpWebserver()
|
||||
{
|
||||
if (!is_null($this->webserverProcessId)) {
|
||||
if ('Windows' == substr(php_uname('s'), 0, 7 )) {
|
||||
exec('TASKKILL /F /PID ' . $this->webserverProcessId);
|
||||
} else {
|
||||
exec('kill ' . $this->webserverProcessId);
|
||||
}
|
||||
$this->webserverProcessId = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testExec()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$this->assertTrue($curl->exec('http://localhost:8000/curl.txt'));
|
||||
$this->assertTrue($curl->exec('http://localhost:8000/404.txt'));
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetErrorMessage()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://unknown/curl.txt');
|
||||
$this->assertEquals('Could not connect to host', $curl->getErrorMessage());
|
||||
|
||||
$curl->exec('xyz://localhost:8000/@404.txt');
|
||||
$this->assertEquals('Unknown protocol. Only http and https are allowed.', $curl->getErrorMessage());
|
||||
|
||||
$curl->exec('');
|
||||
$this->assertEquals('Unable to parse URL', $curl->getErrorMessage());
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetRequestHeaders()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://localhost:8000/curl.txt');
|
||||
$this->assertEquals(136, strlen($curl->getRequestHeaders()));
|
||||
|
||||
$curl->exec('http://localhost:8000/404.txt');
|
||||
$this->assertEquals(135, strlen($curl->getRequestHeaders()));
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetResponse()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://localhost:8000/curl.txt');
|
||||
$this->assertEquals(150, strlen($curl->getResponse()));
|
||||
|
||||
$curl->exec('http://localhost:8000/404.txt');
|
||||
$this->assertEquals(1282, strlen($curl->getResponse()));
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetResponseBody()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://localhost:8000/curl.txt');
|
||||
$this->assertEquals('This is a testfile for cURL.', $curl->getResponseBody());
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetResponseContentType()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://localhost:8000/curl.txt');
|
||||
$this->assertEquals('text/plain; charset=UTF-8', $curl->getResponseContentType());
|
||||
|
||||
$curl->exec('http://localhost:8000/404.txt');
|
||||
$this->assertEquals('text/html; charset=UTF-8', $curl->getResponseContentType());
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetResponseHeaders()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://localhost:8000/curl.txt');
|
||||
$this->assertEquals(122, strlen($curl->getResponseHeaders()));
|
||||
|
||||
$curl->exec('http://localhost:8000/404.txt');
|
||||
$this->assertEquals(130, strlen($curl->getResponseHeaders()));
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetResponseStatusCode()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://localhost:8000/curl.txt');
|
||||
$this->assertEquals(200, $curl->getResponseStatusCode());
|
||||
|
||||
$curl->exec('http://localhost:8000/404.txt');
|
||||
$this->assertEquals(404, $curl->getResponseStatusCode());
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testGetResponseStatusMessage()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$curl->exec('http://localhost:8000/curl.txt');
|
||||
$this->assertEquals('OK', $curl->getResponseStatusMessage());
|
||||
|
||||
$curl->exec('http://localhost:8000/404.txt');
|
||||
$this->assertEquals('Not Found', $curl->getResponseStatusMessage());
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
}
|
1
src/BeSimple/SoapClient/Tests/Fixtures/curl.txt
Normal file
1
src/BeSimple/SoapClient/Tests/Fixtures/curl.txt
Normal file
@ -0,0 +1 @@
|
||||
This is a testfile for cURL.
|
47
src/BeSimple/SoapClient/Tests/Fixtures/foobar.wsdl
Normal file
47
src/BeSimple/SoapClient/Tests/Fixtures/foobar.wsdl
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0"?>
|
||||
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://foobar/soap/User/1.0/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="User" targetNamespace="http://foobar/soap/User/1.0/">
|
||||
<portType name="UserPortType">
|
||||
<operation name="login" parameterOrder="username password">
|
||||
<input message="tns:loginRequest"/>
|
||||
<output message="tns:loginResponse"/>
|
||||
</operation>
|
||||
</portType>
|
||||
<binding name="UserBinding" type="tns:UserPortType">
|
||||
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<operation name="login">
|
||||
<soap:operation soapAction="http://foobar/soap/User/1.0/login"/>
|
||||
<input>
|
||||
<soap:body parts="username password" use="literal" namespace="http://foobar/soap/User/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</input>
|
||||
<output>
|
||||
<soap:body parts="return" use="literal" namespace="http://foobar/soap/User/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</output>
|
||||
</operation>
|
||||
</binding>
|
||||
<service name="UserService">
|
||||
<port name="UserPort" binding="tns:UserBinding">
|
||||
<soap:address location="http://foobar/soap/user"/>
|
||||
</port>
|
||||
</service>
|
||||
<types>
|
||||
<xsd:schema targetNamespace="http://foobar/soap/User/1.0/">
|
||||
<xsd:complexType name="User">
|
||||
<xsd:all>
|
||||
<xsd:element name="id" type="xsd:int" nillable="true"/>
|
||||
<xsd:element name="username" type="xsd:string"/>
|
||||
<xsd:element name="email" type="xsd:string"/>
|
||||
<xsd:element name="language" type="xsd:string"/>
|
||||
<xsd:element name="apiKey" type="xsd:string"/>
|
||||
<xsd:element name="subscriptionEndAt" type="xsd:dateTime" nillable="true"/>
|
||||
</xsd:all>
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
</types>
|
||||
<message name="loginRequest">
|
||||
<part name="username" type="xsd:string"/>
|
||||
<part name="password" type="xsd:string"/>
|
||||
</message>
|
||||
<message name="loginResponse">
|
||||
<part name="return" type="tns:User"/>
|
||||
</message>
|
||||
</definitions>
|
15
src/BeSimple/SoapClient/Tests/Fixtures/type_include.xsd
Normal file
15
src/BeSimple/SoapClient/Tests/Fixtures/type_include.xsd
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<xs:element name="note">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="to" type="xs:string"/>
|
||||
<xs:element name="from" type="xs:string"/>
|
||||
<xs:element name="heading" type="xs:string"/>
|
||||
<xs:element name="body" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
</xs:schema>
|
15
src/BeSimple/SoapClient/Tests/Fixtures/wsdl_include.wsdl
Normal file
15
src/BeSimple/SoapClient/Tests/Fixtures/wsdl_include.wsdl
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<wsdl:types xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://test.sample">
|
||||
<xs:element name="note">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="to" type="xs:string"/>
|
||||
<xs:element name="from" type="xs:string"/>
|
||||
<xs:element name="heading" type="xs:string"/>
|
||||
<xs:element name="body" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
</wsdl:types>
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<wsdl:documentation>wsdlincludetest</wsdl:documentation>
|
||||
<wsdl:include location="http://localhost:8000/wsdl_include.wsdl"/>
|
||||
</wsdl:definitions>
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<wsdl:documentation>wsdlincludetest</wsdl:documentation>
|
||||
<wsdl:include location="../wsdl_include.wsdl"/>
|
||||
</wsdl:definitions>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<wsdl:documentation>xsdinctest</wsdl:documentation>
|
||||
<wsdl:types>
|
||||
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://test.sample">
|
||||
<xs:include schemaLocation="http://localhost:8000/type_include.xsd"/>
|
||||
</xs:schema>
|
||||
</wsdl:types>
|
||||
</wsdl:definitions>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<wsdl:documentation>xsdinctest</wsdl:documentation>
|
||||
<wsdl:types>
|
||||
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://test.sample">
|
||||
<xs:include schemaLocation="../type_include.xsd"/>
|
||||
</xs:schema>
|
||||
</wsdl:types>
|
||||
</wsdl:definitions>
|
61
src/BeSimple/SoapClient/Tests/ServerInterop/MTOM.php
Normal file
61
src/BeSimple/SoapClient/Tests/ServerInterop/MTOM.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
||||
use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
|
||||
|
||||
require '../bootstrap.php';
|
||||
|
||||
class base64Binary
|
||||
{
|
||||
public $_;
|
||||
public $contentType;
|
||||
}
|
||||
|
||||
class AttachmentType
|
||||
{
|
||||
public $fileName;
|
||||
public $binaryData;
|
||||
}
|
||||
|
||||
class AttachmentRequest extends AttachmentType
|
||||
{
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'soap_version' => SOAP_1_1,
|
||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||
'trace' => true, // enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders
|
||||
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
|
||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||
'classmap' => array(
|
||||
'base64Binary' => 'base64Binary',
|
||||
'AttachmentRequest' => 'AttachmentRequest',
|
||||
),
|
||||
);
|
||||
|
||||
$sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
|
||||
|
||||
//var_dump($sc->__getFunctions());
|
||||
//var_dump($sc->__getTypes());
|
||||
|
||||
try {
|
||||
$b64 = new base64Binary();
|
||||
$b64->_ = 'This is a test. :)';
|
||||
$b64->contentType = 'text/plain';
|
||||
|
||||
$attachment = new AttachmentRequest();
|
||||
$attachment->fileName = 'test123.txt';
|
||||
$attachment->binaryData = $b64;
|
||||
|
||||
var_dump($sc->attachment($attachment));
|
||||
|
||||
} catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
|
||||
// var_dump(
|
||||
// $sc->__getLastRequestHeaders(),
|
||||
// $sc->__getLastRequest(),
|
||||
// $sc->__getLastResponseHeaders(),
|
||||
// $sc->__getLastResponse()
|
||||
// );
|
89
src/BeSimple/SoapClient/Tests/ServerInterop/MTOM.wsdl
Normal file
89
src/BeSimple/SoapClient/Tests/ServerInterop/MTOM.wsdl
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definitions targetNamespace="http://ws.apache.org/axis2/mtomsample/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.apache.org/axis2/mtomsample/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
|
||||
<types>
|
||||
<xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.apache.org/axis2/mtomsample/" xmlns="http://schemas.xmlsoap.org/wsdl/">
|
||||
<xsd:import namespace="http://www.w3.org/2005/05/xmlmime"/>
|
||||
<xsd:complexType name="AttachmentType">
|
||||
<xsd:sequence>
|
||||
<xsd:element minOccurs="0" name="fileName" type="xsd:string"/>
|
||||
<xsd:element minOccurs="0" name="binaryData" type="xmime:base64Binary"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
<xsd:element name="AttachmentRequest" type="tns:AttachmentType"/>
|
||||
<xsd:element name="AttachmentResponse" type="xsd:string"/>
|
||||
</xsd:schema>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://www.w3.org/2005/05/xmlmime">
|
||||
<xs:attribute name="contentType">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:minLength value="3"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="expectedContentTypes" type="xs:string"/>
|
||||
<xs:complexType name="base64Binary">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:base64Binary">
|
||||
<xs:attribute ref="xmime:contentType"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="hexBinary">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:hexBinary">
|
||||
<xs:attribute ref="xmime:contentType"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
|
||||
</types>
|
||||
<message name="AttachmentResponse">
|
||||
<part name="part1" element="tns:AttachmentResponse">
|
||||
</part>
|
||||
</message>
|
||||
<message name="AttachmentRequest">
|
||||
<part name="part1" element="tns:AttachmentRequest">
|
||||
</part>
|
||||
</message>
|
||||
<portType name="MTOMServicePortType">
|
||||
<operation name="attachment">
|
||||
<input message="tns:AttachmentRequest" wsaw:Action="attachment">
|
||||
</input>
|
||||
<output message="tns:AttachmentResponse" wsaw:Action="http://schemas.xmlsoap.org/wsdl/MTOMServicePortType/AttachmentResponse">
|
||||
</output>
|
||||
</operation>
|
||||
</portType>
|
||||
<binding name="MTOMServiceSOAP11Binding" type="tns:MTOMServicePortType">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<operation name="attachment">
|
||||
<soap:operation soapAction="attachment" style="document"/>
|
||||
<input>
|
||||
<soap:body use="literal"/>
|
||||
</input>
|
||||
<output>
|
||||
<soap:body use="literal"/>
|
||||
</output>
|
||||
</operation>
|
||||
</binding>
|
||||
<binding name="MTOMServiceSOAP12Binding" type="tns:MTOMServicePortType">
|
||||
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<operation name="attachment">
|
||||
<soap12:operation soapAction="attachment" style="document"/>
|
||||
<input>
|
||||
<soap12:body use="literal"/>
|
||||
</input>
|
||||
<output>
|
||||
<soap12:body use="literal"/>
|
||||
</output>
|
||||
</operation>
|
||||
</binding>
|
||||
<service name="MTOMSample">
|
||||
<port name="MTOMSampleSOAP12port_http" binding="tns:MTOMServiceSOAP12Binding">
|
||||
<soap12:address location="http://web/BeSimpleSoapClient/tests/ServerInterop/MTOMServer.php"/>
|
||||
</port>
|
||||
<port name="MTOMSampleSOAP11port_http" binding="tns:MTOMServiceSOAP11Binding">
|
||||
<soap:address location="http://web/BeSimpleSoapClient/tests/ServerInterop/MTOMServer.php"/>
|
||||
</port>
|
||||
</service>
|
||||
</definitions>
|
53
src/BeSimple/SoapClient/Tests/ServerInterop/MTOMServer.php
Normal file
53
src/BeSimple/SoapClient/Tests/ServerInterop/MTOMServer.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper;
|
||||
use BeSimple\SoapServer\SoapServer as BeSimpleSoapServer;
|
||||
|
||||
require '../../../BeSimpleSoapServer/tests/bootstrap.php';
|
||||
|
||||
class base64Binary
|
||||
{
|
||||
public $_;
|
||||
public $contentType;
|
||||
}
|
||||
|
||||
class AttachmentType
|
||||
{
|
||||
public $fileName;
|
||||
public $binaryData;
|
||||
}
|
||||
|
||||
class AttachmentRequest extends AttachmentType
|
||||
{
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'soap_version' => SOAP_1_1,
|
||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
|
||||
'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
|
||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||
'classmap' => array(
|
||||
'base64Binary' => 'base64Binary',
|
||||
'AttachmentRequest' => 'AttachmentRequest',
|
||||
),
|
||||
);
|
||||
|
||||
class Mtom
|
||||
{
|
||||
public function attachment(AttachmentRequest $attachment)
|
||||
{
|
||||
$b64 = $attachment->binaryData;
|
||||
|
||||
file_put_contents('test.txt', var_export(array(
|
||||
$attachment->fileName,
|
||||
$b64->_,
|
||||
$b64->contentType
|
||||
), true));
|
||||
|
||||
return 'done';
|
||||
}
|
||||
}
|
||||
|
||||
$ss = new BeSimpleSoapServer('MTOM.wsdl', $options);
|
||||
$ss->setClass('Mtom');
|
||||
$ss->handle();
|
119
src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php
Normal file
119
src/BeSimple/SoapClient/Tests/SoapClientBuilderTest.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapClient\Tests;
|
||||
|
||||
use BeSimple\SoapClient\SoapClientBuilder;
|
||||
|
||||
class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $defaultOptions = array(
|
||||
'features' => 0,
|
||||
'classmap' => array(),
|
||||
'typemap' => array(),
|
||||
);
|
||||
|
||||
public function testContruct()
|
||||
{
|
||||
$options = $this
|
||||
->getSoapBuilder()
|
||||
->getSoapOptions()
|
||||
;
|
||||
|
||||
$this->assertEquals($this->mergeOptions(array()), $options);
|
||||
}
|
||||
|
||||
public function testWithTrace()
|
||||
{
|
||||
$builder = $this->getSoapBuilder();
|
||||
|
||||
$builder->withTrace();
|
||||
$this->assertEquals($this->mergeOptions(array('trace' => true)), $builder->getSoapOptions());
|
||||
|
||||
$builder->withTrace(false);
|
||||
$this->assertEquals($this->mergeOptions(array('trace' => false)), $builder->getSoapOptions());
|
||||
}
|
||||
|
||||
public function testWithExceptions()
|
||||
{
|
||||
$builder = $this->getSoapBuilder();
|
||||
|
||||
$builder->withExceptions();
|
||||
$this->assertEquals($this->mergeOptions(array('exceptions' => true)), $builder->getSoapOptions());
|
||||
|
||||
$builder->withExceptions(false);
|
||||
$this->assertEquals($this->mergeOptions(array('exceptions' => false)), $builder->getSoapOptions());
|
||||
}
|
||||
|
||||
public function testWithUserAgent()
|
||||
{
|
||||
$builder = $this->getSoapBuilder();
|
||||
|
||||
$builder->withUserAgent('BeSimpleSoap Test');
|
||||
$this->assertEquals($this->mergeOptions(array('user_agent' => 'BeSimpleSoap Test')), $builder->getSoapOptions());
|
||||
}
|
||||
|
||||
public function testWithCompression()
|
||||
{
|
||||
$builder = $this->getSoapBuilder();
|
||||
|
||||
$builder->withCompressionGzip();
|
||||
$this->assertEquals($this->mergeOptions(array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP)), $builder->getSoapOptions());
|
||||
|
||||
$builder->withCompressionDeflate();
|
||||
$this->assertEquals($this->mergeOptions(array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE)), $builder->getSoapOptions());
|
||||
}
|
||||
|
||||
public function testWithAuthentication()
|
||||
{
|
||||
$builder = $this->getSoapBuilder();
|
||||
|
||||
$builder->withDigestAuthentication(__DIR__.'/Fixtures/cert.pem', 'foobar');
|
||||
$this->assertEquals($this->mergeOptions(array('authentication' => SOAP_AUTHENTICATION_DIGEST, 'local_cert' => __DIR__.'/Fixtures/cert.pem', 'passphrase' => 'foobar')), $builder->getSoapOptions());
|
||||
|
||||
$builder->withDigestAuthentication(__DIR__.'/Fixtures/cert.pem');
|
||||
$this->assertEquals($this->mergeOptions(array('authentication' => SOAP_AUTHENTICATION_DIGEST, 'local_cert' => __DIR__.'/Fixtures/cert.pem')), $builder->getSoapOptions());
|
||||
|
||||
$builder->withBasicAuthentication('foo', 'bar');
|
||||
$this->assertEquals($this->mergeOptions(array('authentication' => SOAP_AUTHENTICATION_BASIC, 'login' => 'foo', 'password' => 'bar')), $builder->getSoapOptions());
|
||||
}
|
||||
|
||||
public function testWithProxy()
|
||||
{
|
||||
$builder = $this->getSoapBuilder();
|
||||
|
||||
$builder->withProxy('localhost', 8080);
|
||||
$this->assertEquals($this->mergeOptions(array('proxy_host' => 'localhost', 'proxy_port' => 8080)), $builder->getSoapOptions());
|
||||
|
||||
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar');
|
||||
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar')), $builder->getSoapOptions());
|
||||
}
|
||||
|
||||
public function testCreateWithDefaults()
|
||||
{
|
||||
$builder = SoapClientBuilder::createWithDefaults();
|
||||
|
||||
$this->assertInstanceOf('BeSimple\SoapClient\SoapClientBuilder', $builder);
|
||||
|
||||
$this->assertEquals($this->mergeOptions(array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'user_agent' => 'BeSimpleSoap')), $builder->getSoapOptions());
|
||||
}
|
||||
|
||||
private function getSoapBuilder()
|
||||
{
|
||||
return new SoapClientBuilder();
|
||||
}
|
||||
|
||||
private function mergeOptions(array $options)
|
||||
{
|
||||
return array_merge($this->defaultOptions, $options);
|
||||
}
|
||||
}
|
268
src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php
Normal file
268
src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php
Normal file
@ -0,0 +1,268 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapClient.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapClient\Tests;
|
||||
|
||||
use BeSimple\SoapClient\WsdlDownloader;
|
||||
use BeSimple\SoapClient\Curl;
|
||||
|
||||
/**
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $webserverProcessId;
|
||||
|
||||
protected function startPhpWebserver()
|
||||
{
|
||||
$this->markTestSkipped('Start a local webserver is not the best practice');
|
||||
|
||||
$dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures';
|
||||
if ('Windows' == substr(php_uname('s'), 0, 7)) {
|
||||
$powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
|
||||
$shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
|
||||
} else {
|
||||
$shellCommand = "nohup php -S localhost:8000 -t ".$dir." &";
|
||||
}
|
||||
$output = array();
|
||||
exec($shellCommand, $output);
|
||||
$this->webserverProcessId = $output[0]; // pid is in first element
|
||||
}
|
||||
|
||||
protected function stopPhpWebserver()
|
||||
{
|
||||
if (!is_null($this->webserverProcessId)) {
|
||||
if ('Windows' == substr(php_uname('s'), 0, 7)) {
|
||||
exec('TASKKILL /F /PID ' . $this->webserverProcessId);
|
||||
} else {
|
||||
exec('kill ' . $this->webserverProcessId);
|
||||
}
|
||||
$this->webserverProcessId = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testDownload()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
$wd = new WsdlDownloader($curl);
|
||||
|
||||
$cacheDir = ini_get('soap.wsdl_cache_dir');
|
||||
if (!is_dir($cacheDir)) {
|
||||
$cacheDir = sys_get_temp_dir();
|
||||
$cacheDirForRegExp = preg_quote($cacheDir);
|
||||
}
|
||||
|
||||
$tests = array(
|
||||
'localWithAbsolutePath' => array(
|
||||
'source' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/xsdinclude/xsdinctest_absolute.xml',
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
'localWithRelativePath' => array(
|
||||
'source' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/xsdinclude/xsdinctest_relative.xml',
|
||||
'assertRegExp' => '~.*\.\./type_include\.xsd.*~',
|
||||
),
|
||||
'remoteWithAbsolutePath' => array(
|
||||
'source' => 'http://localhost:8000/xsdinclude/xsdinctest_absolute.xml',
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
'remoteWithAbsolutePath' => array(
|
||||
'source' => 'http://localhost:8000/xsdinclude/xsdinctest_relative.xml',
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($tests as $name => $values) {
|
||||
$cacheFileName = $wd->download($values['source']);
|
||||
$result = file_get_contents($cacheFileName);
|
||||
$this->assertRegExp($values['assertRegExp'], $result, $name);
|
||||
unlink($cacheFileName);
|
||||
}
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testIsRemoteFile()
|
||||
{
|
||||
$curl = new Curl();
|
||||
$wd = new WsdlDownloader($curl);
|
||||
|
||||
$class = new \ReflectionClass($wd);
|
||||
$method = $class->getMethod('isRemoteFile');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertTrue($method->invoke($wd, 'http://www.php.net/'));
|
||||
$this->assertTrue($method->invoke($wd, 'http://localhost/'));
|
||||
$this->assertTrue($method->invoke($wd, 'http://mylocaldomain/'));
|
||||
$this->assertTrue($method->invoke($wd, 'http://www.php.net/dir/test.html'));
|
||||
$this->assertTrue($method->invoke($wd, 'http://localhost/dir/test.html'));
|
||||
$this->assertTrue($method->invoke($wd, 'http://mylocaldomain/dir/test.html'));
|
||||
$this->assertTrue($method->invoke($wd, 'https://www.php.net/'));
|
||||
$this->assertTrue($method->invoke($wd, 'https://localhost/'));
|
||||
$this->assertTrue($method->invoke($wd, 'https://mylocaldomain/'));
|
||||
$this->assertTrue($method->invoke($wd, 'https://www.php.net/dir/test.html'));
|
||||
$this->assertTrue($method->invoke($wd, 'https://localhost/dir/test.html'));
|
||||
$this->assertTrue($method->invoke($wd, 'https://mylocaldomain/dir/test.html'));
|
||||
$this->assertFalse($method->invoke($wd, 'c:/dir/test.html'));
|
||||
$this->assertFalse($method->invoke($wd, '/dir/test.html'));
|
||||
$this->assertFalse($method->invoke($wd, '../dir/test.html'));
|
||||
}
|
||||
|
||||
public function testResolveWsdlIncludes()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
$wd = new WsdlDownloader($curl);
|
||||
|
||||
$class = new \ReflectionClass($wd);
|
||||
$method = $class->getMethod('resolveRemoteIncludes');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$cacheDir = ini_get('soap.wsdl_cache_dir');
|
||||
if (!is_dir($cacheDir)) {
|
||||
$cacheDir = sys_get_temp_dir();
|
||||
$cacheDirForRegExp = preg_quote($cacheDir);
|
||||
}
|
||||
|
||||
$remoteUrlAbsolute = 'http://localhost:8000/wsdlinclude/wsdlinctest_absolute.xml';
|
||||
$remoteUrlRelative = 'http://localhost:8000/wsdlinclude/wsdlinctest_relative.xml';
|
||||
$tests = array(
|
||||
'localWithAbsolutePath' => array(
|
||||
'source' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/wsdlinclude/wsdlinctest_absolute.xml',
|
||||
'cacheFile' => $cacheDir.'/cache_local_absolute.xml',
|
||||
'remoteParentUrl' => null,
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
'localWithRelativePath' => array(
|
||||
'source' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/wsdlinclude/wsdlinctest_relative.xml',
|
||||
'cacheFile' => $cacheDir.'/cache_local_relative.xml',
|
||||
'remoteParentUrl' => null,
|
||||
'assertRegExp' => '~.*\.\./wsdl_include\.wsdl.*~',
|
||||
),
|
||||
'remoteWithAbsolutePath' => array(
|
||||
'source' => $remoteUrlAbsolute,
|
||||
'cacheFile' => $cacheDir.'/cache_remote_absolute.xml',
|
||||
'remoteParentUrl' => $remoteUrlAbsolute,
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
'remoteWithAbsolutePath' => array(
|
||||
'source' => $remoteUrlRelative,
|
||||
'cacheFile' => $cacheDir.'/cache_remote_relative.xml',
|
||||
'remoteParentUrl' => $remoteUrlRelative,
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($tests as $name => $values) {
|
||||
$wsdl = file_get_contents($values['source']);
|
||||
$method->invoke($wd, $wsdl, $values['cacheFile'], $values['remoteParentUrl']);
|
||||
$result = file_get_contents($values['cacheFile']);
|
||||
$this->assertRegExp($values['assertRegExp'], $result, $name);
|
||||
unlink($values['cacheFile']);
|
||||
}
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testResolveXsdIncludes()
|
||||
{
|
||||
$this->startPhpWebserver();
|
||||
|
||||
$curl = new Curl();
|
||||
$wd = new WsdlDownloader($curl);
|
||||
|
||||
$class = new \ReflectionClass($wd);
|
||||
$method = $class->getMethod('resolveRemoteIncludes');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$cacheDir = ini_get('soap.wsdl_cache_dir');
|
||||
if (!is_dir($cacheDir)) {
|
||||
$cacheDir = sys_get_temp_dir();
|
||||
$cacheDirForRegExp = preg_quote($cacheDir);
|
||||
}
|
||||
|
||||
$remoteUrlAbsolute = 'http://localhost:8000/xsdinclude/xsdinctest_absolute.xml';
|
||||
$remoteUrlRelative = 'http://localhost:8000/xsdinclude/xsdinctest_relative.xml';
|
||||
$tests = array(
|
||||
'localWithAbsolutePath' => array(
|
||||
'source' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/xsdinclude/xsdinctest_absolute.xml',
|
||||
'cacheFile' => $cacheDir.'/cache_local_absolute.xml',
|
||||
'remoteParentUrl' => null,
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
'localWithRelativePath' => array(
|
||||
'source' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/xsdinclude/xsdinctest_relative.xml',
|
||||
'cacheFile' => $cacheDir.'/cache_local_relative.xml',
|
||||
'remoteParentUrl' => null,
|
||||
'assertRegExp' => '~.*\.\./type_include\.xsd.*~',
|
||||
),
|
||||
'remoteWithAbsolutePath' => array(
|
||||
'source' => $remoteUrlAbsolute,
|
||||
'cacheFile' => $cacheDir.'/cache_remote_absolute.xml',
|
||||
'remoteParentUrl' => $remoteUrlAbsolute,
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
'remoteWithAbsolutePath' => array(
|
||||
'source' => $remoteUrlRelative,
|
||||
'cacheFile' => $cacheDir.'/cache_remote_relative.xml',
|
||||
'remoteParentUrl' => $remoteUrlRelative,
|
||||
'assertRegExp' => '~.*'.$cacheDirForRegExp.'\\\wsdl_.*\.cache.*~',
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($tests as $name => $values) {
|
||||
$wsdl = file_get_contents($values['source']);
|
||||
$method->invoke($wd, $wsdl, $values['cacheFile'], $values['remoteParentUrl']);
|
||||
$result = file_get_contents($values['cacheFile']);
|
||||
$this->assertRegExp($values['assertRegExp'], $result, $name);
|
||||
unlink($values['cacheFile']);
|
||||
}
|
||||
|
||||
$this->stopPhpWebserver();
|
||||
}
|
||||
|
||||
public function testResolveRelativePathInUrl()
|
||||
{
|
||||
$curl = new Curl();
|
||||
$wd = new WsdlDownloader($curl);
|
||||
|
||||
$class = new \ReflectionClass($wd);
|
||||
$method = $class->getMethod('resolveRelativePathInUrl');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertEquals('http://localhost:8080/test', $method->invoke($wd, 'http://localhost:8080/sub', '/test'));
|
||||
$this->assertEquals('http://localhost:8080/test', $method->invoke($wd, 'http://localhost:8080/sub/', '/test'));
|
||||
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/sub', '/test'));
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/sub/', '/test'));
|
||||
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost', './test'));
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/', './test'));
|
||||
|
||||
$this->assertEquals('http://localhost/sub/test', $method->invoke($wd, 'http://localhost/sub/sub', './test'));
|
||||
$this->assertEquals('http://localhost/sub/sub/test', $method->invoke($wd, 'http://localhost/sub/sub/', './test'));
|
||||
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/sub/sub', '../test'));
|
||||
$this->assertEquals('http://localhost/sub/test', $method->invoke($wd, 'http://localhost/sub/sub/', '../test'));
|
||||
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/sub/sub/sub', '../../test'));
|
||||
$this->assertEquals('http://localhost/sub/test', $method->invoke($wd, 'http://localhost/sub/sub/sub/', '../../test'));
|
||||
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/sub/sub/sub/sub', '../../../test'));
|
||||
$this->assertEquals('http://localhost/sub/test', $method->invoke($wd, 'http://localhost/sub/sub/sub/sub/', '../../../test'));
|
||||
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/sub/sub/sub', '../../../test'));
|
||||
$this->assertEquals('http://localhost/test', $method->invoke($wd, 'http://localhost/sub/sub/sub/', '../../../test'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user