+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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 org.argeo.slc.server.client.impl;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
+import java.net.Authenticator;
import java.net.HttpURLConnection;
+import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
public abstract class AbstractHttpServicesClient implements HttpServicesClient {
private final static Log log = LogFactory
.getLog(AbstractHttpServicesClient.class);
+
+ private String user;
+ private String password;
+
private Unmarshaller unmarshaller;
private Marshaller marshaller;
private String baseUrl;
private Long retryPeriod = 1000l;
private Long defaultTimeout = 30 * 1000l;
+ public void init() {
+ if (user != null && password != null)
+ Authenticator.setDefault(new Authenticator() {
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(user, password
+ .toCharArray());
+ }
+ });
+ }
+
@SuppressWarnings(value = { "unchecked" })
public <T> T callService(String path, Map<String, String> parameters) {
- return (T)callService(path, parameters, null);
+ return (T) callService(path, parameters, null);
}
@SuppressWarnings(value = { "unchecked" })
protected Object callServiceLowLevel(String path,
Map<String, String> parameters, Object body) throws IOException {
+
Assert.notNull(baseUrl, "base url");
HttpURLConnection connection = null;
Writer writer = null;
return defaultTimeout;
}
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
}