コード例 #1
0
  @Override
  public void perform(RestMockService mockService, Object param) {
    XFormDialog dialog = ADialogBuilder.buildDialog(Form.class);
    dialog.setOptions(Form.HTTP_METHOD, RestRequestInterface.HttpMethod.getMethodsAsStringArray());
    dialog.setValue(Form.HTTP_METHOD, RestRequestInterface.HttpMethod.GET.name());

    JTextFieldFormField formField = (JTextFieldFormField) dialog.getFormField(Form.RESOURCE_PATH);
    formField.getComponent().requestFocus();

    while (dialog.show()) {
      String resourcePath = dialog.getValue(Form.RESOURCE_PATH);
      String httpMethod = dialog.getValue(Form.HTTP_METHOD);

      if (StringUtils.hasContent(resourcePath)) {
        mockService.addEmptyMockAction(
            RestRequestInterface.HttpMethod.valueOf(httpMethod), resourcePath);
        break;
      }
      UISupport.showInfoMessage("The resource path can not be empty");
    }
  }
コード例 #2
0
 public RestRequestInterface.HttpMethod getMethod() {
   return RestRequestInterface.HttpMethod.valueOf(request.getMethod());
 }
コード例 #3
0
ファイル: WadlImporter.java プロジェクト: SmartBear/soapui
  private RestMethod initMethod(RestResource newResource, Method method) {
    // build name
    String name = getFirstTitle(method.getDocList(), method.getName());
    String id = method.getId();
    if (StringUtils.hasContent(id) && !id.trim().equals(name.trim())) {
      name += " - " + method.getId();
    }

    // ensure unique name
    if (newResource.getRestMethodByName(name) != null) {
      int cnt = 0;
      String orgName = name;

      while (newResource.getRestMethodByName(name) != null) {
        cnt++;
        name = orgName + "-" + cnt;
      }
    }

    // add to resource
    RestMethod restMethod = newResource.addNewMethod(name);
    restMethod.setMethod(RestRequestInterface.HttpMethod.valueOf(method.getName()));

    if (method.getRequest() != null) {
      for (Param param : method.getRequest().getParamList()) {
        param = resolveParameter(param);
        if (param != null) {
          RestParamProperty p = restMethod.addProperty(param.getName());
          initParam(param, p);
        }
      }

      for (Representation representation : method.getRequest().getRepresentationList()) {
        representation = resolveRepresentation(representation);
        addRepresentationFromConfig(
            restMethod, representation, RestRepresentation.Type.REQUEST, null);
      }
    }

    for (Response response : method.getResponseList()) {
      for (Representation representation : response.getRepresentationList()) {
        addRepresentation(response, restMethod, representation);
      }
      if (!isWADL11) {
        NodeList children = response.getDomNode().getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
          Node n = children.item(i);
          if ("fault".equals(n.getNodeName())) {
            String content = XmlUtils.serialize(n, false);
            try {
              Map<Object, Object> map = new HashMap<Object, Object>();
              XmlCursor cursor = response.newCursor();
              cursor.getAllNamespaces(map);
              cursor.dispose();
              XmlOptions options = new XmlOptions();
              options.setLoadAdditionalNamespaces(map);
              // XmlObject obj = XmlObject.Factory.parse(
              // content.replaceFirst( "<(([a-z]+:)?)fault ",
              // "<$1representation " ), options );
              XmlObject obj =
                  XmlUtils.createXmlObject(
                      content.replaceFirst("<(([a-z]+:)?)fault ", "<$1representation "), options);
              RepresentationDocument representation =
                  (RepresentationDocument) obj.changeType(RepresentationDocument.type);
              addRepresentation(response, restMethod, representation.getRepresentation());
            } catch (XmlException e) {
            }
          }
        }
      }
    }

    restMethod.addNewRequest("Request 1");
    return restMethod;
  }