View Javadoc

1   /*
2    * Copyright 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.addressing.messageid;
18  
19  import java.net.URI;
20  
21  import org.springframework.ws.soap.SoapMessage;
22  
23  /**
24   * Implementation of the {@link MessageIdStrategy} interface that uses a {@link RandomGuid} to generate a Message Id.
25   * The GUID is prefixed by <code>urn:guid:</code>.
26   *
27   * @author Arjen Poutsma
28   * @since 1.5.0
29   */
30  public class RandomGuidMessageIdStrategy implements MessageIdStrategy {
31  
32      public static final String PREFIX = "urn:guid:";
33  
34      private boolean secure;
35  
36      /**
37       * Sets whether or not the generated random numbers should be <i>secure</i>. If set to <code>true</code>, generated
38       * GUIDs are cryptographically strong.
39       */
40      public void setSecure(boolean secure) {
41          this.secure = secure;
42      }
43  
44      /** Returns <code>false</code>. */
45      public boolean isDuplicate(URI messageId) {
46          return false;
47      }
48  
49      public URI newMessageId(SoapMessage message) {
50          return URI.create(PREFIX + new RandomGuid(secure).toString());
51      }
52  }