Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
[*.{java,html}]
root = true

[*]
charset = utf-8
indent_style = space
end_of_line = lf
indent_size = 4
trim_trailing_whitespace = true
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
ij_continuation_indent_size = 8

[*.{yml,yaml}]
[*.{yaml,yml}]
indent_size = 2

[*.properties]
ij_properties_align_group_field_declarations = false
40 changes: 40 additions & 0 deletions asterisk-java-ami/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
id 'java-library'
}

java {
sourceCompatibility = '17'
targetCompatibility = '17'

withSourcesJar()
withJavadocJar()
}

repositories {
mavenCentral()
}

dependencies {
implementation project(':asterisk-java-core')

implementation 'org.apache.commons:commons-lang3:3.14.0'

testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
testImplementation 'org.mockito:mockito-core:5.7.0'
testImplementation 'ch.qos.logback:logback-classic:1.4.11' //todo remove

testImplementation platform('org.testcontainers:testcontainers-bom:1.19.3')
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:testcontainers'

//todo only for testing framework
testImplementation 'io.netty:netty-codec:4.1.101.Final'
testImplementation 'io.netty:netty-handler:4.1.101.Final'
testImplementation 'io.netty:netty-transport:4.1.101.Final'
testImplementation 'org.awaitility:awaitility:4.2.0'
}

tasks.named('test') {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2004-2023 Asterisk Java contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asteriskjava.ami;

import java.util.Comparator;

/**
* Convenient class to sort Action and ActionID fields in action object. Those fields are first and second retrospectively.
*
* @author Piotr Olaszewski
* @since 4.0.0
*/
public class ActionFieldsComparator implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
if (o1.equals(o2)) {
return 0;
}
if (o1.equalsIgnoreCase("Action") && o2.equalsIgnoreCase("ActionID") || (o1.equalsIgnoreCase("ActionID") && o2.equalsIgnoreCase("Action"))) {
return 1;
}
if (o1.equalsIgnoreCase("Action") || o1.equalsIgnoreCase("ActionID")) {
return -1;
}
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2004-2023 Asterisk Java contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asteriskjava.ami.action;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.asteriskjava.core.databind.annotation.AsteriskName;

import java.io.Serial;

/**
* This class implements the {@link ManagerAction} interface and can serve as the base class for your concrete action
* implementations.
*
* @author Stefan Reuter
* @author Piotr Olaszewski
* @since 1.0.0
*/
public abstract class AbstractManagerAction implements ManagerAction {
@Serial
private static final long serialVersionUID = -7667827187378395689L;

private String actionId;

@AsteriskName("ActionID")
public String getActionId() {
return actionId;
}

public void setActionId(String actionId) {
this.actionId = actionId;
}

@Override
public String toString() {
return new ToStringBuilder(this)
.append("action", getAction())
.append("actionId", actionId)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asteriskjava.core.databind.writer;
package org.asteriskjava.ami.action;

/**
* Context for the process methods.
* Digest algorithms to use in the challenge.
*
* @param serializerWriteFieldName whatever serializer write field names
* @author Piotr Olaszewski
* @see ChallengeAction
* @since 4.0.0
*/
public record AsteriskObjectMethodWriterContext(boolean serializerWriteFieldName) {
public enum AuthType {
MD5,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2004-2023 Asterisk Java contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asteriskjava.ami.action;

import org.asteriskjava.ami.action.annotation.ExpectedResponse;
import org.asteriskjava.ami.action.response.ChallengeManagerActionResponse;

import java.io.Serial;

/**
* The {@link ChallengeAction} requests a challenge from the server to use when logging in using challenge/response.
* Sending this action to the Asterisk server results in a {@link ChallengeManagerActionResponse} being received from the server.
* <p>
* Supported Asterisk versions:
* <ul>
* <li>18 - <a href="https://docs.asterisk.org/Asterisk_18_Documentation/API_Documentation/AMI_Actions/Challenge/">Challenge</a></li>
* <li>20 - <a href="https://docs.asterisk.org/Asterisk_20_Documentation/API_Documentation/AMI_Actions/Challenge/">Challenge</a></li>
* </ul>
*
* @author Stefan Reuter
* @author Piotr Olaszewski
* @see ChallengeManagerActionResponse
* @since 1.0.0
*/
@ExpectedResponse(ChallengeManagerActionResponse.class)
public class ChallengeAction extends AbstractManagerAction {
@Serial
private static final long serialVersionUID = 7240516124871953971L;

private AuthType authType;

@Override
public String getAction() {
return "Challenge";
}

/**
* Asterisk argument: {@code AuthType}.
*/
public AuthType getAuthType() {
return authType;
}

/**
* Sets Asterisk argument: {@code AuthType}.
*/
public void setAuthType(AuthType authType) {
this.authType = authType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2004-2023 Asterisk Java contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asteriskjava.ami.action;

import java.io.Serializable;

/**
* Interface that all actions that can be sent to the Asterisk server must implement.
* <p>
* Instances of this class represent a command sent to Asterisk via AMI, requesting a particular action be performed.
* The number of actions available to the client are determined by the modules presently loaded in the Asterisk engine.
* <p>
* There is one concrete subclass of ManagerAction per each supported Asterisk action.
*
* @author Stefan Reuter
* @since 1.0.0
*/
public interface ManagerAction extends Serializable {
/**
* Asterisk argument: {@code Action}.
*/
String getAction();

/**
* Asterisk argument: {@code ActionID}.
*/
String getActionId();

/**
* Sets the Asterisk argument: {@code ActionID}.
* <p>
* If the {@code ActionID} is set and sent to Asterisk, any response returned by Asterisk will include the same ID.
* This way, the {@code ActionID} can be used to track actions and their corresponding responses and response events.
* <p>
* Note that Asterisk Java uses its own internal {@code ActionID} to match actions with the corresponding responses
* and events. Although the internal action is never exposed to the application code, if you want to handle responses
* or response events on your own, your application must set a unique {@code ActionID} using this method.
* Otherwise, the {@code ActionID} of the responses and response event objects passed to your application will be null.
*/
void setActionId(String actionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asteriskjava.core.databind.annotation;
package org.asteriskjava.ami.action.annotation;

import org.asteriskjava.core.databind.serializer.AsteriskSerializer;
import org.asteriskjava.ami.action.ManagerAction;
import org.asteriskjava.ami.action.response.ManagerActionResponse;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Annotation used for configuring serialization aspects, by attaching to "getter" methods.
* Indicates that an annotated {@link ManagerAction} expects a specific subclass of {@link ManagerActionResponse} when
* executed successfully.
*
* @author Piotr Olaszewski
* @since 4.0.0
* @author Stefan Reuter
* @since 1.0.0
*/
@Target({METHOD})
@Target(TYPE)
@Retention(RUNTIME)
public @interface AsteriskSerialize {
public @interface ExpectedResponse {
/**
* Serializer class to use for serializing associated value.
* {@link ManagerActionResponse} subclass, to handle {@link ManagerAction} response.
*/
Class<? extends AsteriskSerializer<?>> value();
Class<? extends ManagerActionResponse> value();
}
Loading