-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimizing sending of AS2 messages and adding support for pluggable g…
…eneration of Message-Id. #294
- Loading branch information
Showing
11 changed files
with
398 additions
and
35 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
oxalis-as2/src/main/java/no/difi/oxalis/as2/api/MessageIdGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2010-2017 Norwegian Agency for Public Management and eGovernment (Difi) | ||
* | ||
* Licensed under the EUPL, Version 1.1 or – as soon they | ||
* will be approved by the European Commission - subsequent | ||
* versions of the EUPL (the "Licence"); | ||
* | ||
* You may not use this work except in compliance with the Licence. | ||
* | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* https://joinup.ec.europa.eu/community/eupl/og_page/eupl | ||
* | ||
* Unless required by applicable law or agreed to in | ||
* writing, software distributed under the Licence is | ||
* distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. | ||
* See the Licence for the specific language governing | ||
* permissions and limitations under the Licence. | ||
*/ | ||
|
||
package no.difi.oxalis.as2.api; | ||
|
||
import no.difi.oxalis.api.outbound.TransmissionRequest; | ||
|
||
/** | ||
* @author erlend | ||
* @since 4.0.2 | ||
*/ | ||
public interface MessageIdGenerator { | ||
|
||
String generate(TransmissionRequest transmissionRequest); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
oxalis-as2/src/main/java/no/difi/oxalis/as2/common/As2CommonModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2010-2017 Norwegian Agency for Public Management and eGovernment (Difi) | ||
* | ||
* Licensed under the EUPL, Version 1.1 or – as soon they | ||
* will be approved by the European Commission - subsequent | ||
* versions of the EUPL (the "Licence"); | ||
* | ||
* You may not use this work except in compliance with the Licence. | ||
* | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* https://joinup.ec.europa.eu/community/eupl/og_page/eupl | ||
* | ||
* Unless required by applicable law or agreed to in | ||
* writing, software distributed under the Licence is | ||
* distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. | ||
* See the Licence for the specific language governing | ||
* permissions and limitations under the Licence. | ||
*/ | ||
|
||
package no.difi.oxalis.as2.common; | ||
|
||
import com.google.inject.Injector; | ||
import com.google.inject.Provides; | ||
import com.google.inject.Singleton; | ||
import com.google.inject.name.Named; | ||
import no.difi.oxalis.api.settings.Settings; | ||
import no.difi.oxalis.as2.api.MessageIdGenerator; | ||
import no.difi.oxalis.commons.guice.ImplLoader; | ||
import no.difi.oxalis.commons.guice.OxalisModule; | ||
|
||
/** | ||
* @author erlend | ||
* @since 4.0.2 | ||
*/ | ||
public class As2CommonModule extends OxalisModule { | ||
|
||
@Override | ||
protected void configure() { | ||
bindTyped(MessageIdGenerator.class, DefaultMessageIdGenerator.class); | ||
|
||
bindSettings(As2Conf.class); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
@Named("as2-notification") | ||
public String getNotification(Settings<As2Conf> settings) { | ||
return settings.getString(As2Conf.NOTIFICATION); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public MessageIdGenerator getMessageIdGenerator(Injector injector, Settings<As2Conf> settings) { | ||
return ImplLoader.get(injector, MessageIdGenerator.class, settings, As2Conf.MSGID_GENERATOR); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
oxalis-as2/src/main/java/no/difi/oxalis/as2/common/As2Conf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2010-2017 Norwegian Agency for Public Management and eGovernment (Difi) | ||
* | ||
* Licensed under the EUPL, Version 1.1 or – as soon they | ||
* will be approved by the European Commission - subsequent | ||
* versions of the EUPL (the "Licence"); | ||
* | ||
* You may not use this work except in compliance with the Licence. | ||
* | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* https://joinup.ec.europa.eu/community/eupl/og_page/eupl | ||
* | ||
* Unless required by applicable law or agreed to in | ||
* writing, software distributed under the Licence is | ||
* distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. | ||
* See the Licence for the specific language governing | ||
* permissions and limitations under the Licence. | ||
*/ | ||
|
||
package no.difi.oxalis.as2.common; | ||
|
||
import no.difi.oxalis.api.settings.DefaultValue; | ||
import no.difi.oxalis.api.settings.Path; | ||
import no.difi.oxalis.api.settings.Title; | ||
|
||
/** | ||
* @author erlend | ||
* @since 4.0.2 | ||
*/ | ||
@Title("AS2") | ||
public enum As2Conf { | ||
|
||
@Path("oxalis.as2.hostname") | ||
@DefaultValue("") | ||
HOSTNAME, | ||
|
||
@Path("oxalis.as2.notification") | ||
@DefaultValue("not.in.use@difi.no") | ||
NOTIFICATION, | ||
|
||
@Path("oxalis.as2.msgid_gen") | ||
@DefaultValue("default") | ||
MSGID_GENERATOR, | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
oxalis-as2/src/main/java/no/difi/oxalis/as2/common/DefaultMessageIdGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2010-2017 Norwegian Agency for Public Management and eGovernment (Difi) | ||
* | ||
* Licensed under the EUPL, Version 1.1 or – as soon they | ||
* will be approved by the European Commission - subsequent | ||
* versions of the EUPL (the "Licence"); | ||
* | ||
* You may not use this work except in compliance with the Licence. | ||
* | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* https://joinup.ec.europa.eu/community/eupl/og_page/eupl | ||
* | ||
* Unless required by applicable law or agreed to in | ||
* writing, software distributed under the Licence is | ||
* distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. | ||
* See the Licence for the specific language governing | ||
* permissions and limitations under the Licence. | ||
*/ | ||
|
||
package no.difi.oxalis.as2.common; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import no.difi.oxalis.api.outbound.TransmissionRequest; | ||
import no.difi.oxalis.api.settings.Settings; | ||
import no.difi.oxalis.api.util.Type; | ||
import no.difi.oxalis.as2.api.MessageIdGenerator; | ||
|
||
import javax.mail.internet.InternetAddress; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* @author erlend | ||
*/ | ||
@Singleton | ||
@Type("default") | ||
public class DefaultMessageIdGenerator implements MessageIdGenerator { | ||
|
||
private String hostname; | ||
|
||
private AtomicLong atomicLong = new AtomicLong(); | ||
|
||
@Inject | ||
public DefaultMessageIdGenerator(Settings<As2Conf> settings) { | ||
try { | ||
hostname = settings.getString(As2Conf.HOSTNAME); | ||
if (hostname.trim().isEmpty()) | ||
hostname = InetAddress.getLocalHost().getHostName(); | ||
} catch (UnknownHostException e) { | ||
throw new IllegalStateException("Unable to get local hostname.", e); | ||
} | ||
} | ||
|
||
@Override | ||
public String generate(TransmissionRequest transmissionRequest) { | ||
return new StringBuilder() | ||
.append('<') | ||
.append(System.currentTimeMillis()) | ||
.append('.') | ||
.append(atomicLong.incrementAndGet()) | ||
.append('.') | ||
.append(transmissionRequest.hashCode()) | ||
.append('.') | ||
.append("Oxalis") | ||
.append('@') | ||
.append(hostname) | ||
.append('>') | ||
.toString(); | ||
} | ||
} |
Oops, something went wrong.