Example usage for java.util.regex Pattern matches

List of usage examples for java.util.regex Pattern matches

Introduction

In this page you can find the example usage for java.util.regex Pattern matches.

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:com.microsoft.azure.management.resources.ManagementLockOperationsImpl.java

/**
* Create or update a management lock at the resource level or any level
* below resource.//from  ww  w .  j  av a2 s.c  om
*
* @param resourceGroupName Required. The name of the resource group.
* @param identity Required. Resource identity.
* @param lockName Required. The name of lock.
* @param parameters Required. Create or update management lock parameters.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return Management lock information.
*/
@Override
public ManagementLockReturnResult createOrUpdateAtResourceLevel(String resourceGroupName,
        ResourceIdentity identity, String lockName, ManagementLockProperties parameters)
        throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (resourceGroupName != null && resourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (identity == null) {
        throw new NullPointerException("identity");
    }
    if (identity.getResourceName() == null) {
        throw new NullPointerException("identity.");
    }
    if (identity.getResourceProviderApiVersion() == null) {
        throw new NullPointerException("identity.");
    }
    if (identity.getResourceProviderNamespace() == null) {
        throw new NullPointerException("identity.");
    }
    if (identity.getResourceType() == null) {
        throw new NullPointerException("identity.");
    }
    if (lockName == null) {
        throw new NullPointerException("lockName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("identity", identity);
        tracingParameters.put("lockName", lockName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createOrUpdateAtResourceLevelAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourcegroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + URLEncoder.encode(identity.getResourceProviderNamespace(), "UTF-8");
    url = url + "/";
    if (identity.getParentResourcePath() != null) {
        url = url + identity.getParentResourcePath();
    }
    url = url + "/";
    url = url + identity.getResourceType();
    url = url + "/";
    url = url + URLEncoder.encode(identity.getResourceName(), "UTF-8");
    url = url + "/providers/Microsoft.Authorization/locks/";
    url = url + URLEncoder.encode(lockName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2015-01-01");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPut httpRequest = new HttpPut(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Serialize Request
    String requestContent = null;
    JsonNode requestDoc = null;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode propertiesValue = objectMapper.createObjectNode();
    requestDoc = propertiesValue;

    if (parameters.getLevel() != null) {
        ((ObjectNode) propertiesValue).put("level", parameters.getLevel());
    }

    if (parameters.getNotes() != null) {
        ((ObjectNode) propertiesValue).put("notes", parameters.getNotes());
    }

    StringWriter stringWriter = new StringWriter();
    objectMapper.writeValue(stringWriter, requestDoc);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ManagementLockReturnResult result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ManagementLockReturnResult();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                ManagementLockObject managementLockInstance = new ManagementLockObject();
                result.setManagementLock(managementLockInstance);

                JsonNode propertiesValue2 = responseDoc.get("properties");
                if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                    ManagementLockProperties propertiesInstance = new ManagementLockProperties();
                    managementLockInstance.setProperties(propertiesInstance);

                    JsonNode levelValue = propertiesValue2.get("level");
                    if (levelValue != null && levelValue instanceof NullNode == false) {
                        String levelInstance;
                        levelInstance = levelValue.getTextValue();
                        propertiesInstance.setLevel(levelInstance);
                    }

                    JsonNode notesValue = propertiesValue2.get("notes");
                    if (notesValue != null && notesValue instanceof NullNode == false) {
                        String notesInstance;
                        notesInstance = notesValue.getTextValue();
                        propertiesInstance.setNotes(notesInstance);
                    }
                }

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    managementLockInstance.setId(idInstance);
                }

                JsonNode typeValue = responseDoc.get("type");
                if (typeValue != null && typeValue instanceof NullNode == false) {
                    String typeInstance;
                    typeInstance = typeValue.getTextValue();
                    managementLockInstance.setType(typeInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    managementLockInstance.setName(nameInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.dnielfe.manager.preview.MimeTypes.java

public static boolean mimeTypeMatch(String mime, String input) {
    return Pattern.matches(mime.replace("*", ".*"), input);
}

From source file:com.btmatthews.atlas.jcr.impl.JCRTemplate.java

/**
 * @param workspaceName The name of the workspace.
 * @param callback      The callback that implements the function to be executed.
 * @param <T>           The type returned by the function.
 * @return The result of the function./*  w w w . j  a  va  2 s .  c  om*/
 */
public <T> T withSession(final String workspaceName, final SessionCallback<T> callback) {

    assert workspaceName != null && Pattern.matches(WORKSPACE_PATTERN, workspaceName);
    assert callback != null;

    try {
        final Session session = sessionFactory.getSession(workspaceName);
        if (session == null) {
            throw new RepositoryAccessException(BORROW_SESSION_RETURNED_NULL);
        }
        try {
            if (credentialsProvider == null) {
                return callback.doInSession(session);
            } else {
                final Credentials credentials = credentialsProvider.getUserCredentials();
                if (credentials == null) {
                    return callback.doInSession(session);
                } else {
                    final Session impersonatedSession = session.impersonate(credentials);
                    try {
                        return callback.doInSession(impersonatedSession);
                    } finally {
                        impersonatedSession.logout();
                    }
                }
            }
        } finally {
            sessionFactory.releaseSession(workspaceName, session);
        }
    } catch (final RepositoryAccessException e) {
        LOGGER.debug(e.getMessage(), e);
        throw e;
    } catch (final Exception e) {
        final String message = e.getMessage();
        LOGGER.debug(message, e);
        throw new RepositoryAccessException(message, e);
    }
}

From source file:cn.org.once.cstack.cli.utils.ApplicationUtils.java

public String createEnvironmentVariable(String applicationName, String key, String value) {
    Application application = getSpecificOrCurrentApplication(applicationName);

    Guard.guardTrue(StringUtils.isNotEmpty(key), "No key was given");
    Guard.guardTrue(Pattern.matches("^[a-zA-Z][-a-zA-Z0-9_]*$", key), "Invalid key name \"{0}\"", key);

    try {/*from w  w  w .  ja  va  2s  .c o m*/
        Map<String, String> parameters = new HashMap<>();
        parameters.put("keyEnv", key);
        parameters.put("valueEnv", value);

        restUtils.sendPostCommand(
                authenticationUtils.finalHost + urlLoader.actionApplication + application.getName()
                        + "/container/" + application.getServer().getName() + "/environmentVariables",
                authenticationUtils.getMap(), parameters).get("body");
    } catch (ManagerResponseException e) {
        throw new CloudUnitCliException("Couldn't create environment variable", e);
    }

    return MessageFormat.format(ENV_VAR_ADDED, key, application.getName());
}

From source file:com.microsoft.azure.management.resources.DeploymentOperationOperationsImpl.java

/**
* Gets a list of deployments operations.
*
* @param resourceGroupName Required. The name of the resource group. The
* name is case insensitive./*from   w ww .  jav a 2  s. c o  m*/
* @param deploymentName Required. The name of the deployment.
* @param parameters Optional. Query parameters.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return List of deployment operations.
*/
@Override
public DeploymentOperationsListResult list(String resourceGroupName, String deploymentName,
        DeploymentOperationsListParameters parameters)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (resourceGroupName != null && resourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (deploymentName == null) {
        throw new NullPointerException("deploymentName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("deploymentName", deploymentName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourcegroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/deployments/";
    url = url + URLEncoder.encode(deploymentName, "UTF-8");
    url = url + "/operations";
    ArrayList<String> queryParameters = new ArrayList<String>();
    if (parameters != null && parameters.getTop() != null) {
        queryParameters.add("$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8"));
    }
    queryParameters.add("api-version=" + "2014-04-01-preview");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        DeploymentOperationsListResult result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DeploymentOperationsListResult();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                JsonNode valueArray = responseDoc.get("value");
                if (valueArray != null && valueArray instanceof NullNode == false) {
                    for (JsonNode valueValue : ((ArrayNode) valueArray)) {
                        DeploymentOperation deploymentOperationInstance = new DeploymentOperation();
                        result.getOperations().add(deploymentOperationInstance);

                        JsonNode idValue = valueValue.get("id");
                        if (idValue != null && idValue instanceof NullNode == false) {
                            String idInstance;
                            idInstance = idValue.getTextValue();
                            deploymentOperationInstance.setId(idInstance);
                        }

                        JsonNode operationIdValue = valueValue.get("operationId");
                        if (operationIdValue != null && operationIdValue instanceof NullNode == false) {
                            String operationIdInstance;
                            operationIdInstance = operationIdValue.getTextValue();
                            deploymentOperationInstance.setOperationId(operationIdInstance);
                        }

                        JsonNode propertiesValue = valueValue.get("properties");
                        if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                            DeploymentOperationProperties propertiesInstance = new DeploymentOperationProperties();
                            deploymentOperationInstance.setProperties(propertiesInstance);

                            JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                            if (provisioningStateValue != null
                                    && provisioningStateValue instanceof NullNode == false) {
                                String provisioningStateInstance;
                                provisioningStateInstance = provisioningStateValue.getTextValue();
                                propertiesInstance.setProvisioningState(provisioningStateInstance);
                            }

                            JsonNode timestampValue = propertiesValue.get("timestamp");
                            if (timestampValue != null && timestampValue instanceof NullNode == false) {
                                Calendar timestampInstance;
                                timestampInstance = DatatypeConverter
                                        .parseDateTime(timestampValue.getTextValue());
                                propertiesInstance.setTimestamp(timestampInstance);
                            }

                            JsonNode statusCodeValue = propertiesValue.get("statusCode");
                            if (statusCodeValue != null && statusCodeValue instanceof NullNode == false) {
                                String statusCodeInstance;
                                statusCodeInstance = statusCodeValue.getTextValue();
                                propertiesInstance.setStatusCode(statusCodeInstance);
                            }

                            JsonNode statusMessageValue = propertiesValue.get("statusMessage");
                            if (statusMessageValue != null && statusMessageValue instanceof NullNode == false) {
                                String statusMessageInstance;
                                statusMessageInstance = statusMessageValue.getTextValue();
                                propertiesInstance.setStatusMessage(statusMessageInstance);
                            }

                            JsonNode targetResourceValue = propertiesValue.get("targetResource");
                            if (targetResourceValue != null
                                    && targetResourceValue instanceof NullNode == false) {
                                TargetResource targetResourceInstance = new TargetResource();
                                propertiesInstance.setTargetResource(targetResourceInstance);

                                JsonNode idValue2 = targetResourceValue.get("id");
                                if (idValue2 != null && idValue2 instanceof NullNode == false) {
                                    String idInstance2;
                                    idInstance2 = idValue2.getTextValue();
                                    targetResourceInstance.setId(idInstance2);
                                }

                                JsonNode resourceNameValue = targetResourceValue.get("resourceName");
                                if (resourceNameValue != null
                                        && resourceNameValue instanceof NullNode == false) {
                                    String resourceNameInstance;
                                    resourceNameInstance = resourceNameValue.getTextValue();
                                    targetResourceInstance.setResourceName(resourceNameInstance);
                                }

                                JsonNode resourceTypeValue = targetResourceValue.get("resourceType");
                                if (resourceTypeValue != null
                                        && resourceTypeValue instanceof NullNode == false) {
                                    String resourceTypeInstance;
                                    resourceTypeInstance = resourceTypeValue.getTextValue();
                                    targetResourceInstance.setResourceType(resourceTypeInstance);
                                }
                            }
                        }
                    }
                }

                JsonNode nextLinkValue = responseDoc.get("nextLink");
                if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) {
                    String nextLinkInstance;
                    nextLinkInstance = nextLinkValue.getTextValue();
                    result.setNextLink(nextLinkInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:gobblin.data.management.conversion.hive.publisher.HiveConvertPublisher.java

@VisibleForTesting
private boolean matched(List<String> whitelist, List<String> blacklist, String key) {
    for (String patternStr : blacklist) {
        if (Pattern.matches(getRegexPatternString(patternStr), key)) {
            return false;
        }//from  w  ww. ja  v a  2  s  .  c o  m
    }

    for (String patternStr : whitelist) {
        if (Pattern.matches(getRegexPatternString(patternStr), key)) {
            return true;
        }
    }
    return false;
}

From source file:com.intel.ssg.dcst.panthera.parse.sql.SqlXlateUtil.java

/**
 * Check if it is position order by clause e.g. order by 1
 *
 * @param orderby//from  w  w w. j  a va  2s  .c om
 * @return
 */
public static boolean isOrderByPosition(ASTNode orderby) {
    if (orderby == null) {
        return false;
    }
    for (int i = 0; i < orderby.getChildCount(); i++) {
        String id = orderby.getChild(i).getChild(0).getText();
        if (Pattern.matches("\\d+", id)) {
            // if found any, return true;
            return true;
        }
    }
    return false;
}

From source file:com.freedomotic.core.TriggerCheck.java

/**
 * Checks if a string represents a decimal number.
 *
 * @param number string to check//from w w w.ja va  2s .  c  o m
 * @return true if it's a decimal number, false otherwise
 */
private boolean isDecimalNumber(String number) {
    String decimalPattern = "([0-9]*)\\.([0-9]*)";
    return Pattern.matches(decimalPattern, number);
}

From source file:com.zimbra.common.soap.SoapTestHarness.java

private void doSelect(Element context, Element parent)
        throws SoapFaultException, IOException, HarnessException {

    String path = parent.getAttribute(A_PATH, null);
    String attr = parent.getAttribute(A_ATTR, null);
    String match = parent.getAttribute(A_MATCH, null);

    Element se;/*from ww w .j a  v  a  2s  .  com*/
    if (path != null) {
        // FIXME: hacky!
        org.dom4j.Element d4context = context.toXML();
        org.dom4j.XPath xpath = d4context.createXPath(path);
        xpath.setNamespaceURIs(getURIs(mResponseProto));
        org.dom4j.Node node = xpath.selectSingleNode(d4context);
        //System.out.println("path = " + path + " node = " + node);
        if (!(node instanceof org.dom4j.Element)) {
            mCurrent.check(false, "select failed: " + path);
            return;
        } else {
            se = Element.convertDOM((org.dom4j.Element) node);
            mCurrent.check(true, "select ok: " + path);
        }
    } else {
        se = context;
    }

    String value;
    if (attr != null) {
        value = se.getAttribute(attr, null);
    } else {
        value = se.getText();
    }

    if (match != null) {
        boolean ok = Pattern.matches(match, value);
        mCurrent.check(ok, "match " + (ok ? "ok" : "failed") + " (" + match + ")" + " (" + value + ")");
    }

    //System.out.println(se.getText());
    String property = parent.getAttribute(A_SET, null);
    if (property != null) {
        //System.out.println(property+" "+value);
        setProperty(property, value);
    }

    for (Element e : parent.listElements()) {
        if (e.getQName().equals(E_SELECT)) {
            doSelect(se, e);
        } else {
            checkGlobals(e);
        }
    }
}

From source file:com.microsoft.azure.management.resources.ResourceGroupOperationsImpl.java

/**
* Create a resource group.//www .  j  av  a 2 s  .  c  o  m
*
* @param resourceGroupName Required. The name of the resource group to be
* created or updated.
* @param parameters Required. Parameters supplied to the create or update
* resource group service operation.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return Resource group information.
*/
@Override
public ResourceGroupCreateOrUpdateResult createOrUpdate(String resourceGroupName, ResourceGroup parameters)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (resourceGroupName != null && resourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getLocation() == null) {
        throw new NullPointerException("parameters.Location");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createOrUpdateAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourcegroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-04-01-preview");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPut httpRequest = new HttpPut(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Serialize Request
    String requestContent = null;
    JsonNode requestDoc = null;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode resourceGroupValue = objectMapper.createObjectNode();
    requestDoc = resourceGroupValue;

    ((ObjectNode) resourceGroupValue).put("location", parameters.getLocation());

    if (parameters.getProperties() != null) {
        ((ObjectNode) resourceGroupValue).put("properties", objectMapper.readTree(parameters.getProperties()));
    }

    if (parameters.getTags() != null) {
        if (parameters.getTags() instanceof LazyCollection == false
                || ((LazyCollection) parameters.getTags()).isInitialized()) {
            ObjectNode tagsDictionary = objectMapper.createObjectNode();
            for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) {
                String tagsKey = entry.getKey();
                String tagsValue = entry.getValue();
                ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue);
            }
            ((ObjectNode) resourceGroupValue).put("tags", tagsDictionary);
        }
    }

    if (parameters.getProvisioningState() != null) {
        ((ObjectNode) resourceGroupValue).put("provisioningState", parameters.getProvisioningState());
    }

    StringWriter stringWriter = new StringWriter();
    objectMapper.writeValue(stringWriter, requestDoc);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ResourceGroupCreateOrUpdateResult result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ResourceGroupCreateOrUpdateResult();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                ResourceGroupExtended resourceGroupInstance = new ResourceGroupExtended();
                result.setResourceGroup(resourceGroupInstance);

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    resourceGroupInstance.setId(idInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    resourceGroupInstance.setName(nameInstance);
                }

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                    if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) {
                        String provisioningStateInstance;
                        provisioningStateInstance = provisioningStateValue.getTextValue();
                        resourceGroupInstance.setProvisioningState(provisioningStateInstance);
                    }
                }

                JsonNode locationValue = responseDoc.get("location");
                if (locationValue != null && locationValue instanceof NullNode == false) {
                    String locationInstance;
                    locationInstance = locationValue.getTextValue();
                    resourceGroupInstance.setLocation(locationInstance);
                }

                JsonNode propertiesValue2 = responseDoc.get("properties");
                if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                    String propertiesInstance;
                    propertiesInstance = propertiesValue2.getTextValue();
                    resourceGroupInstance.setProperties(propertiesInstance);
                }

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                    while (itr.hasNext()) {
                        Map.Entry<String, JsonNode> property = itr.next();
                        String tagsKey2 = property.getKey();
                        String tagsValue2 = property.getValue().getTextValue();
                        resourceGroupInstance.getTags().put(tagsKey2, tagsValue2);
                    }
                }

                JsonNode provisioningStateValue2 = responseDoc.get("provisioningState");
                if (provisioningStateValue2 != null && provisioningStateValue2 instanceof NullNode == false) {
                    String provisioningStateInstance2;
                    provisioningStateInstance2 = provisioningStateValue2.getTextValue();
                    resourceGroupInstance.setProvisioningState(provisioningStateInstance2);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}