diff options
author | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2009-01-28 19:40:11 +0000 |
---|---|---|
committer | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2009-01-28 19:40:11 +0000 |
commit | 54aa4703e3d66c5b1a63b8d925fd4c9c1766687c (patch) | |
tree | 28bde8b9ec66dd2f94a34e39ee8392e40e9f0809 /STALXService/src/main/java/at/gv/egiz | |
parent | cfae494572cdac7ab124f9a4214bc8f43b87b7fe (diff) | |
download | mocca-54aa4703e3d66c5b1a63b8d925fd4c9c1766687c.tar.gz mocca-54aa4703e3d66c5b1a63b8d925fd4c9c1766687c.tar.bz2 mocca-54aa4703e3d66c5b1a63b8d925fd4c9c1766687c.zip |
activation
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@291 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'STALXService/src/main/java/at/gv/egiz')
3 files changed, 335 insertions, 0 deletions
diff --git a/STALXService/src/main/java/at/gv/egiz/stalx/service/STALPortType.java b/STALXService/src/main/java/at/gv/egiz/stalx/service/STALPortType.java new file mode 100644 index 00000000..b31e60ce --- /dev/null +++ b/STALXService/src/main/java/at/gv/egiz/stalx/service/STALPortType.java @@ -0,0 +1,45 @@ +package at.gv.egiz.stalx.service; + +//import at.buergerkarte.namespaces.cardchannel.service.ObjectFactory; +//import at.buergerkarte.namespaces.cardchannel.service.ScriptType; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * Dummy PortType to add at.buergerkarte.namespaces.cardchannel.service to the + * JAXB context seed. + * + * overriding a webmethod results in ClassCastEx for the WebResult + * ClassCastException: at.gv.egiz.stal.service.types.GetNextRequestResponseType + * cannot be cast to at.buergerkarte.namespaces.cardchannel.service.GetNextRequestResponseType + * + * adding a new method results in Error: Undefined operation name + * + * adding a constant doesn't seed + */ +@WebService(name = "STALPortType", targetNamespace = "http://www.egiz.gv.at/wsdl/stal") +@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) +@XmlSeeAlso({ + at.gv.egiz.stal.service.types.ObjectFactory.class, + at.buergerkarte.namespaces.cardchannel.service.ObjectFactory.class +}) +interface STALPortType extends at.gv.egiz.stal.service.STALPortType { + + // doesn't seed +// public static final ScriptType seed = (new ObjectFactory()).createScriptType(); + /** + * dummy method to put at.buergerkarte.namespaces.cardchannel.service as JAXB context seed + * @return + */ +// @WebMethod +// @WebResult(name = "Script", targetNamespace = "http://www.buergerkarte.at/cardchannel", partName = "part1") + //java.lang.Error: Undefined operation name seedJAXBContext +// ScriptType seedJAXBContext(); + +// @WebMethod +// @WebResult(name = "GetNextRequestResponse", targetNamespace = "http://www.egiz.gv.at/stal", partName = "part1") +// @Override +// public GetNextRequestResponseType connect( +// @WebParam(name = "SessionId", targetNamespace = "http://www.egiz.gv.at/stal", partName = "part1") String sessionId); +} diff --git a/STALXService/src/main/java/at/gv/egiz/stalx/service/STALService.java b/STALXService/src/main/java/at/gv/egiz/stalx/service/STALService.java new file mode 100644 index 00000000..eccd2c4f --- /dev/null +++ b/STALXService/src/main/java/at/gv/egiz/stalx/service/STALService.java @@ -0,0 +1,73 @@ + +package at.gv.egiz.stalx.service; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Logger; +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import javax.xml.ws.WebEndpoint; +import javax.xml.ws.WebServiceClient; +import javax.xml.ws.WebServiceFeature; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.1.3-b02- + * Generated source version: 2.1 + * + */ +@WebServiceClient(name = "STALService", targetNamespace = "http://www.egiz.gv.at/wsdl/stal") +//, wsdlLocation = "file:/home/clemens/workspace/mocca/BKUOnline/src/main/webapp/WEB-INF/wsdl/stal-service.wsdl") +public class STALService + extends Service +{ + +// private final static URL STALSERVICE_WSDL_LOCATION; + private final static Logger logger = Logger.getLogger(at.gv.egiz.stalx.service.STALService.class.getName()); + +// static { +// URL url = null; +// try { +// URL baseUrl; +// baseUrl = at.gv.egiz.stal.service.STALService.class.getResource("."); +// url = new URL(baseUrl, "file:/home/clemens/workspace/mocca/BKUOnline/src/main/webapp/WEB-INF/wsdl/stal-service.wsdl"); +// } catch (MalformedURLException e) { +// logger.warning("Failed to create URL for the wsdl Location: 'file:/home/clemens/workspace/mocca/BKUOnline/src/main/webapp/WEB-INF/wsdl/stal-service.wsdl', retrying as a local file"); +// logger.warning(e.getMessage()); +// } +// STALSERVICE_WSDL_LOCATION = url; +// } + + public STALService(URL wsdlLocation, QName serviceName) { + super(wsdlLocation, serviceName); + } + +// public STALService() { +// super(STALSERVICE_WSDL_LOCATION, new QName("http://www.egiz.gv.at/wsdl/stal", "STALService")); +// } + + /** + * Do not export package protected STALXPortType interface + * (this is a dummy interface to make JAXB include the STAL-X types) + * @return + * returns STALPortType + */ + @WebEndpoint(name = "STALPort") + public at.gv.egiz.stal.service.STALPortType getSTALPort() { + return super.getPort(new QName("http://www.egiz.gv.at/wsdl/stal", "STALPort"), STALPortType.class); + } + + /** + * + * @param features + * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values. + * @return + * returns STALPortType + */ +// @WebEndpoint(name = "STALPort") +// public STALPortType getSTALPort(WebServiceFeature... features) { +// return super.getPort(new QName("http://www.egiz.gv.at/wsdl/stal", "STALPort"), STALPortType.class, features); +// } + +} diff --git a/STALXService/src/main/java/at/gv/egiz/stalx/service/translator/STALXTranslationHandler.java b/STALXService/src/main/java/at/gv/egiz/stalx/service/translator/STALXTranslationHandler.java new file mode 100644 index 00000000..d93da722 --- /dev/null +++ b/STALXService/src/main/java/at/gv/egiz/stalx/service/translator/STALXTranslationHandler.java @@ -0,0 +1,217 @@ +/* + * Copyright 2008 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.egiz.stalx.service.translator; + +import at.buergerkarte.namespaces.cardchannel.service.ATRType; +import at.buergerkarte.namespaces.cardchannel.service.CommandAPDUType; +import at.buergerkarte.namespaces.cardchannel.service.ObjectFactory; +import at.buergerkarte.namespaces.cardchannel.service.ResetType; +import at.buergerkarte.namespaces.cardchannel.service.ResponseAPDUType; +import at.buergerkarte.namespaces.cardchannel.service.ScriptType; +import at.buergerkarte.namespaces.cardchannel.service.VerifyAPDUType; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.ext.APDUScriptRequest; +import at.gv.egiz.stal.ext.APDUScriptRequest.RequestScriptElement; +import at.gv.egiz.stal.ext.APDUScriptResponse; +import at.gv.egiz.stal.service.translator.STALTranslator; +import at.gv.egiz.stal.service.translator.TranslationException; +import at.gv.egiz.stal.service.types.RequestType; +import at.gv.egiz.stal.service.types.ResponseType; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.xml.bind.JAXBElement; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at> + */ +public class STALXTranslationHandler implements STALTranslator.TranslationHandler { + + private static final Log log = LogFactory.getLog(STALXTranslationHandler.class); + ObjectFactory of; + + public STALXTranslationHandler() { + of = new ObjectFactory(); + } + + @Override + public List<Class> getSupportedTypes() { + return Arrays.asList(new Class[]{ScriptType.class, + ResponseType.class, + APDUScriptRequest.class, + APDUScriptResponse.class}); + } + + @Override + public JAXBElement<? extends RequestType> translate(STALRequest request) throws TranslationException { + if (request instanceof APDUScriptRequest) { + log.trace("translate at.gv.egiz.stal.ext.APDUScriptRequest -> at.buergerkarte.namespaces.cardchannel.service.ScriptType"); + + ScriptType scriptT = of.createScriptType(); + + List<RequestScriptElement> script = ((APDUScriptRequest) request).getScript(); + for (RequestScriptElement requestScriptElement : script) { + if (requestScriptElement instanceof APDUScriptRequest.Reset) { + scriptT.getResetOrCommandAPDUOrVerifyAPDU().add(of.createResetType()); + } else if (requestScriptElement instanceof APDUScriptRequest.Command) { + APDUScriptRequest.Command cmd = (APDUScriptRequest.Command) requestScriptElement; + CommandAPDUType commandAPDUType = of.createCommandAPDUType(); + commandAPDUType.setSequence(BigInteger.valueOf(cmd.getSequence())); + commandAPDUType.setValue(cmd.getCommandAPDU()); + commandAPDUType.setExpectedSW(cmd.getExpectedSW()); + scriptT.getResetOrCommandAPDUOrVerifyAPDU().add(commandAPDUType); + } else { + log.error("invalid requestScriptElement " + requestScriptElement.getClass()); + throw new TranslationException(requestScriptElement.getClass()); + } + } + + return of.createScript(scriptT); + } else { + log.error("cannot translate " + request.getClass()); + throw new TranslationException(request.getClass()); + } + } + + @Override + public STALRequest translate(RequestType request) throws TranslationException { + if (request instanceof ScriptType) { + + log.trace("translate at.buergerkarte.namespaces.cardchannel.service.ScriptType -> at.gv.egiz.stal.ext.APDUScriptRequest"); + + List<Object> resetOrCommandAPDUOrVerifyAPDU = ((ScriptType) request).getResetOrCommandAPDUOrVerifyAPDU(); + List<APDUScriptRequest.RequestScriptElement> requestScript = new ArrayList<APDUScriptRequest.RequestScriptElement>(); + + for (Object element : resetOrCommandAPDUOrVerifyAPDU) { + + if (element instanceof ResetType) { + + requestScript.add(new APDUScriptRequest.Reset()); + + } else if (element instanceof CommandAPDUType) { + + CommandAPDUType commandAPDU = (CommandAPDUType) element; + int sequence = (commandAPDU.getSequence() != null) + ? commandAPDU.getSequence().intValue() + : 0; + + requestScript.add( + new APDUScriptRequest.Command( + sequence, + commandAPDU.getValue(), + commandAPDU.getExpectedSW())); + + } else if (element instanceof VerifyAPDUType) { + log.error("CardChannel script command 'VerifyAPDU' not implemented."); + throw new TranslationException(VerifyAPDUType.class); + } else { + log.error("invalid requestScriptElement element " + element.getClass()); + throw new TranslationException(element.getClass()); + } + } + + return new APDUScriptRequest(requestScript); + + } else { + log.error("cannot translate " + request.getClass()); + throw new TranslationException(request.getClass()); + } + } + + @Override + public JAXBElement<? extends ResponseType> translate(STALResponse response) throws TranslationException { + if (response instanceof APDUScriptResponse) { + log.trace("translate at.gv.egiz.stal.ext.APDUScriptResponse -> at.buergerkarte.namespaces.cardchannel.service.ResponseType"); + at.buergerkarte.namespaces.cardchannel.service.ResponseType responseT = of.createResponseType(); + List<APDUScriptResponse.ResponseScriptElement> responseScript = ((APDUScriptResponse) response).getScript(); + + for (APDUScriptResponse.ResponseScriptElement element : responseScript) { + + if (element instanceof APDUScriptResponse.ATR) { + + byte[] atr = ((APDUScriptResponse.ATR) element).getAtr(); + + ATRType atrType = of.createATRType(); + atrType.setValue(atr); + atrType.setRc(BigInteger.ZERO); + responseT.getATROrResponseAPDU().add(atrType); + + } else if (element instanceof APDUScriptResponse.Response) { + + APDUScriptResponse.Response resp = (APDUScriptResponse.Response) element; + + ResponseAPDUType responseAPDUType = of.createResponseAPDUType(); + responseAPDUType.setSequence(BigInteger.valueOf(resp.getSequence())); + responseAPDUType.setRc(BigInteger.valueOf(resp.getRc())); + responseAPDUType.setSW(resp.getSw()); + responseAPDUType.setValue(resp.getApdu()); + + responseT.getATROrResponseAPDU().add(responseAPDUType); + } else { + log.error("invalid responseScriptElement " + element.getClass()); + throw new TranslationException(element.getClass()); + } + } + return of.createResponse(responseT); + } else { + log.error("cannot translate " + response.getClass()); + throw new TranslationException(response.getClass()); + } + } + + @Override + public STALResponse translate(ResponseType response) throws TranslationException { + if (response instanceof at.buergerkarte.namespaces.cardchannel.service.ResponseType) { + log.trace("translate at.buergerkarte.namespaces.cardchannel.service.ResponseType -> at.gv.egiz.stal.ext.APDUScriptResponse"); + + List<Object> atrOrResponseAPDU = ((at.buergerkarte.namespaces.cardchannel.service.ResponseType) response).getATROrResponseAPDU(); + List<APDUScriptResponse.ResponseScriptElement> responseScript = new ArrayList<APDUScriptResponse.ResponseScriptElement>(); + + for (Object object : atrOrResponseAPDU) { + if (object instanceof ATRType) { + byte[] atr = ((ATRType) object).getValue(); + responseScript.add(new APDUScriptResponse.ATR(atr)); + } else if (object instanceof ResponseAPDUType) { + ResponseAPDUType respAPDU = (ResponseAPDUType) object; + int sequence = (respAPDU.getSequence() != null) + ? respAPDU.getSequence().intValue() + : 0; + int rc = (respAPDU.getRc() != null) + ? respAPDU.getRc().intValue() + : 0; + responseScript.add(new APDUScriptResponse.Response(sequence, + respAPDU.getValue(), + respAPDU.getSW(), + rc)); + } else { + log.error("invalid responseScriptElement " + object.getClass()); + throw new TranslationException(object.getClass()); + } + } + return new APDUScriptResponse(responseScript); + + } else { + log.error("cannot translate " + response.getClass()); + throw new TranslationException(response.getClass()); + } + } +} |