本文整理汇总了Java中org.restlet.representation.StringRepresentation类的典型用法代码示例。如果您正苦于以下问题:Java StringRepresentation类的具体用法?Java StringRepresentation怎么用?Java StringRepresentation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringRepresentation类属于org.restlet.representation包,在下文中一共展示了StringRepresentation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePost
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
@Post("json")
public Representation handlePost(Representation entity) {
String path = getReference().getPath();
String dbname = getDatabaseName(path);
if (!dbNameExists(dbname)) {
return databaseNotFound();
}
else if (path.endsWith("/_revs_diff")) {
return handleRevsDiff(dbname);
}
else if (path.endsWith("/_ensure_full_commit")) {
return handleEnsureFullCommitPost(dbname);
}
else if (path.endsWith("/_bulk_docs")) {
return handleBulkDocsPost(dbname);
}
else {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("{\"message\": \"Server error for request: " + getMethod() + " " + path + "\"}", MediaType.TEXT_PLAIN);
}
}
示例2: handlePut
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
@Put("json")
public Representation handlePut(Representation entity) {
String path = getReference().getPath();
String dbname = getDatabaseName(path);
String pathWithFirstAndLastSlashRemoved = path.replaceAll("^/", "").replaceAll("/$", "");
if (pathWithFirstAndLastSlashRemoved.equals(dbname)) {
// must be a PUT /target request
return handleCreateTargetPut(dbname);
}
else if (!dbNameExists(dbname)) {
return databaseNotFound();
}
else if (path.contains("/_local/")) {
return handleLocalPut(dbname);
} else {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("{\"message\": \"Server error for request: " + getMethod() + " " + path + "\"}", MediaType.TEXT_PLAIN);
}
}
示例3: put
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
@Override
@Put("json")
public Representation put(Representation entity) {
try {
String jsonRequest = entity.getText();
TopicPartition topicPartitionInfo = TopicPartition.init(jsonRequest);
if (_autoTopicWhitelistingManager != null) {
_autoTopicWhitelistingManager.removeFromBlacklist(topicPartitionInfo.getTopic());
}
if (_helixMirrorMakerManager.isTopicExisted(topicPartitionInfo.getTopic())) {
_helixMirrorMakerManager.expandTopicInMirrorMaker(topicPartitionInfo);
return new StringRepresentation(
String.format("Successfully expand topic: %s", topicPartitionInfo));
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(String.format(
"Failed to expand topic, topic: %s is not existed!", topicPartitionInfo.getTopic()));
}
} catch (IOException e) {
LOGGER.error("Got error during processing Put request", e);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation(
String.format("Failed to expand topic, with exception: %s", e));
}
}
示例4: delete
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
@Override
@Delete
public Representation delete() {
final String topicName = (String) getRequest().getAttributes().get("topicName");
if (_autoTopicWhitelistingManager != null) {
_autoTopicWhitelistingManager.addIntoBlacklist(topicName);
}
if (!_helixMirrorMakerManager.isTopicExisted(topicName)) {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(
String.format("Failed to delete not existed topic: %s", topicName));
}
try {
_helixMirrorMakerManager.deleteTopicInMirrorMaker(topicName);
return new StringRepresentation(
String.format("Successfully finished delete topic: %s", topicName));
} catch (Exception e) {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
LOGGER.error("Failed to delete topic: {}, with exception: {}", topicName, e);
return new StringRepresentation(
String.format("Failed to delete topic: %s, with exception: %s", topicName, e));
}
}
示例5: get
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
@Override
@Get
public Representation get() {
final String opt = (String) getRequest().getAttributes().get("opt");
if ("disable_autobalancing".equalsIgnoreCase(opt)) {
_helixMirrorMakerManager.disableAutoBalancing();
LOGGER.info("Disabled autobalancing!");
return new StringRepresentation("Disabled autobalancing!\n");
} else if ("enable_autobalancing".equalsIgnoreCase(opt)) {
_helixMirrorMakerManager.enableAutoBalancing();
LOGGER.info("Enabled autobalancing!");
return new StringRepresentation("Enabled autobalancing!\n");
}
LOGGER.info("No valid input!");
return new StringRepresentation("No valid input!\n");
}
示例6: get
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
@Override
@Get
public Representation get() {
final String option = (String) getRequest().getAttributes().get("option");
if ("srcKafka".equals(option)) {
if (_srcKafkaValidationManager == null) {
LOGGER.warn("SourceKafkaClusterValidationManager is null!");
return new StringRepresentation("SrcKafkaValidationManager is not been initialized!");
}
LOGGER.info("Trying to call validation on source kafka cluster!");
return new StringRepresentation(_srcKafkaValidationManager.validateSourceKafkaCluster());
} else {
LOGGER.info("Trying to call validation on current cluster!");
return new StringRepresentation(_validationManager.validateExternalView());
}
}
示例7: getWebRepresentation
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
/**
* Returns a representation of the list in "text/html" format.
*
* @return A representation of the list in "text/html" format.
*/
public Representation getWebRepresentation() {
// Create a simple HTML list
final StringBuilder sb = new StringBuilder();
sb.append("<html><body style=\"font-family: sans-serif;\">\n");
if (getIdentifier() != null) {
sb.append("<h2>Listing of \"" + getIdentifier().getPath()
+ "\"</h2>\n");
final Reference parentRef = getIdentifier().getParentRef();
if (!parentRef.equals(getIdentifier())) {
sb.append("<a href=\"" + parentRef + "\">..</a><br>\n");
}
} else {
sb.append("<h2>List of references</h2>\n");
}
for (final Reference ref : this) {
sb.append("<a href=\"" + ref.toString() + "\">"
+ ref.getRelativeRef(getIdentifier()) + "</a><br>\n");
}
sb.append("</body></html>\n");
return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML);
}
示例8: writeResponse
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
@Override
public boolean writeResponse( final Object result, final Response response )
throws ResourceException
{
MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType();
if( MediaType.APPLICATION_JSON.equals( type ) )
{
if( result instanceof String || result instanceof Number || result instanceof Boolean )
{
StringRepresentation representation = new StringRepresentation( result.toString(),
MediaType.APPLICATION_JSON );
response.setEntity( representation );
return true;
}
}
return false;
}
示例9: testOfCtlCall
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
/**
* Test method for
* {@link org.o3project.ocnrm.ofctl.OfCtlSender#ofCtlCall()}
*/
@Test
public void testOfCtlCall() throws Exception {
Logger dummyLogger = mock(Logger.class);
Field field = target.getClass().getSuperclass().getDeclaredField("logger");
field.setAccessible(true);
field.set(target, dummyLogger);
String param = "param";
String method = "method";
Representation dummyRepresantation = mock(Representation.class);
when(dummyRepresantation.toString()).thenReturn("dummy");
ClientResource dummyClient = mock(ClientResource.class);
doReturn(dummyRepresantation).when(dummyClient).post((StringRepresentation) anyObject());
PowerMockito.whenNew(ClientResource.class).withAnyArguments().thenReturn(dummyClient);
Whitebox.setInternalState(target, "seqNo", seqNo);
Whitebox.invokeMethod(target, "ofCtlCall", param, method);
verify(dummyLogger, times(1)).info(seqNo + "\t" + "ofCtlCall End");
}
示例10: testOfCtlCallWithNullRepresentation
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
/**
* Test method for
* {@link org.o3project.ocnrm.ofctl.OfCtlSender#ofCtlCall()}
*/
@Test
public void testOfCtlCallWithNullRepresentation() throws Exception {
Logger dummyLogger = mock(Logger.class);
Field field = target.getClass().getSuperclass().getDeclaredField("logger");
field.setAccessible(true);
field.set(target, dummyLogger);
String param = "param";
String method = "method";
Representation dummyRepresantation = mock(Representation.class);
when(dummyRepresantation.toString()).thenReturn(null);
ClientResource dummyClient = mock(ClientResource.class);
doReturn(dummyRepresantation).when(dummyClient).post((StringRepresentation) anyObject());
PowerMockito.whenNew(ClientResource.class).withAnyArguments().thenReturn(dummyClient);
Whitebox.setInternalState(target, "seqNo", seqNo);
Whitebox.invokeMethod(target, "ofCtlCall", param, method);
verify(dummyLogger, times(1)).info(seqNo + "\t" + "ofCtlCall End");
verify(dummyLogger, times(1)).error(seqNo + "\t" + "Representation is null.");
}
示例11: testPrivatePostToMf
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
/**
* Test method for
* {@link org.o3project.ocnrm.lib.MFApiCaller#postToMF()}
*/
@Test
public void testPrivatePostToMf() throws Exception {
String path = "path";
String param = "param";
Representation dummyResponse = mock(Representation.class);
PowerMockito.doReturn("result").when(dummyResponse).getText();
ClientResource dummyClient = mock(ClientResource.class);
doNothing().when(dummyClient).setNext((Uniform) anyObject());
StringRepresentation rep = spy(new StringRepresentation(param.toCharArray()));
PowerMockito.whenNew(StringRepresentation.class).withAnyArguments().thenReturn(rep);
doReturn(dummyResponse).when(dummyClient).post(eq(rep));
PowerMockito.whenNew(ClientResource.class).withAnyArguments().thenReturn(dummyClient);
String result = Whitebox.invokeMethod(target, "postToMF", path, param, seqNo);
assertThat(result, is("result"));
}
示例12: subscribeDescription
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
public Representation subscribeDescription(Representation entity, String acceptType) throws ResourceException, IOException, JAXBException {
//read NGSI description
InputStream description = new ByteArrayInputStream(entity.getText().getBytes());
// String contentType = entity.getMediaType().getSubType();
// System.out.println("Content-Type is: " + contentType);
// System.out.println("Accept: " + acceptType);
//register description
StringRepresentation subRespMsg = null;
// if (contentType.equalsIgnoreCase(MediaType.APPLICATION_JSON.getSubType())) {
//if request payload is JSON
subRespMsg = subscribeJsonHandler(description, acceptType);
// } else {
// //request payload is XML
// subRespMsg = subscribeXmlHandler(description, acceptType);
// }
// System.out.println("Respose To Send: \n" + regRespMsg.getText() + "\n");
return subRespMsg;
}
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:22,代码来源:Resource03_AvailabilitySubscription.java
示例13: subscribeDescription
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
public Representation subscribeDescription(Representation entity, String acceptType) throws ResourceException, IOException, JAXBException {
//read NGSI description
InputStream description = new ByteArrayInputStream(entity.getText().getBytes());
String contentType = entity.getMediaType().getSubType();
// System.out.println("Content-Type is: " + contentType);
// System.out.println("Accept: " + acceptType);
//update subscription
StringRepresentation updSubRespMsg = null;
// if (contentType.equalsIgnoreCase(MediaType.APPLICATION_JSON.getSubType())) {
//if request payload is JSON
updSubRespMsg = subscribeJsonHandler(description, acceptType);
// } else {
// //request payload is XML
// updSubRespMsg = subscribeXmlHandler(description, acceptType);
// }
// System.out.println("Respose To Send: \n" + regRespMsg.getText() + "\n");
return updSubRespMsg;
}
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:22,代码来源:Resource04_AvailabilitySubscriptionUpdate.java
示例14: unsubscribeToDescription
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
public Representation unsubscribeToDescription(Representation entity, String acceptType) throws ResourceException, IOException, JAXBException {
//read NGSI description
InputStream description = new ByteArrayInputStream(entity.getText().getBytes());
String contentType = entity.getMediaType().getSubType();
// System.out.println("Content-Type is: " + contentType);
// System.out.println("Accept: " + acceptType);
//update subscription
StringRepresentation updSubRespMsg = null;
// if (contentType.equalsIgnoreCase(MediaType.APPLICATION_JSON.getSubType())) {
//if request payload is JSON
updSubRespMsg = unsubscribeJsonHandler(description, acceptType);
// } else {
// //request payload is XML
// updSubRespMsg = unsubscribeXmlHandler(description, acceptType);
// }
// System.out.println("Respose To Send: \n" + regRespMsg.getText() + "\n");
return updSubRespMsg;
}
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:22,代码来源:Resource05_AvailabilitySubscriptionDeletion.java
示例15: discoverDescription
import org.restlet.representation.StringRepresentation; //导入依赖的package包/类
public Representation discoverDescription(Representation entity, String acceptType) throws ResourceException, IOException {
//get NGSI discovery request
InputStream discoveryReq = new ByteArrayInputStream(entity.getText().getBytes());
StringRepresentation discRespMsg;//= null;
// String contentType = entity.getMediaType().getSubType();
// System.out.println("Content-Type is: " + contentType);
// System.out.println("Accept: " + acceptType);
// if (contentType.equalsIgnoreCase(MediaType.APPLICATION_JSON.getSubType())) {
//if request payload is JSON
discRespMsg = discoveryJsonHandler(discoveryReq, acceptType);
// } else {
// discRespMsg = discoveryJsonHandler(discoveryReq, acceptType);
// }
// System.out.println("Respose To Send: \n" + discRespMsg.getText() + "\n");
return discRespMsg;
}