diff options
Diffstat (limited to 'src/test/java/test/at/knowcenter/wag/egov/egiz/detached/BKUPostConnection.java')
-rw-r--r-- | src/test/java/test/at/knowcenter/wag/egov/egiz/detached/BKUPostConnection.java | 230 |
1 files changed, 0 insertions, 230 deletions
diff --git a/src/test/java/test/at/knowcenter/wag/egov/egiz/detached/BKUPostConnection.java b/src/test/java/test/at/knowcenter/wag/egov/egiz/detached/BKUPostConnection.java deleted file mode 100644 index 0c219b8..0000000 --- a/src/test/java/test/at/knowcenter/wag/egov/egiz/detached/BKUPostConnection.java +++ /dev/null @@ -1,230 +0,0 @@ -/**
- * <copyright> Copyright (c) 2006 by Know-Center, Graz, Austria </copyright>
- *
- * This software is the confidential and proprietary information of Know-Center,
- * Graz, Austria. You shall not disclose such Confidential Information and shall
- * use it only in accordance with the terms of the license agreement you entered
- * into with Know-Center.
- *
- * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
- * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
- * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES.
- *
- * $Id: BKUPostConnection.java,v 1.3 2006/10/11 07:56:10 wprinz Exp $
- */
-package test.at.knowcenter.wag.egov.egiz.detached;
-
-import java.io.IOException;
-import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
-import org.apache.commons.httpclient.methods.multipart.FilePart;
-import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
-import org.apache.commons.httpclient.methods.multipart.Part;
-import org.apache.commons.httpclient.methods.multipart.StringPart;
-import org.apache.commons.httpclient.params.HttpMethodParams;
-import org.apache.log4j.Logger;
-
-import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
-
-/**
- * @author wprinz
- */
-public abstract class BKUPostConnection
-{
- /**
- * The logger definition.
- */
- private static final Logger logger_ = ConfigLogger.getLogger(BKUPostConnection.class);
-
- /**
- * This method connects the BKU server getting the request and the url. The
- * request is an XML Message send and recieve by the HttpClient module. The
- * Response message of the BKU server is is send back to the calling method.
- *
- * @param url
- * the URL which the BKU server is running
- * @param request
- * the request string (XML) to send.
- * @return the response string (XML) of the BKU server
- * @throws IOException
- * @throws HttpException
- * ErrorCode:320
- */
-
- public static Properties doPostRequest272(String url, String request,
- byte[] signdata, String mimetype) throws HttpException, IOException
- {
- // // TODO remove write request to File
- // FileOutputStream fos = new
- // FileOutputStream("F:\\PDFAS_SVN\\trunk\\work\\pdfastmp\\bku_request.xml");
- // fos.write(request.getBytes("UTF-8"));
- // fos.close();
-
- StringPart xmlpart = new StringPart("XmlRequest", request, "UTF-8");
- xmlpart.setContentType(null);
- xmlpart.setTransferEncoding(null);
- // BKU 2.7.4 can't handle the Content-Type Header for the XML
- // xmlpart.setContentType("text/xml");
- // xmlpart.setTransferEncoding(null);
-
- String filename = mimetype.equals("application/pdf") ? "myfile.pdf" : "myfile.txt";
- ByteArrayPartSource baps = new ByteArrayPartSource(filename, signdata);
- // FilePart fpart = new FilePart("fileupload",signdata.getName(), signdata);
- FilePart filepart = new FilePart("fileupload", baps);
- filepart.setContentType(mimetype);
-
- // Part[] parts = {fpart, xmlrequest};
- Part[] parts = { xmlpart, filepart };
-
- HttpMethodParams method_params = new HttpMethodParams();
- method_params.setContentCharset("UTF-8");
-
- PostMethod post_method = new PostMethod(url);
- post_method.setParams(method_params);
-
- MultipartRequestEntity mprqe = new MultipartRequestEntity(parts, post_method.getParams());
- post_method.setRequestEntity(mprqe);
-
- HttpClient http_client = new HttpClient();
- int method_response = http_client.executeMethod(post_method);
- logger_.debug("method_response = " + method_response);
-
- Properties response_properties = new Properties();
-
- if (logger_.isDebugEnabled())
- {
- Header[] response_headers = post_method.getResponseHeaders();
- for (int i = 0; i < response_headers.length; i++)
- {
- logger_.debug(" response_header[" + i + "]: name = " + response_headers[i].getName() + ", value = " + response_headers[i].getValue());
- }
- }
- // Header server_header = post_method.getResponseHeader("Server");
-
- // TODO does BKU really send Content-Type Header
- logger_.debug(post_method.getResponseCharSet());
- if (!post_method.getResponseCharSet().equals("UTF-8"))
- {
- logger_.error("BKU response charset is not UTF-8!");
- }
- String response_string = post_method.getResponseBodyAsString();
-
-// byte[] response_body = post_method.getResponseBody();
-// String response_string = new String(response_body, "UTF-8");
-
- response_properties.setProperty("response_string", response_string);
-
- return response_properties;
- }
-
- /**
- * This method connects the BKU server getting the request and the url. The
- * request is an XML Message send and recieve by the HttpClient module. The
- * Response message of the BKU server is is send back to the calling method.
- *
- * @param url
- * the URL which the BKU server is running
- * @param request
- * the request string (XML) to send.
- * @return the response string (XML) of the BKU server
- * @throws IOException
- * @throws HttpException
- * ErrorCode:320
- */
- public static Properties doPostRequest(String url, String request) throws HttpException, IOException
- {
-
- PostMethod post_method = new PostMethod(url);
-
- // It is very important to specify the charset of the content (the request)
- // as UTF-8 this way.
- // The HttpClient will then perform the URL encoding assuming that the
- // request is UTF-8 as the BKU expects.
- // If the MethodParams are omitted, the HttpClient will assume that the
- // request is ISO-8859-1 and thereby the BKU cannot properly decode it.
- HttpMethodParams method_params = new HttpMethodParams();
- method_params.setContentCharset("UTF-8");
- post_method.setParams(method_params);
-
- // This is just a hint: do not set the content-type this way or the BKU will
- // assume it as text/XML, but the HttpClient sends it as URL-encoded.
- // The HttpClient will automatically generate the proper Content-Type:
- // application/x-www-form-urlencoded
- // post.addRequestHeader(new Header("Content-Type",
- // "text/xml;charset=UTF-8"));
-
- NameValuePair[] data = { new NameValuePair("XMLRequest", request) };
- post_method.setRequestBody(data);
-
- HttpClient http_client = new HttpClient();
- int method_response = http_client.executeMethod(post_method);
- logger_.debug("method_response = " + method_response);
-
- Properties response_properties = new Properties();
-
- if (logger_.isDebugEnabled())
- {
- Header[] response_headers = post_method.getResponseHeaders();
- logger_.debug("#" + response_headers.length + " headers in response:");
- for (int i = 0; i < response_headers.length; i++)
- {
- logger_.debug(" response_header[" + i + "]: name = " + response_headers[i].getName() + ", value = " + response_headers[i].getValue());
- }
- }
-
- Header server_header = post_method.getResponseHeader("Server");
- logger_.debug("server_header: name = " + server_header.getName() + ", value = " + server_header.getValue());
- parseBKUVersion(server_header.getValue(), response_properties);
-
- byte[] response_body = post_method.getResponseBody();
- String response_string = new String(response_body, "UTF-8");
-
- // Alternatively this could be used.
- // The HttpClient is assumed to use the Content-Type provided by the
- // response.
- // String response_string = post.getResponseBodyAsString();
-
- response_properties.setProperty("response_string", response_string);
-
- return response_properties;
- }
-
- // TODO hotfix
- public static void parseBKUVersion(String header_value, Properties properties)
- {
- Pattern pattern = Pattern.compile("^citizen-card-environment/(\\d+\\.\\d+) (.+)/(\\d+\\.\\d+\\.\\d+)$");
- Matcher m = pattern.matcher(header_value);
-
- m.matches();
-
- logger_.debug("group count = " + m.groupCount());
-
- for (int i = 0; i <= m.groupCount(); i++)
- {
- logger_.debug(" group[" + i + "] = " + m.group(i));
- }
-
- final String cceVersion = m.group(1);
- final String productName = m.group(2);
- final String productVersion = m.group(3);
-
- logger_.debug("cceVersion = " + cceVersion);
- logger_.debug("productName = " + productName);
- logger_.debug("productVersion = " + productVersion);
-
- properties.setProperty("cceVersion", cceVersion);
- properties.setProperty("productName", productName);
- properties.setProperty("productVersion", productVersion);
- }
-}
|