Skip to content

Commit befdfa3

Browse files
author
arnett, stu
committed
v2.0.5
1 parent bd5e16f commit befdfa3

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2015, EMC Corporation.
3+
* Redistribution and use in source and binary forms, with or without modification,
4+
* are permitted provided that the following conditions are met:
5+
*
6+
* + Redistributions of source code must retain the above copyright notice,
7+
* this list of conditions and the following disclaimer.
8+
* + Redistributions in binary form must reproduce the above copyright
9+
* notice, this list of conditions and the following disclaimer in the
10+
* documentation and/or other materials provided with the distribution.
11+
* + The name of EMC Corporation may not be used to endorse or promote
12+
* products derived from this software without specific prior written
13+
* permission.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
19+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
* POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
package com.emc.rest.smart;
28+
29+
import com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider;
30+
import com.sun.jersey.spi.inject.Injectable;
31+
32+
import javax.ws.rs.Consumes;
33+
import javax.ws.rs.Produces;
34+
import javax.ws.rs.WebApplicationException;
35+
import javax.ws.rs.core.Context;
36+
import javax.ws.rs.core.MediaType;
37+
import javax.ws.rs.core.MultivaluedMap;
38+
import javax.ws.rs.ext.MessageBodyReader;
39+
import javax.ws.rs.ext.Providers;
40+
import javax.xml.bind.annotation.XmlRootElement;
41+
import javax.xml.bind.annotation.XmlType;
42+
import javax.xml.parsers.SAXParserFactory;
43+
import java.io.IOException;
44+
import java.io.InputStream;
45+
import java.lang.annotation.Annotation;
46+
import java.lang.reflect.Type;
47+
48+
@Produces("application/octet-stream")
49+
@Consumes("application/octet-stream")
50+
public class OctetStreamXmlProvider implements MessageBodyReader<Object> {
51+
private MessageBodyReader<Object> delegate;
52+
53+
public OctetStreamXmlProvider(@Context Injectable<SAXParserFactory> spf, @Context Providers ps) {
54+
this.delegate = new XMLRootElementProvider.General(spf, ps);
55+
}
56+
57+
@Override
58+
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
59+
return (type.getAnnotation(XmlRootElement.class) != null || type.getAnnotation(XmlType.class) != null)
60+
&& mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE);
61+
}
62+
63+
@Override
64+
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
65+
return delegate.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
66+
}
67+
}

src/main/java/com/emc/rest/smart/SmartClientFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public static Client createStandardClient(SmartConfig smartConfig,
102102
clientConfig.getClasses().add(FileProvider.class);
103103
clientConfig.getClasses().add(InputStreamProvider.class);
104104

105+
// add support for XML with no content-type
106+
clientConfig.getClasses().add(OctetStreamXmlProvider.class);
107+
105108
// build Jersey client
106109
return new Client(clientHandler, clientConfig);
107110
}

src/main/java/com/emc/rest/smart/ecs/Vdc.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ public int hashCode() {
8989
return getName().hashCode();
9090
}
9191

92+
@Override
93+
public String toString() {
94+
String hostsString = "";
95+
if (hosts != null) {
96+
for (Host host : hosts) {
97+
if (hostsString.length() > 0) hostsString += ",";
98+
hostsString += host.getName();
99+
}
100+
}
101+
return name + '(' + hostsString + ')';
102+
}
103+
92104
public String getName() {
93105
return name;
94106
}

0 commit comments

Comments
 (0)