perfsonar-dev - perfsonar: r5315 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: level0 level1 level2
Subject: perfsonar development work
List archive
perfsonar: r5315 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: level0 level1 level2
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5315 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: level0 level1 level2
- Date: Mon, 19 Oct 2009 04:41:01 -0400
Author: krzjed
Date: 2009-10-19 04:41:00 -0400 (Mon, 19 Oct 2009)
New Revision: 5315
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level2/Level2Impl.java
Log:
some lesser bugs removed
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java
2009-10-15 14:31:02 UTC (rev 5314)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/Level0Impl.java
2009-10-19 08:41:00 UTC (rev 5315)
@@ -76,7 +76,7 @@
message.getSOAPBody().addDocument(document);
} catch (SOAPException e) {
logger.error("Can't create a message", e);
- new LsQueryException(e);
+ throw new LsQueryException(e);
}
return message;
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java
2009-10-15 14:31:02 UTC (rev 5314)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/SOAPEndpoint.java
2009-10-19 08:41:00 UTC (rev 5315)
@@ -18,98 +18,117 @@
import org.apache.log4j.Logger;
-
public class SOAPEndpoint {
- protected final Logger logger = Logger.getLogger(getClass());
+ protected final Logger logger = Logger.getLogger(getClass());
- private URL endPoint;
-
- public SOAPEndpoint(URL url) {
- if(url==null) {
- throw new IllegalArgumentException("Url can't be
null");
- }
- if (!url.getProtocol().equalsIgnoreCase("http") &&
!url.getProtocol().equalsIgnoreCase("https")) {
- throw new IllegalArgumentException("Protocol " +
url.getProtocol() + " not supported only http/https sorry");
+ private URL endPoint;
+
+ public SOAPEndpoint(URL url) {
+ if (url == null) {
+ throw new IllegalArgumentException("Url can't be null");
}
- this.endPoint = url;
- }
-
- public InputStream send(SOAPMessage message) throws SOAPException,
IOException {
- HttpURLConnection httpConnection = prepareConnection();
-
- setSoapMineHeader(message);
-
- if (message.saveRequired()) {
+ if (!url.getProtocol().equalsIgnoreCase("http")
+ && !url.getProtocol().equalsIgnoreCase("https")) {
+ throw new IllegalArgumentException("Protocol " +
url.getProtocol()
+ + " not supported only http/https sorry");
+ }
+ this.endPoint = url;
+ }
+
+ public InputStream send(SOAPMessage message) throws SOAPException,
+ IOException {
+ HttpURLConnection httpConnection = prepareConnection();
+
+ setSoapMineHeader(message);
+
+ if (message.saveRequired()) {
message.saveChanges();
- }
-
- boolean hasAuth = processMesageHeaders(message,
httpConnection);
-
- String userInfo = endPoint.getUserInfo();
-
- if (!hasAuth && userInfo != null) {
- initAuthUserInfo(httpConnection, userInfo);
- }
-
- sendMessage(message, httpConnection);
-
- boolean success = checkResponse(httpConnection);
- InputStream httpIn = (success ? httpConnection.getInputStream() :
httpConnection.getErrorStream());
-
- if(logger.isInfoEnabled()) {
- Reader reader = new InputStreamReader(httpIn);
- StringBuilder builder = new StringBuilder();
- int i; while((i = reader.read())!=-1) builder.append((char)i);
- logger.info("Recieved Message ["+builder.toString()+"]");
- httpIn = new
ByteArrayInputStream(builder.toString().getBytes());
}
-
+
+ boolean hasAuth = processMesageHeaders(message, httpConnection);
+
+ String userInfo = endPoint.getUserInfo();
+
+ if (!hasAuth && userInfo != null) {
+ initAuthUserInfo(httpConnection, userInfo);
+ }
+
+ sendMessage(message, httpConnection);
+
+ boolean success = checkResponse(httpConnection);
+ InputStream httpIn = (success ? httpConnection.getInputStream()
+ : httpConnection.getErrorStream());
+
+ if (logger.isInfoEnabled()) {
+ StringBuilder builder = new StringBuilder();
+ Reader reader = new InputStreamReader(httpIn);
+ try {
+ int i;
+ while ((i = reader.read()) != -1) {
+ builder.append((char) i);
+ }
+ } finally {
+ reader.close();
+ httpIn.close();
+ }
+ logger.info("Recieved Message [" + builder.toString() + "]");
+ httpIn = new ByteArrayInputStream(builder.toString().getBytes());
+ }
+
return httpIn;
- }
+ }
- /**
- * Either something went wrong while converting the other code(SAAJ)
- * or I'm missing something.
- * @param message
- */
- protected void setSoapMineHeader(SOAPMessage message) {
- String[] soapAction =
message.getMimeHeaders().getHeader("SOAPAction");
+ /**
+ * Either something went wrong while converting the other code(SAAJ) or
I'm
+ * missing something.
+ *
+ * @param message
+ */
+ protected void setSoapMineHeader(SOAPMessage message) {
+ String[] soapAction =
message.getMimeHeaders().getHeader("SOAPAction");
if (soapAction == null || soapAction.length == 0) {
- message.getMimeHeaders().setHeader("SOAPAction", "\"\"");
+ message.getMimeHeaders().setHeader("SOAPAction", "\"\"");
}
- }
+ }
- protected void sendMessage(SOAPMessage message, HttpURLConnection
httpConnection) throws IOException, SOAPException {
- if(logger.isInfoEnabled()) {
- ByteArrayOutputStream log = new
ByteArrayOutputStream();
- message.writeTo(log);
- logger.info("Sending message
["+log.toString("UTF-8")+"]");
- }
- OutputStream out = httpConnection.getOutputStream();
+ protected void sendMessage(SOAPMessage message,
+ HttpURLConnection httpConnection) throws IOException,
SOAPException {
+ if (logger.isInfoEnabled()) {
+ ByteArrayOutputStream log = new ByteArrayOutputStream();
+ message.writeTo(log);
+ logger.info("Sending message [" + log.toString("UTF-8") + "]");
+ }
+ OutputStream out = httpConnection.getOutputStream();
httpConnection.connect();
- message.writeTo(out);
+ message.writeTo(out);
out.flush();
out.close();
- }
-
- private boolean checkResponse(HttpURLConnection httpConnection)
throws SOAPException, IOException {
- logger.info("cheching result code of request
(connection["+httpConnection+"])");
- int responseCode = httpConnection.getResponseCode();
+ }
- logger.info("Responsecode for connection["+httpConnection+"]
is "+responseCode);
- // let HTTP_INTERNAL_ERROR (500) through because it is used for SOAP
faults
+ private boolean checkResponse(HttpURLConnection httpConnection)
+ throws SOAPException, IOException {
+ logger.info("cheching result code of request (connection["
+ + httpConnection + "])");
+ int responseCode = httpConnection.getResponseCode();
+
+ logger.info("Responsecode for connection[" + httpConnection + "] is "
+ + responseCode);
+ // let HTTP_INTERNAL_ERROR (500) through because it is used for SOAP
+ // faults
if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
return false;
}
// else if (responseCode != HttpURLConnection.HTTP_OK)
- // else if (!(responseCode >= HttpURLConnection.HTTP_OK &&
responseCode < 207))
+ // else if (!(responseCode >= HttpURLConnection.HTTP_OK &&
responseCode
+ // < 207))
else if ((responseCode / 100) != 2) {
- throw new SOAPException("Bad response: ("+ responseCode +
httpConnection.getResponseMessage()+")");
- }
+ throw new SOAPException("Bad response: (" + responseCode
+ + httpConnection.getResponseMessage() + ")");
+ }
return true;
- }
+ }
- private void initAuthUserInfo(HttpURLConnection conn, String
userInfo) {
+ private void initAuthUserInfo(HttpURLConnection conn, String userInfo) {
String user;
String password;
if (userInfo != null) {
@@ -124,56 +143,63 @@
String plain = user + ":";
byte[] nameBytes = plain.getBytes();
- byte[] passwdBytes = (password!=null) ? password.getBytes() :
new byte[]{};
+ byte[] passwdBytes = (password != null) ? password.getBytes()
+ : new byte[] {};
// concatenate user name and password bytes and encode them
byte[] concat = new byte[nameBytes.length + passwdBytes.length];
System.arraycopy(nameBytes, 0, concat, 0, nameBytes.length);
- System.arraycopy(passwdBytes, 0, concat, nameBytes.length,
passwdBytes.length);
+ System.arraycopy(passwdBytes, 0, concat, nameBytes.length,
+ passwdBytes.length);
String auth = "Basic " + new String(Base64.encode(concat));
conn.setRequestProperty("Authorization", auth);
}
}
- @SuppressWarnings("unchecked") // should be save
- private boolean processMesageHeaders(SOAPMessage message,
HttpURLConnection httpConnection) {
- boolean hasAuth = false;
- MimeHeaders headers = message.getMimeHeaders();
- for(Iterator<MimeHeader> it = headers.getAllHeaders();it.hasNext();)
{
+ @SuppressWarnings("unchecked")
+ // should be save
+ private boolean processMesageHeaders(SOAPMessage message,
+ HttpURLConnection httpConnection) {
+ boolean hasAuth = false;
+ MimeHeaders headers = message.getMimeHeaders();
+ for (Iterator<MimeHeader> it = headers.getAllHeaders();
it.hasNext();) {
MimeHeader header = it.next();
-
+
String[] values = headers.getHeader(header.getName());
- httpConnection.setRequestProperty(header.getName(),
createCommaSeperatedList(values));
+ httpConnection.setRequestProperty(header.getName(),
+ createCommaSeperatedList(values));
if ("Authorization".equals(header.getName())) {
hasAuth = true;
}
}
return hasAuth;
- }
+ }
- private String createCommaSeperatedList(String[] values) {
- if(values.length == 1) {
- return values[0];
- }
-
- StringBuffer concat = new StringBuffer();
- int i = 0;
- while (i < values.length) {
- if (i != 0) {
- concat.append(',');
- }
- concat.append(values[i]);
- i++;
- }
- String value = concat.toString();
- return value;
- }
-
- protected HttpURLConnection prepareConnection() throws IOException {
- logger.info("Setting connection settings[ Method:POST
allowUserInteraction:false DoOutput:true DoInput:true UserCaches:false
Timeout:5000msec FollowRedirects:true ]");
- HttpURLConnection httpConnection = (HttpURLConnection)
endPoint.openConnection();
+ private String createCommaSeperatedList(String[] values) {
+ if (values.length == 1) {
+ return values[0];
+ }
+
+ StringBuffer concat = new StringBuffer();
+ int i = 0;
+ while (i < values.length) {
+ if (i != 0) {
+ concat.append(',');
+ }
+ concat.append(values[i]);
+ i++;
+ }
+ String value = concat.toString();
+ return value;
+ }
+
+ protected HttpURLConnection prepareConnection() throws IOException {
+ logger
+ .info("Setting connection settings[ Method:POST
allowUserInteraction:false DoOutput:true DoInput:true UserCaches:false
Timeout:5000msec FollowRedirects:true ]");
+ HttpURLConnection httpConnection = (HttpURLConnection) endPoint
+ .openConnection();
httpConnection.setRequestMethod("POST");
httpConnection.setAllowUserInteraction(false);
httpConnection.setDoOutput(true);
@@ -182,5 +208,5 @@
httpConnection.setConnectTimeout(5000);
httpConnection.setInstanceFollowRedirects(true);
return httpConnection;
- }
+ }
}
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
2009-10-15 14:31:02 UTC (rev 5314)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
2009-10-19 08:41:00 UTC (rev 5315)
@@ -64,7 +64,7 @@
}
public void remove() {
- new UnsupportedOperationException("Can't remove steps");
+ throw new UnsupportedOperationException("Can't remove
steps");
}
};
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java
2009-10-15 14:31:02 UTC (rev 5314)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/Level1Impl.java
2009-10-19 08:41:00 UTC (rev 5315)
@@ -12,7 +12,6 @@
import org.apache.log4j.Logger;
import org.perfsonar.lsclient.DiscoveryProcess;
import org.perfsonar.lsclient.Level0LsClientInterface;
-import org.perfsonar.lsclient.Level1LsClientInterface;
import org.perfsonar.lsclient.LsQueryException;
import org.perfsonar.lsclient.data.AuthorativeLookupservice;
import org.perfsonar.lsclient.data.EventType;
@@ -29,8 +28,7 @@
import org.perfsonar.ri.lsclient.xml.ResponseParser;
import org.xml.sax.SAXException;
-public class Level1Impl extends AbstractLevel1 implements
- Level1LsClientInterface {
+public class Level1Impl extends AbstractLevel1 {
private static final String EAGER_SYSTEM_KEY =
"application.perfsonar.lsclient.eagerRootLses";
@@ -79,26 +77,18 @@
AuthorativeLookupservice hls, Set<TopologyElement> elements,
Set<EventType> eventTypes, Set<ServiceType> type) {
if (logger.isDebugEnabled()) {
- logger
- .debug("quering LS for service content from "
- + hls.getEndPoint() + " where"
- + " topologyElements is any " + elements == null
? ""
- : Arrays.toString(elements.toArray())
- + " eventypes is any " + eventTypes ==
null ? ""
- : Arrays.toString(eventTypes.toArray())
- + " serviceType is any " + type
== null ? ""
- :
Arrays.toString(type.toArray()));
+ logger.debug("quering LS for service content from "
+ + hls.getEndPoint() + " where topologyElements is any "
+ + elements == null ? "" : Arrays.toString(elements
+ .toArray())
+ + " eventypes is any " + eventTypes == null ? "" : Arrays
+ .toString(eventTypes.toArray())
+ + " serviceType is any " + type == null ? "" : Arrays
+ .toString(type.toArray()));
}
- LsTopologyQuery query = new LsTopologyQuery(elements, eventTypes,
type) {
- @Override
- public String toString() {
- return null;
- }
- };
Set<ServiceImpl> services;
try {
- InputStream stream = level0
- .getRawQueryResult(hls, query.toString());
+ InputStream stream = level0.getRawQueryResult(hls, null);
ServiceCollectionHandler sch = new ServiceCollectionHandler();
ResponseParser.parseDiscoveryResponse(stream, sch);
services = sch.getMetadataSet();
@@ -136,8 +126,7 @@
if (logger.isDebugEnabled()) {
logger.debug("quering LS for service locations from "
+ hls.getEndPoint()
- + " where"
- + " topologyElements is any "
+ + " where topologyElements is any "
+ (elements == null ? "" : Arrays.toString(elements
.toArray()))
+ " eventypes is any "
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level2/Level2Impl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level2/Level2Impl.java
2009-10-15 14:31:02 UTC (rev 5314)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level2/Level2Impl.java
2009-10-19 08:41:00 UTC (rev 5315)
@@ -5,10 +5,11 @@
import org.perfsonar.lsclient.Level2LsClientInterface;
import org.perfsonar.lsclient.helpers.AbstractLevel2;
-public class Level2Impl extends AbstractLevel2 implements
Level2LsClientInterface {
+public class Level2Impl extends AbstractLevel2 {
- public Level2Impl(Level0LsClientInterface level0,
Level1LsClientInterface level1) {
- super(level0, level1);
- }
+ public Level2Impl(Level0LsClientInterface level0,
+ Level1LsClientInterface level1) {
+ super(level0, level1);
+ }
}
- perfsonar: r5315 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: level0 level1 level2, svnlog, 10/19/2009
Archive powered by MHonArc 2.6.16.