本文整理汇总了Java中com.github.tomakehurst.wiremock.http.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于com.github.tomakehurst.wiremock.http包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition,
FileSource files, Parameters parameters) {
MockParameters params = (MockParameters) parameters.get(UnitStackTest.MOCK_PARAMS);
Map<String, String> body = new HashMap<>();
String method = request.getMethod().getName();
byte[] fileContent = null;
body.put(PARAMETER_URL_NAME, request.getAbsoluteUrl());
body.put(PARAMETER_METHOD, method);
if (method.equals("GET")) {
body.put(ACTION, StringUtils.substringAfter(request.getAbsoluteUrl(), "?"));
} else {
body.put(PARAMETER_RESPONSE_XML, request.getBodyAsString());
fileContent = request.getBody();
}
body.putAll(getHeaders(request));
MockResponse response = s3Responder.createResponse(
new MockRequest(body, params, utils).withBuckets(buckets).withFileContent(fileContent));
return createResponse(response);
}
示例2: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request,
ResponseDefinition responseDefinition,
FileSource files,
Parameters parameters) {
ResponseDefinitionBuilder builder = new ResponseDefinitionBuilder().like(responseDefinition);
String templatePath = responseDefinition.getBodyFileName();
if (templatePath != null && templatePath.contains(".template")) {
try {
Map scope = new ResponseScope(session, new HashMap(this.config), RequestReader.read(request));
responseWriter = responseWriter == null ? new ResponseWriter(files.getPath()) : responseWriter;
new BeforeBlock().run(responseDefinition, scope);
responseWriter.writeTo(builder, scope, templatePath);
} catch (Exception e) {
String errorMessage = "************* Jeyson Error *******************" + System.getProperty("line.separator");
errorMessage += e.getMessage() + System.getProperty("line.separator");
System.err.println(errorMessage);
e.printStackTrace();
}
}
return builder.build();
}
示例3: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request,
ResponseDefinition responseDefinition,
FileSource files,
Parameters parameters) {
ResponseDefinitionBuilder builder = new ResponseDefinitionBuilder().like(responseDefinition);
String templatePath = responseDefinition.getBodyFileName();
if (templatePath != null) {
try {
Map scope = new ResponseScope(session, new HashMap(this.config), RequestReader.read(request));
responseWriter = responseWriter == null ? new ResponseWriter(files.getPath()) : responseWriter;
new BeforeBlock().run(responseDefinition, scope);
responseWriter.writeTo(builder, scope, templatePath);
} catch (Exception e) {
String errorMessage = "************* Jeyson Error *******************" + System.getProperty("line.separator");
errorMessage += e.getMessage() + System.getProperty("line.separator");
System.err.println(errorMessage);
e.printStackTrace();
}
}
return builder.build();
}
示例4: setupWireMock
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Before
public void setupWireMock() throws Exception {
String fusionHostAndPort = "http://" + fusionHost + fusionApiPort;
fusionPipelineUrlWithoutHostAndPort = fusionProxyBaseUrl + fusionIndexingPipelineUrlExtension +
fusionIndexingPipeline + fusionCollectionApiStrValForUrl + fusionCollectionForUrl +
defaultFusionIndexingPipelineUrlTerminatingString;
fusionUrl = fusionHostAndPort + fusionPipelineUrlWithoutHostAndPort;
fusionSolrProxyWithoutHostAndPort = fusionSolrProxyUrlExtension + fusionCollectionForUrl;
wireMockRule.addMockServiceRequestListener(new RequestListener() {
@Override
public void requestReceived(Request request, Response response) {
loggedRequests.add(LoggedRequest.createFrom(request));
}
});
log.info("running with: fusionSolrProxyWithoutHostAndPort=" + fusionSolrProxyWithoutHostAndPort +
" fusionPipelineUrlWithoutHostAndPort=" + fusionPipelineUrlWithoutHostAndPort +
" wireMockRulePort=" + wireMockRulePort + " useWireMockRule=" + useWireMockRule);
}
示例5: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(final Request request,
final ResponseDefinition responseDefinition, final FileSource files,
final Parameters parameters) {
if (responseDefinition.specifiesBodyFile() && templateDeclared(responseDefinition)) {
this.fileSource = files;
final VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.init();
final ToolManager toolManager = new ToolManager();
toolManager.setVelocityEngine(velocityEngine);
context = toolManager.createContext();
addBodyToContext(request.getBodyAsString());
addHeadersToContext(request.getHeaders());
context.put("requestAbsoluteUrl", request.getAbsoluteUrl());
context.put("requestUrl", request.getUrl());
context.put("requestMethod", request.getMethod());
final String body = getRenderedBody(responseDefinition);
return ResponseDefinitionBuilder.like(responseDefinition).but()
.withBody(body)
.build();
} else {
return responseDefinition;
}
}
示例6: getClaimsFromRequest
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
private JwtClaims getClaimsFromRequest(Request request) throws Exception {
// Get the JWT out of the request body
String body = request.getBodyAsString();
String[] tokens = body.split("&");
String jwt = null;
for (String s : tokens) {
String[] parts = s.split("=");
if (parts[0] != null && parts[0].equals("assertion") && parts[1] != null) {
jwt = parts[1];
}
}
if (jwt == null) {
throw new Exception("No jwt assertion found in request body");
}
// Parse out the JWT to verify the claims
JwtConsumer jwtConsumer = new JwtConsumerBuilder()
.setSkipSignatureVerification()
.setSkipAllValidators()
.build();
return jwtConsumer.processToClaims(jwt);
}
示例7: RootConfigHandler
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
public RootConfigHandler(final Request request, final Parameters transformerParameters) throws WireMockCsvException {
this.request = request;
this.requestParams = RequestTemplateModel.from(request).getQuery();
this.transformerParameters = transformerParameters;
@SuppressWarnings("unchecked")
final Map<String, Map<String, Object>> customParametersConfig =
(Map<String, Map<String, Object>>) this.transformerParameters.get("customParameters");
this.initCustomParameters(customParametersConfig);
}
示例8: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition,
FileSource files, Parameters parameters) {
MockParameters params = (MockParameters) parameters.get(UnitStackTest.MOCK_PARAMS);
Map<String, String> body = utils.queryStringToMap(request.getBodyAsString());
MockResponse response =
snsResponder.createResponse(new MockRequest(body, params, utils).withTopics(topics));
return new ResponseDefinitionBuilder().withBody(response.getBody())
.withStatus(response.getStatus()).build();
}
示例9: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition,
FileSource files, Parameters parameters) {
MockParameters params = (MockParameters) parameters.get(UnitStackTest.MOCK_PARAMS);
Map<String, String> body = new HashMap<>(utils.queryStringToMap(request.getBodyAsString()));
body.put(PARAMETER_URL_NAME, request.getUrl());
MockResponse response =
sqsResponder.createResponse(new MockRequest(body, params, utils).withQueues(queues));
return new ResponseDefinitionBuilder().withBody(response.getBody())
.withStatus(response.getStatus()).build();
}
示例10: read
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
public static Map read(Request request) throws IOException {
if(request.getMethod().getName().equals("GET")){
return new social.amoeba.jeyson.wiremock.request.Request(request);
}
ContentTypeHeader contentType = request.getHeaders().getContentTypeHeader();
String mimeType = contentType == null ? null : contentType.mimeTypePart();
boolean isJSON = contentType != null && mimeType.equalsIgnoreCase("application/json"),
isXML = contentType != null &&mimeType.equalsIgnoreCase("application/xml") || mimeType.equalsIgnoreCase("text/xml");
return isXML ? new XMLRequest(request) : isJSON ? new JSONRequest(request) : new HashMap<>();
}
示例11: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(final Request request, final ResponseDefinition responseDefinition, final FileSource files) {
String patientHashedId = request.getUrl().replace("/patients/", "");
final Patient patientEntity = createPatient(patientHashedId);
try {
responseDefinition.setBody(mapper.writeValueAsString(patientEntity));
} catch (JsonProcessingException jpe) {
LOGGER.error("Unable to convert patient to JSON string", jpe);
}
return responseDefinition;
}
示例12: addMockRequestListener
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
public static void addMockRequestListener(final WireMockRule rule, final List<Request> wiremockRequests) {
//Handy WireMock listener that stores each request received
rule.addMockServiceRequestListener(new RequestListener() {
@Override
public void requestReceived(Request request, Response response) {
wiremockRequests.add(LoggedRequest.createFrom(request));
}
});
}
示例13: transform
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource files) {
System.out.println("Transforming placeholders in " + request.getUrl());
String responseBody = responseDefinition.getBody();
if (responseDefinition.getBodyFileName() != null) {
responseBody = new String(files.getBinaryFileNamed(responseDefinition.getBodyFileName()).readContents(),
Charset.defaultCharset());
}
return ResponseDefinitionBuilder.like(responseDefinition).but().withBody(this.transformResponse(request, responseBody)).build();
}
示例14: transformResponse
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
private String transformResponse(Request request, String response) {
Matcher matcher = PATTERN.matcher(response);
String requestBody = request.getBodyAsString();
Map<String, String> placeholders = Maps.newHashMap();
while (matcher.find()) {
String placeholder = matcher.group();
if (!placeholders.containsKey(placeholder)) {
String value = this.lookupValue(placeholder, request, requestBody);
System.out.println("Placeholder " + placeholder + " will be replace with value " + value);
placeholders.put(placeholder, value);
}
}
return StringUtils.replaceEach(response, placeholders.keySet().toArray(new String[] {}),
placeholders.values().toArray(new String[] {}));
}
示例15: lookupQueryParamValue
import com.github.tomakehurst.wiremock.http.Request; //导入依赖的package包/类
private String lookupQueryParamValue(String property, Request request) {
QueryParameter queryParameter = request.queryParameter(property);
if (queryParameter.isPresent()) {
System.out.println("Placeholder found in query params");
return Strings.join(queryParameter.values(), ",");
}
return null;
}