本文整理汇总了Java中org.raml.model.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于org.raml.model包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exampleResponse
import org.raml.model.Response; //导入依赖的package包/类
@Override
public EndpointRoute exampleResponse(HttpResponseStatus status, Object model, String description) {
Response response = new Response();
response.setDescription(description);
HashMap<String, MimeType> map = new HashMap<>();
response.setBody(map);
MimeType mimeType = new MimeType();
if (model instanceof RestModel) {
String json = JsonUtil.toJson(model);
mimeType.setExample(json);
mimeType.setSchema(JsonUtil.getJsonSchema(model.getClass()));
map.put("application/json", mimeType);
} else {
mimeType.setExample(model.toString());
map.put("text/plain", mimeType);
}
exampleResponses.put(status.code(), response);
exampleResponseClasses.put(status.code(), model.getClass());
return this;
}
示例2: testConvertResponse
import org.raml.model.Response; //导入依赖的package包/类
@Test
public void testConvertResponse() {
Response source = new Response();
source.setDescription("responseDescription");
Map<String, Header> headers = new HashMap<>();
headers.put("testHeader", new Header());
Map<String, MimeType> body = new HashMap<>();
body.put("testBody", new MimeType());
source.setHeaders(headers);
source.setBody(body);
ch.alv.components.web.api.config.Response result = converter.convertResponse(source);
assertEquals(source.getDescription(), result.getDescription());
assertEquals(source.getBody().size(), result.getBody().size());
assertEquals(source.getHeaders().size(), result.getHeaders().size());
assertNull(converter.convertResponse(null));
}
示例3: getProperty
import org.raml.model.Response; //导入依赖的package包/类
@Override
public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
final Response r = (Response) o;
switch (propertyName) {
case "body":
return r.getBody() == null ? null : new TreeMap<>(r.getBody());
case "headers":
return new TreeMap<>(r.getHeaders());
default:
return super.getProperty(interp, self, o, property, propertyName);
}
}
示例4: createMethodResponses
import org.raml.model.Response; //导入依赖的package包/类
private void createMethodResponses(RestApi api, Method method, Map<String, Response> responses, boolean update) {
for (Map.Entry<String, Response> entry : responses.entrySet()) {
createMethodResponse(api, method, entry.getKey(), entry.getValue(), update);
}
if (update) {
cleanupMethodResponses(method, responses);
}
}
示例5: cleanupMethodResponses
import org.raml.model.Response; //导入依赖的package包/类
private void cleanupMethodResponses(Method method, Map<String, Response> responses) {
method.getMethodResponses().entrySet().forEach(entry -> {
if (!responses.containsKey(entry.getKey())) {
entry.getValue().deleteMethodResponse();
}
});
}
示例6: validate
import org.raml.model.Response; //导入依赖的package包/类
@Override
public ValidationErrors validate() {
ValidationErrors errors = new ValidationErrors();
if (!expectation.hasValidAction())
throw new NoValidActionException(expectation);
Integer statusCode = expectation.getResponseStatusCode();
MediaType contentType = expectation.getResponseContentType();
Optional<Response> response = expectation.getResponse();
if (!response.isPresent()) {
errors.addMessage("[ response ] [ %d ] [ %s ] No response body specification exists.", statusCode, contentType);
return errors;
}
Optional<BodySpecification> specification = expectation.getResponseBodySpecification();
Optional<String> responseBody = expectation.getResponseBody();
if (!specification.isPresent() && responseBody.isPresent()) {
errors.addMessage("[ response ] [ %d ] [ %s ] No response body specification exists for this content type. Acceptable content types are [ %s ].", statusCode, contentType, getAllowedContentTypes(response.get().getBody()));
return errors;
}
if (!responseBody.isPresent()) {
errors.addMessage("[ response ] [ %d ] [ %s ] Has an expected response body but none returned.", statusCode, contentType);
return errors;
}
errors.combineWith(specification.get().validate(responseBody.get()));
return errors;
}
示例7: getProperty
import org.raml.model.Response; //导入依赖的package包/类
@Override
public synchronized Object getProperty(Interpreter anInter, ST aSt,
Object anObject, Object aProperty, String aName)
throws STNoSuchPropertyException {
Response oResponse=(Response)anObject;
if(aName.equals("body")) {
if(oResponse.getBody()==null || oResponse.getBody().size()==0) {
Map<String, MimeType> oMap=oResponse.getBody()==null?new HashMap<String, MimeType>():oResponse.getBody();
oMap.put("*/*", new MimeType("*/*"));
oResponse.setBody(oMap);
}
}
return super.getProperty(anInter, aSt, anObject, aProperty, aName);
}
示例8: render
import org.raml.model.Response; //导入依赖的package包/类
@Override
public Bundle render(Raml aRoot, Map<String, String> someOpts) {
STGroup stg = new STGroupFile(stgFile);
stg.registerModelAdaptor(Resource.class, new ResourceAdaptator());
stg.registerModelAdaptor(Raml.class, new RamlAdaptator());
stg.registerModelAdaptor(Action.class, new ActionAdaptator(aRoot));
stg.registerModelAdaptor(Response.class, new ResponseAdaptator());
stg.registerModelAdaptor(MimeType.class, new MimeTypeAdaptator());
Map<String, String> oOpts=new HashMap<String, String>(someOpts);
oOpts.put("title", Utils.cleanString(aRoot.getTitle()));
if(someOpts.get("baseUri")!=null) {
aRoot.setBaseUri(someOpts.get("baseUri"));
}
aRoot.setBaseUri(Utils.resolve(aRoot.getBaseUri(), "version", aRoot.getVersion()));
Bundle oBundle=null;
ST oRootPath=getST(stg,"rootPath", aRoot, oOpts);
if(oRootPath!=null) {
oBundle=new Bundle(oRootPath.render());
} else {
oBundle=new Bundle(someOpts.get(Generator.GENERATED_PATH));
}
for(String oName:rootTemplateNames) {
ST oContent = getST(stg,oName, aRoot, oOpts);
ST oFileName = getST(stg,oName+"_file", aRoot,oOpts);
oBundle.addItem(oFileName.render(), oContent.render());
}
return oBundle;
}
示例9: convertResponses
import org.raml.model.Response; //导入依赖的package包/类
public List<ch.alv.components.web.api.config.Response> convertResponses(Map<String, Response> source) {
List<ch.alv.components.web.api.config.Response> list = new ArrayList<>();
if (source.isEmpty()) {
return list;
}
for (String key : source.keySet()) {
list.add(convertResponse(source.get(key)));
}
return list;
}
示例10: convertResponse
import org.raml.model.Response; //导入依赖的package包/类
public ch.alv.components.web.api.config.Response convertResponse(Response source) {
if (source == null) {
return null;
}
ch.alv.components.web.api.config.Response target = new ch.alv.components.web.api.config.Response();
target.setDescription(convertDescription(source.getDescription()));
target.setBody(convertMimeTypes(source.getBody()));
target.setHeaders(convertHeaders(source.getHeaders()));
return target;
}
示例11: testConvertResponses
import org.raml.model.Response; //导入依赖的package包/类
@Test
public void testConvertResponses() {
Map<String, Response> source = new HashMap<>();
source.put("testResponse", new Response());
List<ch.alv.components.web.api.config.Response> result = converter.convertResponses(source);
assertEquals(1, result.size());
assertEquals(0, converter.convertResponses(new HashMap<String, Response>()).size());
}
示例12: getResponseForAction
import org.raml.model.Response; //导入依赖的package包/类
protected Response getResponseForAction(Action action, String status) {
for (Map.Entry<String, Response> response: action.getResponses().entrySet()) {
if (response.getKey().equals(status)) {
return response.getValue();
}
}
throw new IllegalArgumentException(format("no response found for status %s in action %s", status, action));
}
示例13: getExampleResponses
import org.raml.model.Response; //导入依赖的package包/类
@Override
public Map<Integer, Response> getExampleResponses() {
return exampleResponses;
}
示例14: createRamlResponse
import org.raml.model.Response; //导入依赖的package包/类
@Override
public RamlResponse createRamlResponse() {
return createRamlResponse(new Response());
}
示例15: extractResponse
import org.raml.model.Response; //导入依赖的package包/类
Response extractResponse(RamlResponse ramlResponse) {
return ((RJP08V1RamlResponse)ramlResponse).getResponse();
}