/*
* Copyright 2009 Alberto Gimeno <gimenete at gmail.com>
*
* 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 siena.remote;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
import siena.SienaException;
public class URLConnector implements Connector {
private URL backend;
private URLConnection connection;
public void configure(Properties p) {
try {
backend = new URL(p.getProperty("backend"));
} catch (MalformedURLException e) {
throw new SienaException(e);
}
}
public void close() throws IOException {
}
public void connect() throws IOException {
connection = backend.openConnection();
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
connection.setDoOutput(true);
}
public InputStream getInputStream() throws IOException {
return connection.getInputStream();
}
public OutputStream getOutputStream() throws IOException {
return connection.getOutputStream();
}
}