java - 如何将 PHP 对象数组作为 Java/SOAP 服务的参数传递?
问题描述
我正在用 Java 编写一个 WS Soap,用 PHP 编写一个客户端。我必须将一组“创建者”对象传递给网络服务。但我测试得越多,进步就越少。我指出我对 java 的了解非常有限。
我在哪里阻止:
- 字符串:没问题,没关系。
- 对象:没问题,没关系
- 字符串数组:没问题,没关系。
- 对象数组:KO
我是否有编写 Java Web 服务的正确方法,尤其是@WebParam
( @WebParam(name="creator") ArrayList<Creator> creators
) 和@XMLElement(..., type=Creator.class)
?
public String createMetadata
(
@WebParam(name="identifier") @XmlElement(name="identifier", required=true, nillable=true, type=Identifier.class ) Identifier identifier,
@WebParam(name="creator") @XmlElement(name="creator", required=true, nillable=true, type=Creator.class ) ArrayList<Creator> creators,
@WebParam(name="title") @XmlElement(name="title", required=true, nillable=true, type=Title.class ) ArrayList<Title> titles,
@WebParam(name="publicationYear") @XmlElement(name="publicationYear", required=true, nillable=true, type=String.class ) String publicationYear,
@WebParam(name="publisher") @XmlElement(name="publisher", required=true, nillable=true, type=String.class ) String publisher,
@WebParam(name="resourceType") @XmlElement(name="resourceType", required=true, nillable=true, type=ResourceType.class ) ResourceType resourceType,
@WebParam(name="subject") @XmlElement(name="subject", required=true, nillable=true, type=Subject.class ) ArrayList<Subject> subjects,
@WebParam(name="contributor") @XmlElement(name="contributor", required=true, nillable=true, type=Contributor.class ) ArrayList<Contributor> contributors,
@WebParam(name="date") @XmlElement(name="date", required=true, nillable=true, type=Date.class ) ArrayList<Date> dates,
@WebParam(name="language") @XmlElement(name="language", required=true, nillable=true, type=String.class ) String language,
@WebParam(name="alternateIdentifier") @XmlElement(name="alternateIdentifier", required=true, nillable=true, type=AlternateIdentifier.class ) ArrayList<AlternateIdentifier> alternateIdentifiers,
@WebParam(name="relatedIdentifier") @XmlElement(name="relatedIdentifier", required=true, nillable=true, type=RelatedIdentifier.class ) ArrayList<RelatedIdentifier> relatedIdentifiers,
@WebParam(name="size") @XmlElement(name="size", required=true, nillable=true, type=String.class ) ArrayList<String> sizes,
@WebParam(name="format") @XmlElement(name="format", required=true, nillable=true, type=String.class ) ArrayList<String> formats,
@WebParam(name="version") @XmlElement(name="version", required=true, nillable=true, type=String.class ) String version,
@WebParam(name="rights") @XmlElement(name="rights", required=true, nillable=true, type=Rights.class ) ArrayList<Rights> rights,
@WebParam(name="description") @XmlElement(name="description", required=true, nillable=true, type=Description.class ) ArrayList<Description> descriptions,
@WebParam(name="geoLocation") @XmlElement(name="geoLocation", required=true, nillable=true, type=GeoLocation.class ) ArrayList<GeoLocation> geoLocations,
@WebParam(name="fundingReference") @XmlElement(name="fundingReference", required=true, nillable=true, type=FundingReference.class ) ArrayList<FundingReference> fundingReferences
)
{
String result = "";
result += "\n\n===== IDENTIFIER =====\n";
result += identifier.getIdentifier() + ", " + identifier.getIdentifierType();
result += "\n\n===== CREATORS =====\n";
for(Creator c: creators)
result += c.getCreatorName() + "\n";
result += "\n\n===== PUBLICATION YEAR =====\n";
result += publicationYear + "\n";
result += "\n\n===== PUBLISHER =====\n";
result += publisher + "\n";
result += "\n\n===== LANGUAGE =====\n";
result += language + "\n";
result += "\n\n===== FORMATS =====\n";
for(String f: formats)
result += f + "\n";
result += "\n\n===== SIZES =====\n";
for(String s: sizes)
result += s + "\n";
result += "\n\n===== VERSION =====\n";
result += version + "\n";
return result;
}
如何正确地将 PHP 中的“Creator”对象数组传递给 Web 服务?
现在,这是我在 PHP 中所做的:
<?php
require_once('Entity/AlternateIdentifier.class.php');
require_once('Entity/Contributor.class.php');
require_once('Entity/Creator.class.php');
require_once('Entity/Date.class.php');
require_once('Entity/Description.class.php');
require_once('Entity/FundingReference.class.php');
require_once('Entity/GeoLocation.class.php');
require_once('Entity/GeoLocationBox.class.php');
require_once('Entity/GeoLocationPoint.class.php');
require_once('Entity/GeoLocationPolygon.class.php');
require_once('Entity/Identifier.class.php');
require_once('Entity/NameIdentifier.class.php');
require_once('Entity/RelatedIdentifier.class.php');
require_once('Entity/ResourceType.class.php');
require_once('Entity/Right.class.php');
require_once('Entity/Subject.class.php');
require_once('Entity/Title.class.php');
//Configure the options of the soap client
$options = array(
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => false,
'exceptions' => true,
'stream_context' => stream_context_create ( array( 'ssl' => array( 'cafile' => 'ssl/my_certs_file.crt' ) ) )
);
try
{
//Create the soap client
$client = new SoapClient("https://sicpa-interop.inra.fr:31081/SicpaOpenDataWS-rec/SicpaOpenDataWS?wsdl", $options);
//Prepare the parameters of the request
$params = array(
'identifier' => getIdentifier(),
'creator' => getCreators(),
'title' => null,
'publicationYear' => "2014",
'publisher' => "National Research Council of Canada",
'resourceType' => null,
'subject' => null,
'contributor' => null,
'date' => null,
'language' => "en",
'alternateIdentifier' => null,
'relatedIdentifier' => null,
'size' => getSizes(),
'format' => getFormats(),
'version' => "4.3",
'right' => null,
'description' => null,
'geoLocation' => null,
'fundingReference' => null
);
//Call the method
$reponse = $client->getVersion();
for ($i=0; $i<10; $i++)
{
$reponse = $client->createMetadata($params);
if( isset($reponse->metadata) )
{
var_dump($reponse->metadata);
return;
}
}
}
catch(SoapFault $sf)
{
}
catch(Exception $e)
{
}
function getCreators()
{
$creators = array();
$creator1 = new Creator();
$creator2 = new Creator();
$creator1->setNameType("Personal");
$creator1->setGivenName("Elizabeth");
$creator1->setFamilyName("Miller");
$creator1->setNameType("Organizational");
$creator2->setOrganizationalName("Ontario Ministry of Natural Resources and Forestry");
$creator2->setXmlLang("en");
$creators[] = $creator1;
$creators[] = $creator2;
return $creators;
}
function getFormats()
{
$formats = array();
$formats[] = "application/json";
$formats[] = "application/text";
$formats[] = "application/xml";
return $formats;
}
function getSizes()
{
$sizes = array();
$sizes[] = "4 KB";
$sizes[] = "7 MB";
$sizes[] = "1 GB";
return $sizes;
}
function getIdentifier()
{
return new Identifier("10.5072/example-full", "DOI");
}
?>
这是我得到的结果:
string(330) "
===== IDENTIFIER =====
10.5072/example-full, DOI
===== CREATORS =====
===== PUBLICATION YEAR =====
2014
===== PUBLISHER =====
National Research Council of Canada
===== LANGUAGE =====
en
===== FORMATS =====
application/json
application/text
application/xml
===== SIZES =====
4 KB
7 MB
1 GB
===== VERSION =====
4.3
"
有没有人有一个好主意来解锁我?
先感谢您