/*
* Copyright 2011 Federal Chancellery Austria and
* Graz University of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package at.gv.util.client.moaspss;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLContext;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.soap.SOAPBinding;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.xpath.XPathAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import at.gv.util.DOMUtils;
import at.gv.util.LaxHostNameVerifier;
import at.gv.util.LoggingHandler;
import at.gv.util.MiscUtil;
import at.gv.util.config.EgovUtilConfiguration;
import at.gv.util.ex.EgovUtilException;
import at.gv.util.wsdl.SignatureCreationService;
import at.gv.util.wsdl.SignatureVerificationService;
import at.gv.util.xsd.moaspss.CreateXMLSignatureRequest;
import at.gv.util.xsd.moaspss.CreateXMLSignatureResponseType;
import at.gv.util.xsd.moaspss.ErrorResponseType;
import at.gv.util.xsd.moaspss.VerifyCMSSignatureResponseType;
import at.gv.util.xsd.moaspss.VerifyXMLSignatureRequestType;
import at.gv.util.xsd.moaspss.VerifyXMLSignatureResponseType;
/**
* MOA-SS client.
*
* @author Arne Tauber
*
*/
public class MOASPSSClient {
private static Logger log = LoggerFactory.getLogger(MOASPSSClient.class);
private EgovUtilConfiguration config = null;
public MOASPSSClient(EgovUtilConfiguration config) {
if (config == null) {
throw new NullPointerException("Argument 'config' must not be null.");
}
this.config = config;
}
public MOASPSSClient() {
}
@SuppressWarnings("unchecked")
public Element sendSignatureCreationRequest(String serviceURL,
InputStream signatureCreationRequest) throws MOASPSSClientException {
log.debug("Creating XML signature using raw CreateXMLSignatureRequest.");
// check for arguments
if (serviceURL == null) {
throw new NullPointerException("Argument 'serviceURL' must not be null.");
}
if (signatureCreationRequest == null) {
throw new NullPointerException(
"Argument 'signatureRequest' must not be null.");
}
try {
log.trace("MOA-SS signature service URL: " + serviceURL);
URL url = MOASPSSClient.class.getResource("/wsdl/MOA-SPSS-1.3.wsdl");
SignatureCreationService service = new SignatureCreationService(
url,
new QName(
"http://reference.e-government.gv.at/namespace/moa/20020822#moa.wsdl",
"SignatureCreationService"));
QName qname = new QName(
"http://localhost:8080/moa-spss/services/SignatureCreation",
"CreateXMLSignatureRequest");
service.addPort(qname, SOAPBinding.SOAP11HTTP_BINDING, serviceURL);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
MiscUtil.copyStream(signatureCreationRequest, bos);
Source source = new StreamSource(new ByteArrayInputStream(
bos.toByteArray()));
Dispatch