Java tutorial
/******************************************************************************* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. ******************************************************************************/ /* * Copyright 2003 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.id.auth.validator.parep.client.szrgw; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import javax.net.ssl.SSLSocketFactory; import org.apache.commons.httpclient.params.HttpConnectionParams; import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; /** * This class implements a secure protocol socket factory * for the Apache HTTP client. * * @author <a href="mailto:peter.danner@egiz.gv.at">Peter Danner</a> */ public class SZRGWSecureSocketFactory implements SecureProtocolSocketFactory { /** * The SSL socket factory. */ private SSLSocketFactory factory; /** * Creates a new Secure socket factory for the * Apache HTTP client. * * @param factory the SSL socket factory to use. */ public SZRGWSecureSocketFactory(SSLSocketFactory factory) { this.factory = factory; } /** * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int) */ public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException { return this.factory.createSocket(host, port, clientHost, clientPort); } /** * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int) */ public Socket createSocket(String host, int port) throws IOException, UnknownHostException { return this.factory.createSocket(host, port); } /** * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean) */ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { return this.factory.createSocket(socket, host, port, autoClose); } /** * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int,org.apache.commons.httpclient.params.HttpConnectionParams) */ public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort, HttpConnectionParams params) throws IOException, UnknownHostException, org.apache.commons.httpclient.ConnectTimeoutException { Socket socket = createSocket(host, port, clientHost, clientPort); if (socket != null) { // socket.setKeepAlive(false); if (params.getReceiveBufferSize() >= 0) socket.setReceiveBufferSize(params.getReceiveBufferSize()); if (params.getSendBufferSize() >= 0) socket.setSendBufferSize(params.getSendBufferSize()); socket.setReuseAddress(true); if (params.getSoTimeout() >= 0) socket.setSoTimeout(params.getSoTimeout()); } return socket; } /** * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { return ((obj != null) && obj.getClass().equals(SZRGWSecureSocketFactory.class)); } /** * @see java.lang.Object#hashCode() */ public int hashCode() { return SZRGWSecureSocketFactory.class.hashCode(); } }